class Router (View source)

Class for routing requested methods and paths to specific routes.

Methods

__construct(RouteDefinitionProvider $provider)

Router constructor.

route(string $method, string $path)

Routes the given path with the given HTTP request method to a specific route.

string
generateUrl(string $name, array $parameters = [])

Returns the encoded URL for the route with the given name.

Details

__construct(RouteDefinitionProvider $provider)

Router constructor.

Parameters

RouteDefinitionProvider $provider The route definition provider

Route route(string $method, string $path)

Routes the given path with the given HTTP request method to a specific route.

Parameters

string $method The HTTP request method
string $path The decoded request path

Return Value

Route Matching route

Exceptions

MethodNotAllowedException If the path matches at least one route, but the method is not allowed
RouteNotFoundException If no route matches the given path

string generateUrl(string $name, array $parameters = [])

Returns the encoded URL for the route with the given name.

Parameters

string $name Name of the route
array $parameters Values for the route parameters

Return Value

string The encoded URL for the route