You are here

class DomainRouteProvider in Domain Access 8

Custom router.route_provider service to make it domain context sensitive.

The default behaviour is to cache routes by path and query parameters only, for multiple domains this can make the home page of domain 1 be served from cache as the home page of domain 2.

Originally used by Domain Config, this behavior is tested in domain_config/tests/src/Functional/DomainConfigHomepageTest.php.

We have moved the behavior to the main module to better support extension modules that do not require Domain Config, such as Domain Path.

Hierarchy

Expanded class hierarchy of DomainRouteProvider

1 string reference to 'DomainRouteProvider'
domain.services.yml in domain/domain.services.yml
domain/domain.services.yml
1 service uses DomainRouteProvider
domain.route_provider in domain/domain.services.yml
Drupal\domain\Routing\DomainRouteProvider

File

domain/src/Routing/DomainRouteProvider.php, line 28

Namespace

Drupal\domain\Routing
View source
class DomainRouteProvider extends RouteProvider {

  /**
   * DomainRouteProvider constructor.
   *
   * Extends the core RouteProvider. Note that the Kernel tests load a
   * different RouteProvider, which means we cannot declare a common interface
   * for the $inner_service parameter.
   *
   * @see Drupal\Core\Routing\RouteProvider::__construct()
   */
  public function __construct($inner_service, Connection $connection, StateInterface $state, CurrentPathStack $current_path, CacheBackendInterface $cache_backend, InboundPathProcessorInterface $path_processor, CacheTagsInvalidatorInterface $cache_tag_invalidator, $table = 'router', LanguageManagerInterface $language_manager = NULL) {
    $this->innerService = $inner_service;
    parent::__construct($connection, $state, $current_path, $cache_backend, $path_processor, $cache_tag_invalidator, $table, $language_manager);
  }

  /**
   * Returns the cache ID for the route collection cache.
   *
   * We are overriding the cache id by inserting the host to the cid.
   *
   * @param \Symfony\Component\HttpFoundation\Request $request
   *   The request object.
   *
   * @see \Drupal\Core\Routing\RouteProvider::getRouteCollectionCacheId()
   *
   * @return string
   *   The cache ID.
   */
  protected function getRouteCollectionCacheId(Request $request) {

    // Include the current language code in the cache identifier as
    // the language information can be elsewhere than in the path, for example
    // based on the domain.
    $language_part = $this
      ->getCurrentLanguageCacheIdPart();
    return 'route:' . $request
      ->getHost() . ':' . $language_part . ':' . $request
      ->getPathInfo() . ':' . $request
      ->getQueryString();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DomainRouteProvider::getRouteCollectionCacheId protected function Returns the cache ID for the route collection cache. Overrides RouteProvider::getRouteCollectionCacheId
DomainRouteProvider::__construct public function DomainRouteProvider constructor. Overrides RouteProvider::__construct
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::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::getRouteCollectionForRequest public function Finds routes that may potentially match the request.
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.