CompiledUrlGenerator
extends UrlGenerator
in package
Generates URLs based on rules dumped by CompiledUrlGeneratorDumper.
Table of Contents
Properties
- $context : mixed
- $decodedChars : mixed
- This array defines the characters (besides alphanumeric ones) that will not be percent-encoded in the path segment of the generated URL.
- $logger : mixed
- $routes : mixed
- $strictRequirements : bool|null
- $compiledRoutes : array<string|int, mixed>
- $defaultLocale : string|null
Methods
- __construct() : mixed
- generate() : string
- Generates a URL or path for a specific route based on the given parameters.
- getContext() : RequestContext
- Gets the request context.
- getRelativePath() : string
- Returns the target path as relative reference from the base path.
- isStrictRequirements() : bool|null
- Returns whether to throw an exception on incorrect parameters.
- setContext() : void
- Sets the request context.
- setStrictRequirements() : void
- Enables or disables the exception on incorrect parameters.
- doGenerate() : string
Properties
$context
protected
mixed
$context
$decodedChars
This array defines the characters (besides alphanumeric ones) that will not be percent-encoded in the path segment of the generated URL.
protected
mixed
$decodedChars
= [
// the slash can be used to designate a hierarchical structure and we want allow using it with this meaning
// some webservers don't allow the slash in encoded form in the path for security reasons anyway
// see http://stackoverflow.com/questions/4069002/http-400-if-2f-part-of-get-url-in-jboss
'%2F' => '/',
'%252F' => '%2F',
// the following chars are general delimiters in the URI specification but have only special meaning in the authority component
// so they can safely be used in the path in unencoded form
'%40' => '@',
'%3A' => ':',
// these chars are only sub-delimiters that have no predefined meaning and can therefore be used literally
// so URI producing applications can use these chars to delimit subcomponents in a path segment without being encoded for better readability
'%3B' => ';',
'%2C' => ',',
'%3D' => '=',
'%2B' => '+',
'%21' => '!',
'%2A' => '*',
'%7C' => '|',
]
PHP's rawurlencode() encodes all chars except "a-zA-Z0-9-._~" according to RFC 3986. But we want to allow some chars to be used in their literal form (reasons below). Other chars inside the path must of course be encoded, e.g. "?" and "#" (would be interpreted wrongly as query and fragment identifier), "'" and """ (are used as delimiters in HTML).
$logger
protected
mixed
$logger
$routes
protected
mixed
$routes
$strictRequirements
protected
bool|null
$strictRequirements
= true
$compiledRoutes
private
array<string|int, mixed>
$compiledRoutes
= []
$defaultLocale
private
string|null
$defaultLocale
Methods
__construct()
public
__construct(array<string|int, mixed> $compiledRoutes, RequestContext $context[, LoggerInterface|null $logger = null ][, string|null $defaultLocale = null ]) : mixed
Parameters
- $compiledRoutes : array<string|int, mixed>
- $context : RequestContext
- $logger : LoggerInterface|null = null
- $defaultLocale : string|null = null
generate()
Generates a URL or path for a specific route based on the given parameters.
public
generate(string $name[, array<string|int, mixed> $parameters = [] ][, int $referenceType = self::ABSOLUTE_PATH ]) : string
Parameters that reference placeholders in the route pattern will substitute them in the path or host. Extra params are added as query string to the URL.
When the passed reference type cannot be generated for the route because it requires a different host or scheme than the current one, the method will return a more comprehensive reference that includes the required params. For example, when you call this method with $referenceType = ABSOLUTE_PATH but the route requires the https scheme whereas the current scheme is http, it will instead return an ABSOLUTE_URL with the https scheme and the current host. This makes sure the generated URL matches the route in any case.
If there is no route with the given name, the generator must throw the RouteNotFoundException.
The special parameter _fragment will be used as the document fragment suffixed to the final URL.
Parameters
- $name : string
- $parameters : array<string|int, mixed> = []
- $referenceType : int = self::ABSOLUTE_PATH
Return values
stringgetContext()
Gets the request context.
public
getContext() : RequestContext
Return values
RequestContextgetRelativePath()
Returns the target path as relative reference from the base path.
public
static getRelativePath(string $basePath, string $targetPath) : string
Only the URIs path component (no schema, host etc.) is relevant and must be given, starting with a slash. Both paths must be absolute and not contain relative parts. Relative URLs from one resource to another are useful when generating self-contained downloadable document archives. Furthermore, they can be used to reduce the link size in documents.
Example target paths, given a base path of "/a/b/c/d":
- "/a/b/c/d" -> ""
- "/a/b/c/" -> "./"
- "/a/b/" -> "../"
- "/a/b/c/other" -> "other"
- "/a/x/y" -> "../../x/y"
Parameters
- $basePath : string
-
The base path
- $targetPath : string
-
The target path
Return values
stringisStrictRequirements()
Returns whether to throw an exception on incorrect parameters.
public
isStrictRequirements() : bool|null
Null means the requirements check is deactivated completely.
Return values
bool|nullsetContext()
Sets the request context.
public
setContext(RequestContext $context) : void
Parameters
- $context : RequestContext
setStrictRequirements()
Enables or disables the exception on incorrect parameters.
public
setStrictRequirements(bool|null $enabled) : void
Parameters
- $enabled : bool|null
doGenerate()
protected
doGenerate(array<string|int, mixed> $variables, array<string|int, mixed> $defaults, array<string|int, mixed> $requirements, array<string|int, mixed> $tokens, array<string|int, mixed> $parameters, string $name, int $referenceType, array<string|int, mixed> $hostTokens[, array<string|int, mixed> $requiredSchemes = [] ]) : string
Parameters
- $variables : array<string|int, mixed>
- $defaults : array<string|int, mixed>
- $requirements : array<string|int, mixed>
- $tokens : array<string|int, mixed>
- $parameters : array<string|int, mixed>
- $name : string
- $referenceType : int
- $hostTokens : array<string|int, mixed>
- $requiredSchemes : array<string|int, mixed> = []