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
array
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
array
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 defined routes. Returns either the string URL generate by the route, or false on failure.
-
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.
-
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|false
Reverse route or match a $url array with the defined routes. Returns either the string URL generate by the route, or false 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|false
Throws
Cake\Routing\Exception\MissingRouteException
when a route cannot be matched.
parse() ¶ public
parse(string $url): array
Takes the URL string and iterates the routes until one is able to parse the route.
Parameters
-
string
$url URL to parse.
Returns
array
Throws
Cake\Routing\Exception\MissingRouteException
When a URL has no matching route.