Router
in package
implements
RouterInterface, RequestMatcherInterface
The Router class is an example of the integration of all pieces of the routing system for easier use.
Tags
Table of Contents
Interfaces
- RouterInterface
- RouterInterface is the interface that all Router classes must implement.
- RequestMatcherInterface
- RequestMatcherInterface is the interface that all request matcher classes must implement.
Properties
- $collection : RouteCollection|null
- $context : RequestContext
- $defaultLocale : string|null
- $generator : UrlGeneratorInterface|null
- $loader : LoaderInterface
- $logger : LoggerInterface|null
- $matcher : UrlMatcherInterface|null
- $options : array<string|int, mixed>
- $resource : mixed
- $cache : array<string|int, mixed>|null
- $configCacheFactory : ConfigCacheFactoryInterface
- $expressionLanguageProviders : array<string|int, ExpressionFunctionProviderInterface>
Methods
- __construct() : mixed
- addExpressionLanguageProvider() : void
- generate() : string
- Generates a URL or path for a specific route based on the given parameters.
- getContext() : RequestContext
- Gets the request context.
- getGenerator() : UrlGeneratorInterface
- Gets the UrlGenerator instance associated with this Router.
- getMatcher() : UrlMatcherInterface|RequestMatcherInterface
- Gets the UrlMatcher or RequestMatcher instance associated with this Router.
- getOption() : mixed
- Gets an option value.
- getRouteCollection() : RouteCollection
- Gets the RouteCollection instance associated with this Router.
- match() : array<string|int, mixed>
- Tries to match a URL path with a set of routes.
- matchRequest() : array<string|int, mixed>
- Tries to match a request with a set of routes.
- setConfigCacheFactory() : void
- Sets the ConfigCache factory to use.
- setContext() : void
- Sets the request context.
- setOption() : void
- Sets an option.
- setOptions() : void
- Sets options.
- getGeneratorDumperInstance() : GeneratorDumperInterface
- getMatcherDumperInstance() : MatcherDumperInterface
- getCompiledRoutes() : array<string|int, mixed>
- getConfigCacheFactory() : ConfigCacheFactoryInterface
- Provides the ConfigCache factory implementation, falling back to a default implementation if necessary.
Properties
$collection
protected
RouteCollection|null
$collection
$context
protected
RequestContext
$context
$defaultLocale
protected
string|null
$defaultLocale
$generator
protected
UrlGeneratorInterface|null
$generator
$loader
protected
LoaderInterface
$loader
$logger
protected
LoggerInterface|null
$logger
$matcher
protected
UrlMatcherInterface|null
$matcher
$options
protected
array<string|int, mixed>
$options
= []
$resource
protected
mixed
$resource
$cache
private
static array<string|int, mixed>|null
$cache
= []
$configCacheFactory
private
ConfigCacheFactoryInterface
$configCacheFactory
$expressionLanguageProviders
private
array<string|int, ExpressionFunctionProviderInterface>
$expressionLanguageProviders
= []
Methods
__construct()
public
__construct(LoaderInterface $loader, mixed $resource[, array<string|int, mixed> $options = [] ][, RequestContext|null $context = null ][, LoggerInterface|null $logger = null ][, string|null $defaultLocale = null ]) : mixed
Parameters
- $loader : LoaderInterface
- $resource : mixed
- $options : array<string|int, mixed> = []
- $context : RequestContext|null = null
- $logger : LoggerInterface|null = null
- $defaultLocale : string|null = null
addExpressionLanguageProvider()
public
addExpressionLanguageProvider(ExpressionFunctionProviderInterface $provider) : void
Parameters
- $provider : ExpressionFunctionProviderInterface
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
RequestContextgetGenerator()
Gets the UrlGenerator instance associated with this Router.
public
getGenerator() : UrlGeneratorInterface
Return values
UrlGeneratorInterfacegetMatcher()
Gets the UrlMatcher or RequestMatcher instance associated with this Router.
public
getMatcher() : UrlMatcherInterface|RequestMatcherInterface
Return values
UrlMatcherInterface|RequestMatcherInterfacegetOption()
Gets an option value.
public
getOption(string $key) : mixed
Parameters
- $key : string
Tags
getRouteCollection()
Gets the RouteCollection instance associated with this Router.
public
getRouteCollection() : RouteCollection
Return values
RouteCollectionmatch()
Tries to match a URL path with a set of routes.
public
match(string $pathinfo) : array<string|int, mixed>
If the matcher cannot find information, it must throw one of the exceptions documented below.
Parameters
- $pathinfo : string
-
The path info to be parsed (raw format, i.e. not urldecoded)
Return values
array<string|int, mixed>matchRequest()
Tries to match a request with a set of routes.
public
matchRequest(Request $request) : array<string|int, mixed>
If the matcher cannot find information, it must throw one of the exceptions documented below.
Parameters
- $request : Request
Return values
array<string|int, mixed>setConfigCacheFactory()
Sets the ConfigCache factory to use.
public
setConfigCacheFactory(ConfigCacheFactoryInterface $configCacheFactory) : void
Parameters
- $configCacheFactory : ConfigCacheFactoryInterface
setContext()
Sets the request context.
public
setContext(RequestContext $context) : void
Parameters
- $context : RequestContext
setOption()
Sets an option.
public
setOption(string $key, mixed $value) : void
Parameters
- $key : string
- $value : mixed
Tags
setOptions()
Sets options.
public
setOptions(array<string|int, mixed> $options) : void
Available options:
- cache_dir: The cache directory (or null to disable caching)
- debug: Whether to enable debugging or not (false by default)
- generator_class: The name of a UrlGeneratorInterface implementation
- generator_dumper_class: The name of a GeneratorDumperInterface implementation
- matcher_class: The name of a UrlMatcherInterface implementation
- matcher_dumper_class: The name of a MatcherDumperInterface implementation
- resource_type: Type hint for the main resource (optional)
- strict_requirements: Configure strict requirement checking for generators implementing ConfigurableRequirementsInterface (default is true)
Parameters
- $options : array<string|int, mixed>
Tags
getGeneratorDumperInstance()
protected
getGeneratorDumperInstance() : GeneratorDumperInterface
Return values
GeneratorDumperInterfacegetMatcherDumperInstance()
protected
getMatcherDumperInstance() : MatcherDumperInterface
Return values
MatcherDumperInterfacegetCompiledRoutes()
private
static getCompiledRoutes(string $path) : array<string|int, mixed>
Parameters
- $path : string
Return values
array<string|int, mixed>getConfigCacheFactory()
Provides the ConfigCache factory implementation, falling back to a default implementation if necessary.
private
getConfigCacheFactory() : ConfigCacheFactoryInterface