Mercurial > hg > isophonics-drupal-site
comparison core/lib/Drupal/Core/Routing/RouteProvider.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | 7a779792577d |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
13:5fb285c0d0e3 | 14:1fec387a4317 |
---|---|
4 | 4 |
5 use Drupal\Component\Utility\Unicode; | 5 use Drupal\Component\Utility\Unicode; |
6 use Drupal\Core\Cache\Cache; | 6 use Drupal\Core\Cache\Cache; |
7 use Drupal\Core\Cache\CacheBackendInterface; | 7 use Drupal\Core\Cache\CacheBackendInterface; |
8 use Drupal\Core\Cache\CacheTagsInvalidatorInterface; | 8 use Drupal\Core\Cache\CacheTagsInvalidatorInterface; |
9 use Drupal\Core\Language\LanguageInterface; | |
10 use Drupal\Core\Language\LanguageManagerInterface; | |
9 use Drupal\Core\Path\CurrentPathStack; | 11 use Drupal\Core\Path\CurrentPathStack; |
10 use Drupal\Core\PathProcessor\InboundPathProcessorInterface; | 12 use Drupal\Core\PathProcessor\InboundPathProcessorInterface; |
11 use Drupal\Core\State\StateInterface; | 13 use Drupal\Core\State\StateInterface; |
12 use Symfony\Cmf\Component\Routing\PagedRouteCollection; | 14 use Symfony\Cmf\Component\Routing\PagedRouteCollection; |
13 use Symfony\Cmf\Component\Routing\PagedRouteProviderInterface; | 15 use Symfony\Cmf\Component\Routing\PagedRouteProviderInterface; |
82 * A path processor manager for resolving the system path. | 84 * A path processor manager for resolving the system path. |
83 * | 85 * |
84 * @var \Drupal\Core\PathProcessor\InboundPathProcessorInterface | 86 * @var \Drupal\Core\PathProcessor\InboundPathProcessorInterface |
85 */ | 87 */ |
86 protected $pathProcessor; | 88 protected $pathProcessor; |
89 | |
90 /** | |
91 * The language manager. | |
92 * | |
93 * @var \Drupal\Core\Language\LanguageManagerInterface | |
94 */ | |
95 protected $languageManager; | |
87 | 96 |
88 /** | 97 /** |
89 * Cache ID prefix used to load routes. | 98 * Cache ID prefix used to load routes. |
90 */ | 99 */ |
91 const ROUTE_LOAD_CID_PREFIX = 'route_provider.route_load:'; | 100 const ROUTE_LOAD_CID_PREFIX = 'route_provider.route_load:'; |
105 * The path processor. | 114 * The path processor. |
106 * @param \Drupal\Core\Cache\CacheTagsInvalidatorInterface $cache_tag_invalidator | 115 * @param \Drupal\Core\Cache\CacheTagsInvalidatorInterface $cache_tag_invalidator |
107 * The cache tag invalidator. | 116 * The cache tag invalidator. |
108 * @param string $table | 117 * @param string $table |
109 * (Optional) The table in the database to use for matching. Defaults to 'router' | 118 * (Optional) The table in the database to use for matching. Defaults to 'router' |
110 */ | 119 * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager |
111 public function __construct(Connection $connection, StateInterface $state, CurrentPathStack $current_path, CacheBackendInterface $cache_backend, InboundPathProcessorInterface $path_processor, CacheTagsInvalidatorInterface $cache_tag_invalidator, $table = 'router') { | 120 * (Optional) The language manager. |
121 */ | |
122 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) { | |
112 $this->connection = $connection; | 123 $this->connection = $connection; |
113 $this->state = $state; | 124 $this->state = $state; |
114 $this->currentPath = $current_path; | 125 $this->currentPath = $current_path; |
115 $this->cache = $cache_backend; | 126 $this->cache = $cache_backend; |
116 $this->cacheTagInvalidator = $cache_tag_invalidator; | 127 $this->cacheTagInvalidator = $cache_tag_invalidator; |
117 $this->pathProcessor = $path_processor; | 128 $this->pathProcessor = $path_processor; |
118 $this->tableName = $table; | 129 $this->tableName = $table; |
130 $this->languageManager = $language_manager ?: \Drupal::languageManager(); | |
119 } | 131 } |
120 | 132 |
121 /** | 133 /** |
122 * Finds routes that may potentially match the request. | 134 * Finds routes that may potentially match the request. |
123 * | 135 * |
145 * by route name for routes with the same fit. | 157 * by route name for routes with the same fit. |
146 */ | 158 */ |
147 public function getRouteCollectionForRequest(Request $request) { | 159 public function getRouteCollectionForRequest(Request $request) { |
148 // Cache both the system path as well as route parameters and matching | 160 // Cache both the system path as well as route parameters and matching |
149 // routes. | 161 // routes. |
150 $cid = 'route:' . $request->getPathInfo() . ':' . $request->getQueryString(); | 162 $cid = $this->getRouteCollectionCacheId($request); |
151 if ($cached = $this->cache->get($cid)) { | 163 if ($cached = $this->cache->get($cid)) { |
152 $this->currentPath->setPath($cached->data['path'], $request); | 164 $this->currentPath->setPath($cached->data['path'], $request); |
153 $request->query->replace($cached->data['query']); | 165 $request->query->replace($cached->data['query']); |
154 return $cached->data['routes']; | 166 return $cached->data['routes']; |
155 } | 167 } |
429 */ | 441 */ |
430 public function getRoutesCount() { | 442 public function getRoutesCount() { |
431 return $this->connection->query("SELECT COUNT(*) FROM {" . $this->connection->escapeTable($this->tableName) . "}")->fetchField(); | 443 return $this->connection->query("SELECT COUNT(*) FROM {" . $this->connection->escapeTable($this->tableName) . "}")->fetchField(); |
432 } | 444 } |
433 | 445 |
446 /** | |
447 * Returns the cache ID for the route collection cache. | |
448 * | |
449 * @param \Symfony\Component\HttpFoundation\Request $request | |
450 * The request object. | |
451 * | |
452 * @return string | |
453 * The cache ID. | |
454 */ | |
455 protected function getRouteCollectionCacheId(Request $request) { | |
456 // Include the current language code in the cache identifier as | |
457 // the language information can be elsewhere than in the path, for example | |
458 // based on the domain. | |
459 $language_part = $this->getCurrentLanguageCacheIdPart(); | |
460 return 'route:' . $language_part . ':' . $request->getPathInfo() . ':' . $request->getQueryString(); | |
461 } | |
462 | |
463 /** | |
464 * Returns the language identifier for the route collection cache. | |
465 * | |
466 * @return string | |
467 * The language identifier. | |
468 */ | |
469 protected function getCurrentLanguageCacheIdPart() { | |
470 // This must be in sync with the language logic in | |
471 // \Drupal\Core\PathProcessor\PathProcessorAlias::processInbound() and | |
472 // \Drupal\Core\Path\AliasManager::getPathByAlias(). | |
473 // @todo Update this if necessary in https://www.drupal.org/node/1125428. | |
474 return $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_URL)->getId(); | |
475 } | |
476 | |
434 } | 477 } |