Router
final class Router (View source)
Collects immutable route definitions and resolves requests after registration freezes.
It owns route-name uniqueness and path normalization but leaves request preprocessing to the dispatch boundary.
Methods
Initializes an empty mutable route collection.
Registers a GET route using the current group prefix.
Registers a POST route using the current group prefix.
Registers a PUT route using the current group prefix.
Registers a PATCH route using the current group prefix.
Registers a DELETE route using the current group prefix.
Registers a HEAD route using the current group prefix.
Registers an OPTIONS route using the current group prefix.
Registers a named GET route and reserves its URL-generation name.
Registers a named POST route and reserves its URL-generation name.
Registers a named PUT route and reserves its URL-generation name.
Registers a named PATCH route and reserves its URL-generation name.
Registers a named DELETE route and reserves its URL-generation name.
Registers a named HEAD route and reserves its URL-generation name.
Registers a named OPTIONS route and reserves its URL-generation name.
Adds one route definition and applies constraints configured for localized groups.
Adds one named route after rejecting a duplicate effective name.
Runs a registration callback with a temporary path prefix and returns its routes.
Registers parallel plain and locale-prefixed variants for the callback's routes.
Configures the static locale-prefix convention used by future localized groups.
Generates a path for a named route and appends unused parameters as a query string.
Prevents further route and localized-route configuration changes.
Reports whether route registration has become immutable.
Matches the request method against its URI path or a dispatch-only path override.
Lists normalized HTTP methods that have a route for the supplied path.
Reports whether one method has an explicitly registered route for the path.
Details
__construct
__construct()
Initializes an empty mutable route collection.
get
Route
get(string $path, ControllerAction $action)
Registers a GET route using the current group prefix.
post
Route
post(string $path, ControllerAction $action)
Registers a POST route using the current group prefix.
put
Route
put(string $path, ControllerAction $action)
Registers a PUT route using the current group prefix.
patch
Route
patch(string $path, ControllerAction $action)
Registers a PATCH route using the current group prefix.
delete
Route
delete(string $path, ControllerAction $action)
Registers a DELETE route using the current group prefix.
head
Route
head(string $path, ControllerAction $action)
Registers a HEAD route using the current group prefix.
options
Route
options(string $path, ControllerAction $action)
Registers an OPTIONS route using the current group prefix.
getNamed
Route
getNamed(string $name, string $path, ControllerAction $action)
Registers a named GET route and reserves its URL-generation name.
postNamed
Route
postNamed(string $name, string $path, ControllerAction $action)
Registers a named POST route and reserves its URL-generation name.
putNamed
Route
putNamed(string $name, string $path, ControllerAction $action)
Registers a named PUT route and reserves its URL-generation name.
patchNamed
Route
patchNamed(string $name, string $path, ControllerAction $action)
Registers a named PATCH route and reserves its URL-generation name.
deleteNamed
Route
deleteNamed(string $name, string $path, ControllerAction $action)
Registers a named DELETE route and reserves its URL-generation name.
headNamed
Route
headNamed(string $name, string $path, ControllerAction $action)
Registers a named HEAD route and reserves its URL-generation name.
optionsNamed
Route
optionsNamed(string $name, string $path, ControllerAction $action)
Registers a named OPTIONS route and reserves its URL-generation name.
map
Route
map(HttpMethod|string $method, string $path, ControllerAction $action)
Adds one route definition and applies constraints configured for localized groups.
mapNamed
Route
mapNamed(string $name, HttpMethod|string $method, string $path, ControllerAction $action)
Adds one named route after rejecting a duplicate effective name.
group
RouteGroup
group(string $prefix, callable $builder)
Runs a registration callback with a temporary path prefix and returns its routes.
localizedGroup
LocalizedRouteGroup
localizedGroup(callable $builder)
Registers parallel plain and locale-prefixed variants for the callback's routes.
configureLocalizedRoutes
void
configureLocalizedRoutes(string $routeNamePrefix = 'localized.', string|null $routePrefix = null, string $localeParameter = 'locale', array $supportedLocales = [])
Configures the static locale-prefix convention used by future localized groups.
It must run before route registration is frozen.
url
string
url(string $name, array $params = [])
Generates a path for a named route and appends unused parameters as a query string.
freeze
void
freeze()
Prevents further route and localized-route configuration changes.
isFrozen
bool
isFrozen()
Reports whether route registration has become immutable.
match
RouteMatch
match(ServerRequestInterface $request, string|null $dispatchPath = null)
Matches the request method against its URI path or a dispatch-only path override.
The override changes only route selection; request metadata and the query-free path reported by a missing-route exception remain those of the original request.
allowedMethodsForPath
array
allowedMethodsForPath(string $path)
Lists normalized HTTP methods that have a route for the supplied path.
hasExplicitRouteForPath
bool
hasExplicitRouteForPath(HttpMethod|string $method, string $path)
Reports whether one method has an explicitly registered route for the path.