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
arrayRoute extensions
-
$_named protected
arrayThe hash map of named routes that are in this collection.
-
$_paths protected
arrayRoutes indexed by path prefix.
-
$_routeTable protected
arrayThe routes connected to this collection.
-
$_routes protected
arrayThe 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
arrayThe set of names of the url
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
_nameoption, which enables named routes.
Returns
voidextensions() ¶ 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
arrayThe valid extensions.
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|falseEither a string on match, or false on failure.
Throws
Cake\Routing\Exception\MissingRouteExceptionwhen 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
arrayAn array of request parameters parsed from the URL.
Throws
Cake\Routing\Exception\MissingRouteExceptionWhen a URL has no matching route.