CompiledUrlGenerator
extends UrlGenerator
in package
Generates URLs based on rules dumped by CompiledUrlGeneratorDumper.
Table of Contents
- QUERY_FRAGMENT_DECODED = [ // RFC 3986 explicitly allows those in the query/fragment to reference other URIs unencoded '%2F' => '/', '%3F' => '?', // reserved chars that have no special meaning for HTTP URIs in a query or fragment // this excludes esp. "&", "=" and also "+" because PHP would treat it as a space (form-encoded) '%40' => '@', '%3A' => ':', '%21' => '!', '%3B' => ';', '%2C' => ',', '%2A' => '*', ]
- $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 : mixed
- $defaultLocale : mixed
- __construct() : mixed
- generate() : string
- Generates a URL or path for a specific route based on the given parameters.
- getContext() : mixed
- {@inheritdoc}
- 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() : mixed
- {@inheritdoc}
- setStrictRequirements() : mixed
- Enables or disables the exception on incorrect parameters.
- doGenerate() : string
Constants
QUERY_FRAGMENT_DECODED
private
mixed
QUERY_FRAGMENT_DECODED
= [
// RFC 3986 explicitly allows those in the query/fragment to reference other URIs unencoded
'%2F' => '/',
'%3F' => '?',
// reserved chars that have no special meaning for HTTP URIs in a query or fragment
// this excludes esp. "&", "=" and also "+" because PHP would treat it as a space (form-encoded)
'%40' => '@',
'%3A' => ':',
'%21' => '!',
'%3B' => ';',
'%2C' => ',',
'%2A' => '*',
]
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
mixed
$compiledRoutes
= []
$defaultLocale
private
mixed
$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
Return values
mixed —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
- $name : string
- $parameters : array<string|int, mixed> = []
- $referenceType : int = self::ABSOLUTE_PATH
Return values
string —getContext()
{@inheritdoc}
public
getContext() : mixed
Return values
mixed —getRelativePath()
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
string —isStrictRequirements()
Returns whether to throw an exception on incorrect parameters.
public
isStrictRequirements() : bool|null
Return values
bool|null —setContext()
{@inheritdoc}
public
setContext(RequestContext $context) : mixed
Parameters
- $context : RequestContext
Return values
mixed —setStrictRequirements()
Enables or disables the exception on incorrect parameters.
public
setStrictRequirements(bool|null $enabled) : mixed
Parameters
- $enabled : bool|null
Return values
mixed —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> = []