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 protectedarrayRoute extensions 
- 
        $_named protectedCake\Routing\Route\Route[]The hash map of named routes that are in this collection. 
- 
        $_paths protectedarrayRoutes indexed by path prefix. 
- 
        $_routeTable protectedarrayThe routes connected to this collection. 
- 
        $_routes protectedCake\Routing\Route\Route[]The routes connected to this collection. 
Method Summary
- 
          _getNames() protectedGet the set of names from the $url. Accepts both older style array urls, and newer style urls containing '_name' 
- 
          add() publicAdd a route to the collection. 
- 
          extensions() publicGet/set the extensions that the route collection could handle. 
- 
          match() publicReverse route or match a $url array with the connected routes. 
- 
          named() publicGet the connected named routes. 
- 
          parse() publicTakes the URL string and iterates the routes until one is able to parse the route. 
- 
          parseRequest() publicTakes the ServerRequestInterface, iterates the routes until one is able to parse the route. 
- 
          routes() publicGet all the connected routes as a flat list. 
Method Detail
_getNames() ¶ protected
_getNames(array $url): arrayGet 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 = []): voidAdd 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): arrayGet/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): stringReverse 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
stringThe URL string on match.
Throws
Cake\Routing\Exception\MissingRouteExceptionWhen 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 = ''): arrayTakes 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
arrayAn array of request parameters parsed from the URL.
Throws
Cake\Routing\Exception\MissingRouteExceptionWhen a URL has no matching route.
parseRequest() ¶ public
parseRequest(Psr\Http\Messages\ServerRequestInterface $request): arrayTakes 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
arrayAn array of request parameters parsed from the URL.
Throws
Cake\Routing\Exception\MissingRouteExceptionWhen 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[]