public function RouteProvider::getRouteCollectionForRequest in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/lib/Drupal/Core/Routing/RouteProvider.php \Drupal\Core\Routing\RouteProvider::getRouteCollectionForRequest()
Finds routes that may potentially match the request.
This may return a mixed list of class instances, but all routes returned must extend the core symfony route. The classes may also implement RouteObjectInterface to link to a content document.
This method may not throw an exception based on implementation specific restrictions on the url. That case is considered a not found - returning an empty array. Exceptions are only used to abort the whole request in case something is seriously broken, like the storage backend being down.
Note that implementations may not implement an optimal matching algorithm, simply a reasonable first pass. That allows for potentially very large route sets to be filtered down to likely candidates, which may then be filtered in memory more completely.
Parameters
Request $request A request against which to match.:
Return value
\Symfony\Component\Routing\RouteCollection with all urls that could potentially match $request. Empty collection if nothing can match.
Overrides RouteProviderInterface::getRouteCollectionForRequest
File
- core/
lib/ Drupal/ Core/ Routing/ RouteProvider.php, line 148 - Contains \Drupal\Core\Routing\RouteProvider.
Class
- RouteProvider
- A Route Provider front-end for all Drupal-stored routes.
Namespace
Drupal\Core\RoutingCode
public function getRouteCollectionForRequest(Request $request) {
// Cache both the system path as well as route parameters and matching
// routes.
$cid = 'route:' . $request
->getPathInfo() . ':' . $request
->getQueryString();
if ($cached = $this->cache
->get($cid)) {
$this->currentPath
->setPath($cached->data['path'], $request);
$request->query
->replace($cached->data['query']);
return $cached->data['routes'];
}
else {
// Just trim on the right side.
$path = $request
->getPathInfo();
$path = $path === '/' ? $path : rtrim($request
->getPathInfo(), '/');
$path = $this->pathProcessor
->processInbound($path, $request);
$this->currentPath
->setPath($path, $request);
// Incoming path processors may also set query parameters.
$query_parameters = $request->query
->all();
$routes = $this
->getRoutesByPath(rtrim($path, '/'));
$cache_value = [
'path' => $path,
'query' => $query_parameters,
'routes' => $routes,
];
$this->cache
->set($cid, $cache_value, CacheBackendInterface::CACHE_PERMANENT, [
'route_match',
]);
return $routes;
}
}