class Router implements RouterInterface (View source)

The default web router

Properties

protected LoggerInterface $logger
protected ConfigurationManager $configurationManager
protected RouterCachingService $routerCachingService
protected array $routesConfiguration

Array containing the configuration for all routes

protected Route[] $routes

Array of routes to match against

protected bool $routesCreated

true if route object have been created, otherwise false

protected Route $lastMatchedRoute
protected Route $lastResolvedRoute

Methods

void
injectLogger(LoggerInterface $logger)

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

void
setRoutesConfiguration(array $routesConfiguration = null)

Sets the routes configuration.

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.

array
getRoutes()

Returns a list of configured routes

void
addRoute(Route $route)

Manually adds a route to the beginning of the configured routes

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.

void
createRoutesFromConfiguration()

Creates \Neos\Flow\Mvc\Routing\Route objects from the injected routes configuration.

void
initializeRoutesConfiguration()

Checks if a routes configuration was set and otherwise loads the configuration from the configuration manager.

Details

void injectLogger(LoggerInterface $logger)

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

Parameters

LoggerInterface $logger

Return Value

void

void setRoutesConfiguration(array $routesConfiguration = null)

Sets the routes configuration.

Parameters

array $routesConfiguration

The routes configuration or NULL if it should be fetched from configuration

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

array getRoutes()

Returns a list of configured routes

Return Value

array

void addRoute(Route $route)

Manually adds a route to the beginning of the configured routes

Parameters

Route $route

Return Value

void

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

protected void createRoutesFromConfiguration()

Creates \Neos\Flow\Mvc\Routing\Route objects from the injected routes configuration.

Return Value

void

Exceptions

InvalidRouteSetupException

protected void initializeRoutesConfiguration()

Checks if a routes configuration was set and otherwise loads the configuration from the configuration manager.

Return Value

void