class Router implements RouterInterface (View source)

The default web router

Properties

protected RoutesProviderInterface $routesProvider
protected LoggerInterface $logger
protected RouterCachingService $routerCachingService
protected Route|null $lastMatchedRoute
protected Route|null $lastResolvedRoute

Methods

void
injectLogger(LoggerInterface $logger)

Injects the (system) logger based on PSR-3.

array
route(RouteContext $routeContext)

Iterates through all configured routes and calls matches() on them.

getLastMatchedRoute()

Returns the route that has been matched with the last route() call.

UriInterface
resolve(ResolveContext $resolveContext)

Builds the corresponding uri (excluding protocol and host) by iterating through all configured routes and calling their respective resolves() method. If no matching route is found, an empty string is returned.

getLastResolvedRoute()

Returns the route that has been resolved with the last resolve() call.

Details

void injectLogger(LoggerInterface $logger)

Injects the (system) logger based on PSR-3.

Parameters

LoggerInterface $logger

Return Value

void

array route(RouteContext $routeContext)

Iterates through all configured routes and calls matches() on them.

Returns the matchResults of the matching route or NULL if no matching route could be found.

Parameters

RouteContext $routeContext

The Route Context containing the current HTTP Request and, optional, Routing RouteParameters

Return Value

array

The results of the matching route

Exceptions

InvalidRouteSetupException
NoMatchingRouteException
InvalidRoutePartValueException

Route getLastMatchedRoute()

Returns the route that has been matched with the last route() call.

Returns NULL if no route matched or route() has not been called yet

Return Value

Route

UriInterface resolve(ResolveContext $resolveContext)

Builds the corresponding uri (excluding protocol and host) by iterating through all configured routes and calling their respective resolves() method. If no matching route is found, an empty string is returned.

Note: calls of this message are cached by RouterCachingAspect

Parameters

ResolveContext $resolveContext

The Resolve Context containing the route values, the request URI and some flags to be resolved

Return Value

UriInterface

The resolved Uri

Exceptions

NoMatchingRouteException

Route getLastResolvedRoute()

Returns the route that has been resolved with the last resolve() call.

Returns NULL if no route was found or resolve() has not been called yet

Return Value

Route