Class RouteCollection
Contains a collection of routes.
Provides an interface for adding/removing routes and parsing/generating URLs with the routes it contains.
Property Summary
-
$_extensions protected
array
Route extensions
-
$_named protected
Cake\Routing\Route\Route[]
The hash map of named routes that are in this collection.
-
$_paths protected
array
Routes indexed by path prefix.
-
$_routeTable protected
array
The routes connected to this collection.
-
$_routes protected
Cake\Routing\Route\Route[]
The routes connected to this collection.
Method Summary
-
_getNames() protected
Get the set of names from the $url. Accepts both older style array urls, and newer style urls containing '_name'
-
add() public
Add a route to the collection.
-
extensions() public
Get/set the extensions that the route collection could handle.
-
match() public
Reverse route or match a $url array with the connected routes.
-
named() public
Get the connected named routes.
-
parse() public
Takes the URL string and iterates the routes until one is able to parse the route.
-
parseRequest() public
Takes the ServerRequestInterface, iterates the routes until one is able to parse the route.
-
routes() public
Get all the connected routes as a flat list.
Method Detail
_getNames() ¶ protected
_getNames(array $url): array
Get the set of names from the $url. Accepts both older style array urls, and newer style urls containing '_name'
Parameters
-
array
$url The url to match.
Returns
array
add() ¶ public
add(Cake\Routing\Route\Route $route, array $options = []): void
Add a route to the collection.
Parameters
-
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.
Returns
void
extensions() ¶ public
extensions(null|string|array $extensions = null, bool $merge = true): array
Get/set the extensions that the route collection could handle.
Parameters
-
null|string|array
$extensions optional Either the list of extensions to set, or null to get.
-
bool
$merge optional Whether to merge with or override existing extensions. Defaults to
true
.
Returns
array
match() ¶ public
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.
Parameters
-
array
$url The URL to match.
-
array
$context The request context to use. Contains _base, _port, _host, _scheme and params keys.
Returns
string
Throws
Cake\Routing\Exception\MissingRouteException
When no route could be matched.
named() ¶ public
named(): Cake\Routing\Route\Route[]
Get the connected named routes.
Returns
Cake\Routing\Route\Route[]
parse() ¶ public
parse(string $url, string $method = ''): array
Takes the URL string and iterates the routes until one is able to parse the route.
Parameters
-
string
$url URL to parse.
-
string
$method optional The HTTP method to use.
Returns
array
Throws
Cake\Routing\Exception\MissingRouteException
When a URL has no matching route.
parseRequest() ¶ public
parseRequest(Psr\Http\Messages\ServerRequestInterface $request): array
Takes the ServerRequestInterface, iterates the routes until one is able to parse the route.
Parameters
-
Psr\Http\Messages\ServerRequestInterface
$request The request to parse route data from.
Returns
array
Throws
Cake\Routing\Exception\MissingRouteException
When a URL has no matching route.
routes() ¶ public
routes(): Cake\Routing\Route\Route[]
Get all the connected routes as a flat list.
Returns
Cake\Routing\Route\Route[]
Property Detail
$_named ¶ protected
The hash map of named routes that are in this collection.
Type
Cake\Routing\Route\Route[]