Contains a collection of routes.
Provides an interface for adding/removing routes and parsing/generating URLs with the routes it contains.
array<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.
arrayCake\Routing\Route\Route>
The hash map of named routes that are in this collection.
array<string, arrayCake\Routing\Route\Route>>
Routes indexed by path prefix.
array<string, arrayCake\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'
Add a route to the collection.
Get the extensions that can be handled.
Get an array of middleware given a list of names
Check if the named middleware has been registered.
Check if the named middleware group has been created.
Reverse route or match a $url array with the connected routes.
Check if the named middleware or middleware group has been registered.
Add middleware to a middleware group
Get the connected named routes.
Takes the URL string and iterates the routes until one is able to parse the route.
Takes the ServerRequestInterface, iterates the routes until one is able to parse the route.
Register a middleware with the RouteCollection.
Get all the connected routes as a flat list.
Set the extensions that the route collection can handle.
_getNames(array $url): array<string>
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.
array<string>
add(Cake\Routing\Route\Route $route, array<string, mixed> $options = []): void
Add a route to the collection.
Cake\Routing\Route\Route
$route The route object to add.
array<string, mixed>
$options optional Additional options for the route. Primarily for the _name
option, which enables named routes.
void
getExtensions(): array<string>
Get the extensions that can be handled.
array<string>
getMiddleware(array<string> $names): array
Get an array of middleware given a list of names
array<string>
$names The names of the middleware or groups to fetch
array
RuntimeException
hasMiddleware(string $name): bool
Check if the named middleware has been registered.
string
$name The name of the middleware to check.
bool
hasMiddlewareGroup(string $name): bool
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): string
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
Cake\Routing\Exception\MissingRouteException
middlewareExists(string $name): bool
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<string> $middlewareNames): $this
Add middleware to a middleware group
string
$name Name of the middleware group
array<string>
$middlewareNames Names of the middleware
$this
RuntimeException
named(): arrayCake\Routing\Route\Route>
Get the connected named routes.
arrayCake\Routing\Route\Route>
parse(string $url, string $method = ''): array
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
Cake\Routing\Exception\MissingRouteException
parseRequest(Psr\Http\Message\ServerRequestInterface $request): array
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
Cake\Routing\Exception\MissingRouteException
registerMiddleware(string $name, Psr\Http\Server\MiddlewareInterfaceClosure|string $middleware): $this
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.
Psr\Http\Server\MiddlewareInterfaceClosure|string
$middleware The middleware to register.
$this
RuntimeException
routes(): arrayCake\Routing\Route\Route>
Get all the connected routes as a flat list.
arrayCake\Routing\Route\Route>
setExtensions(array<string> $extensions, bool $merge = true): $this
Set the extensions that the route collection can handle.
array<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
array<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.
arrayCake\Routing\Route\Route>
Routes indexed by path prefix.
array<string, arrayCake\Routing\Route\Route>>
The routes connected to this collection.
array<string, arrayCake\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.4/class-Cake.Routing.RouteCollection.html