You are here

public function RouteProvider::getRouteCollectionForRequest in Multiversion 8

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

\Symfony\Component\HttpFoundation\Request $request: A request against which to match.

Return value

\Symfony\Component\Routing\RouteCollection RouteCollection with all urls that could potentially match $request. Empty collection if nothing can match. The collection will be sorted from highest to lowest fit (match of path parts) and then in ascending order by route name for routes with the same fit.

Overrides RouteProvider::getRouteCollectionForRequest

File

src/RouteProvider.php, line 45

Class

RouteProvider
Overrides core RouteProvider.

Namespace

Drupal\multiversion

Code

public function getRouteCollectionForRequest(Request $request) {

  // Cache both the system path as well as route parameters and matching
  // routes.
  $workspace_id = $this->workspaceManager
    ->getActiveWorkspaceId();

  // @todo Remove this when Multiversion requires Drupal 8.5 or newer.
  if (!method_exists($this, 'getCurrentLanguageCacheIdPart')) {
    $cid = 'route:' . "workspace{$workspace_id}:" . $request
      ->getPathInfo() . ':' . $request
      ->getQueryString();
  }
  else {
    $language_part = $this
      ->getCurrentLanguageCacheIdPart();
    $cid = 'route:' . "workspace{$workspace_id}:" . "{$language_part}:" . $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;
  }
}