Contains a collection of routes.
Provides an interface for adding/removing routes and parsing/generating URLs with the routes it contains.
string[]
Route extensions
array
A map of middleware names and the related objects.
array
A map of middleware group names and the related middleware names.
\Cake\Routing\Route\Route[]
The hash map of named routes that are in this collection.
array
Routes indexed by path prefix.
array
The routes connected to this collection.
\Cake\Routing\Route\Route[]
The routes connected to this collection.
Get the set of names from the $url. Accepts both older style array urls, and newer style urls containing '_name'
Takes the ServerRequestInterface, iterates the routes until one is able to parse the route.
_getNames(array $url)
Get the set of names from the $url. Accepts both older style array urls, and newer style urls containing '_name'
array
$url The url to match.
string[]
The set of names of the url
add(\Cake\Routing\Route\Route $route, array $options)
Add a route to the collection.
\Cake\Routing\Route\Route
$route The route object to add.
array
$options optional Additional options for the route. Primarily for the _name
option, which enables named routes.
getExtensions()
Get the extensions that can be handled.
string[]
The valid extensions.
getMiddleware(array $names)
Get an array of middleware given a list of names
string[]
$names The names of the middleware or groups to fetch
array
An array of middleware. If any of the passed names are groups, the groups middleware will be flattened into the returned list.
RuntimeException
hasMiddleware(string $name)
Check if the named middleware has been registered.
string
$name The name of the middleware to check.
bool
hasMiddlewareGroup(string $name)
Check if the named middleware group has been created.
string
$name The name of the middleware group to check.
bool
match(array $url, array $context)
Reverse route or match a $url array with the connected routes.
Returns either the URL string generated by the route, or throws an exception on failure.
array
$url The URL to match.
array
$context The request context to use. Contains _base, _port, _host, _scheme and params keys.
string
The URL string on match.
Cake\Routing\Exception\MissingRouteException
middlewareExists(string $name)
Check if the named middleware or middleware group has been registered.
string
$name The name of the middleware to check.
bool
middlewareGroup(string $name, array $middlewareNames)
Add middleware to a middleware group
string
$name Name of the middleware group
string[]
$middlewareNames Names of the middleware
$this
RuntimeException
named()
Get the connected named routes.
\Cake\Routing\Route\Route[]
parse(string $url, string $method)
Takes the URL string and iterates the routes until one is able to parse the route.
string
$url URL to parse.
string
$method optional The HTTP method to use.
array
An array of request parameters parsed from the URL.
Cake\Routing\Exception\MissingRouteException
parseRequest(\Psr\Http\Message\ServerRequestInterface $request)
Takes the ServerRequestInterface, iterates the routes until one is able to parse the route.
\Psr\Http\Message\ServerRequestInterface
$request The request to parse route data from.
array
An array of request parameters parsed from the URL.
Cake\Routing\Exception\MissingRouteException
registerMiddleware(string $name, mixed $middleware)
Register a middleware with the RouteCollection.
Once middleware has been registered, it can be applied to the current routing scope or any child scopes that share the same RouteCollection.
string
$name The name of the middleware. Used when applying middleware to a scope.
string|\Closure|\Psr\Http\Server\MiddlewareInterface
$middleware The middleware to register.
$this
RuntimeException
routes()
Get all the connected routes as a flat list.
\Cake\Routing\Route\Route[]
setExtensions(array $extensions, bool $merge)
Set the extensions that the route collection can handle.
string[]
$extensions The list of extensions to set.
bool
$merge optional Whether to merge with or override existing extensions. Defaults to true
.
$this
Route extensions
string[]
A map of middleware names and the related objects.
array
A map of middleware group names and the related middleware names.
array
The hash map of named routes that are in this collection.
\Cake\Routing\Route\Route[]
Routes indexed by path prefix.
array
The routes connected to this collection.
array
The routes connected to this collection.
\Cake\Routing\Route\Route[]
© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/4.1/class-Cake.Routing.RouteCollection.html