You are here

class RouteProvider in Multiversion 8

Overrides core RouteProvider.

Hierarchy

Expanded class hierarchy of RouteProvider

1 string reference to 'RouteProvider'
multiversion.services.yml in ./multiversion.services.yml
multiversion.services.yml
1 service uses RouteProvider
multiversion.route_provider in ./multiversion.services.yml
Drupal\multiversion\RouteProvider

File

src/RouteProvider.php, line 19

Namespace

Drupal\multiversion
View source
class RouteProvider extends CoreRouteProvider {

  /**
   * The workspace manager.
   *
   * @var \Drupal\multiversion\Workspace\WorkspaceManagerInterface
   */
  private $workspaceManager;

  /**
   * {@inheritdoc}
   */
  public function __construct(Connection $connection, StateInterface $state, CurrentPathStack $current_path, CacheBackendInterface $cache_backend, InboundPathProcessorInterface $path_processor, CacheTagsInvalidatorInterface $cache_tag_invalidator, $table = 'router', LanguageManagerInterface $language_manager = NULL, WorkspaceManagerInterface $workspace_manager) {

    // @todo Remove this when Multiversion requires Drupal 8.5 or newer.
    if (floatval(\Drupal::VERSION) < 8.5) {
      parent::__construct($connection, $state, $current_path, $cache_backend, $path_processor, $cache_tag_invalidator, $table);
    }
    else {
      parent::__construct($connection, $state, $current_path, $cache_backend, $path_processor, $cache_tag_invalidator, $table, $language_manager);
    }
    $this->workspaceManager = $workspace_manager;
  }

  /**
   * {@inheritdoc}
   */
  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;
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RouteProvider::$cache protected property The cache backend.
RouteProvider::$cacheTagInvalidator protected property The cache tag invalidator.
RouteProvider::$connection protected property The database connection from which to read route information.
RouteProvider::$currentPath protected property The current path.
RouteProvider::$extraCacheKeyParts protected property An array of cache key parts to be used for the route match cache.
RouteProvider::$languageManager protected property The language manager.
RouteProvider::$pathProcessor protected property A path processor manager for resolving the system path.
RouteProvider::$routes protected property A cache of already-loaded routes, keyed by route name.
RouteProvider::$serializedRoutes protected property A cache of already-loaded serialized routes, keyed by route name.
RouteProvider::$state protected property The state.
RouteProvider::$tableName protected property The name of the SQL table from which to read the routes.
RouteProvider::$workspaceManager private property The workspace manager.
RouteProvider::addExtraCacheKeyPart public function Adds a cache key part to be used in the cache ID of the route collection. Overrides CacheableRouteProviderInterface::addExtraCacheKeyPart
RouteProvider::getAllRoutes public function Returns all the routes on the system. Overrides RouteProviderInterface::getAllRoutes
RouteProvider::getCandidateOutlines protected function Returns an array of path pattern outlines that could match the path parts. 1
RouteProvider::getCurrentLanguageCacheIdPart protected function Returns the language identifier for the route collection cache.
RouteProvider::getRouteByName public function Find the route using the provided route name.
RouteProvider::getRouteCollectionCacheId protected function Returns the cache ID for the route collection cache.
RouteProvider::getRouteCollectionForRequest public function Finds routes that may potentially match the request. Overrides RouteProvider::getRouteCollectionForRequest
RouteProvider::getRoutesByNames public function Find many routes by their names using the provided list of names.
RouteProvider::getRoutesByPath protected function Get all routes which match a certain pattern.
RouteProvider::getRoutesByPattern public function Get all routes which match a certain pattern. Overrides RouteProviderInterface::getRoutesByPattern
RouteProvider::getRoutesCount public function Determines the total amount of routes.
RouteProvider::getRoutesPaged public function Find an amount of routes with an offset and possible a limit.
RouteProvider::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
RouteProvider::preLoadRoutes public function Pre-load routes by their names using the provided list of names. Overrides PreloadableRouteProviderInterface::preLoadRoutes
RouteProvider::reset public function Resets the route provider object. Overrides RouteProviderInterface::reset
RouteProvider::routeProviderRouteCompare protected function Comparison function for usort on routes.
RouteProvider::ROUTE_LOAD_CID_PREFIX constant Cache ID prefix used to load routes.
RouteProvider::__construct public function Constructs a new PathMatcher. Overrides RouteProvider::__construct