RouteProvider::getRouteCollectionForRequest

public RouteProvider::getRouteCollectionForRequest(Request $request)

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 144

Class

RouteProvider
A Route Provider front-end for all Drupal-stored routes.

Namespace

Drupal\Core\Routing

Code

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;
  }
}
doc_Drupal
2016-10-29 09:39:17
Comments
Leave a Comment

Please login to continue.