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 protectedarray<string>Route extensions 
- 
        $_middleware protectedarrayA map of middleware names and the related objects. 
- 
        $_middlewareGroups protectedarrayA map of middleware group names and the related middleware names. 
- 
        $_named protectedarray<Cake\Routing\Route\Route>The hash map of named routes that are in this collection. 
- 
        $_paths protectedarray<string, array<Cake\Routing\Route\Route>>Routes indexed by path prefix. 
- 
        $_routeTable protectedarray<string, array<Cake\Routing\Route\Route>>The routes connected to this collection. 
- 
        $staticPaths protectedarray<string, array<Cake\Routing\Route\Route>>Routes indexed by static path. 
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. 
- 
          getExtensions() publicGet the extensions that can be handled. 
- 
          getMiddleware() publicGet an array of middleware given a list of names 
- 
          hasMiddleware() publicCheck if the named middleware has been registered. 
- 
          hasMiddlewareGroup() publicCheck if the named middleware group has been created. 
- 
          match() publicReverse route or match a $url array with the connected routes. 
- 
          middlewareExists() publicCheck if the named middleware or middleware group has been registered. 
- 
          middlewareGroup() publicAdd middleware to a middleware group 
- 
          named() publicGet the connected named routes. 
- 
          parseRequest() publicTakes the ServerRequestInterface, iterates the routes until one is able to parse the route. 
- 
          registerMiddleware() publicRegister a middleware with the RouteCollection. 
- 
          routes() publicGet all the connected routes as a flat list. 
- 
          setExtensions() publicSet the extensions that the route collection can handle. 
Method Detail
_getNames() ¶ protected
_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'
Parameters
- 
                array$url
- The url to match. 
Returns
array<string>The set of names of the url
add() ¶ public
add(Cake\Routing\Route\Route $route, array<string, mixed> $options = []): voidAdd a route to the collection.
Parameters
- 
                Cake\Routing\Route\Route$route
- The route object to add. 
- 
                array<string, mixed>$options optional
- Additional options for the route. Primarily for the - _nameoption, which enables named routes.
Returns
voidgetExtensions() ¶ public
getExtensions(): array<string>Get the extensions that can be handled.
Returns
array<string>The valid extensions.
getMiddleware() ¶ public
getMiddleware(array<string> $names): arrayGet an array of middleware given a list of names
Parameters
- 
                array<string>$names
- The names of the middleware or groups to fetch 
Returns
arrayAn array of middleware. If any of the passed names are groups, the groups middleware will be flattened into the returned list.
Throws
InvalidArgumentExceptionwhen a requested middleware does not exist.
hasMiddleware() ¶ public
hasMiddleware(string $name): boolCheck if the named middleware has been registered.
Parameters
- 
                string$name
- The name of the middleware to check. 
Returns
boolhasMiddlewareGroup() ¶ public
hasMiddlewareGroup(string $name): boolCheck if the named middleware group has been created.
Parameters
- 
                string$name
- The name of the middleware group to check. 
Returns
boolmatch() ¶ 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.
middlewareExists() ¶ public
middlewareExists(string $name): boolCheck if the named middleware or middleware group has been registered.
Parameters
- 
                string$name
- The name of the middleware to check. 
Returns
boolmiddlewareGroup() ¶ public
middlewareGroup(string $name, array<string> $middlewareNames): $thisAdd middleware to a middleware group
Parameters
- 
                string$name
- Name of the middleware group 
- 
                array<string>$middlewareNames
- Names of the middleware 
Returns
$thisThrows
InvalidArgumentExceptionnamed() ¶ public
named(): array<Cake\Routing\Route\Route>Get the connected named routes.
Returns
array<Cake\Routing\Route\Route>parseRequest() ¶ public
parseRequest(Psr\Http\Message\ServerRequestInterface $request): arrayTakes the ServerRequestInterface, iterates the routes until one is able to parse the route.
Parameters
- 
                Psr\Http\Message\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.
registerMiddleware() ¶ public
registerMiddleware(string $name, Psr\Http\Server\MiddlewareInterface|Closure|string $middleware): $thisRegister 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.
Parameters
- 
                string$name
- The name of the middleware. Used when applying middleware to a scope. 
- 
                Psr\Http\Server\MiddlewareInterface|Closure|string$middleware
- The middleware to register. 
Returns
$thisroutes() ¶ public
routes(): array<Cake\Routing\Route\Route>Get all the connected routes as a flat list.
Routes will not be returned in the order they were added.
Returns
array<Cake\Routing\Route\Route>setExtensions() ¶ public
setExtensions(array<string> $extensions, bool $merge = true): $thisSet the extensions that the route collection can handle.
Parameters
- 
                array<string>$extensions
- The list of extensions to set. 
- 
                bool$merge optional
- Whether to merge with or override existing extensions. Defaults to - true.
Returns
$thisProperty Detail
$_middlewareGroups ¶ protected
A map of middleware group names and the related middleware names.
Type
array$_named ¶ protected
The hash map of named routes that are in this collection.
Type
array<Cake\Routing\Route\Route>$_paths ¶ protected
Routes indexed by path prefix.
Type
array<string, array<Cake\Routing\Route\Route>>$_routeTable ¶ protected
The routes connected to this collection.
Type
array<string, array<Cake\Routing\Route\Route>>$staticPaths ¶ protected
Routes indexed by static path.
Type
array<string, array<Cake\Routing\Route\Route>>