diff --git a/core/lib/Drupal/Core/Routing/RouteProvider.php b/core/lib/Drupal/Core/Routing/RouteProvider.php index 370da07..e315ca2 100644 --- a/core/lib/Drupal/Core/Routing/RouteProvider.php +++ b/core/lib/Drupal/Core/Routing/RouteProvider.php @@ -9,6 +9,7 @@ use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\CacheBackendInterface; +use Drupal\Core\Cache\CacheTagsInvalidatorInterface; use Drupal\Core\Path\CurrentPathStack; use Drupal\Core\PathProcessor\InboundPathProcessorInterface; use Drupal\Core\State\StateInterface; @@ -77,6 +78,13 @@ class RouteProvider implements PreloadableRouteProviderInterface, PagedRouteProv protected $cache; /** + * The cache tag invalidator. + * + * @var \Drupal\Core\Cache\CacheTagsInvalidatorInterface + */ + protected $cacheTagInvalidator; + + /** * A path processor manager for resolving the system path. * * @var \Drupal\Core\PathProcessor\InboundPathProcessorInterface @@ -86,7 +94,7 @@ class RouteProvider implements PreloadableRouteProviderInterface, PagedRouteProv /** * Cache ID prefix used to load routes. */ - const ROUTE_LOAD_CID = 'route_provider.route_load:'; + const ROUTE_LOAD_CID_PREFIX = 'route_provider.route_load:'; /** * Constructs a new PathMatcher. @@ -101,15 +109,18 @@ class RouteProvider implements PreloadableRouteProviderInterface, PagedRouteProv * The cache backend. * @param \Drupal\Core\PathProcessor\InboundPathProcessorInterface $path_processor * The path processor. + * @param \Drupal\Core\Cache\CacheTagsInvalidatorInterface $cache_tag_invalidator + * The cache tag invalidator. * @param string $table * The table in the database to use for matching. */ - public function __construct(Connection $connection, StateInterface $state, CurrentPathStack $current_path, CacheBackendInterface $cache_backend, InboundPathProcessorInterface $path_processor, $table = 'router') { + public function __construct(Connection $connection, StateInterface $state, CurrentPathStack $current_path, CacheBackendInterface $cache_backend, InboundPathProcessorInterface $path_processor, CacheTagsInvalidatorInterface $cache_tag_invalidator, $table = 'router') { $this->connection = $connection; $this->state = $state; $this->tableName = $table; $this->currentPath = $current_path; $this->cache = $cache_backend; + $this->cacheTagInvalidator = $cache_tag_invalidator; $this->pathProcessor = $path_processor; } @@ -196,7 +207,7 @@ public function preLoadRoutes($names) { $routes_to_load = array_diff($names, array_keys($this->routes), array_keys($this->serializedRoutes)); if ($routes_to_load) { - $cid = static::ROUTE_LOAD_CID . hash('sha512', serialize($routes_to_load)); + $cid = static::ROUTE_LOAD_CID_PREFIX . hash('sha512', serialize($routes_to_load)); if ($cache = $this->cache->get($cid)) { $routes = $cache->data; } @@ -355,7 +366,7 @@ public function getAllRoutes() { public function reset() { $this->routes = array(); $this->serializedRoutes = array(); - Cache::invalidateTags(['routes']); + $this->cacheTagInvalidator->invalidateTags(['routes']); } /** diff --git a/core/modules/system/src/Tests/Routing/RouteProviderTest.php b/core/modules/system/src/Tests/Routing/RouteProviderTest.php index 74cbaa3..e59097c 100644 --- a/core/modules/system/src/Tests/Routing/RouteProviderTest.php +++ b/core/modules/system/src/Tests/Routing/RouteProviderTest.php @@ -71,6 +71,13 @@ class RouteProviderTest extends KernelTestBase { */ protected $pathProcessor; + /** + * The cache tags invalidator. + * + * @var \Drupal\Core\Cache\CacheTagsInvalidatorInterface + */ + protected $cacheTagsInvalidator; + protected function setUp() { parent::setUp(); $this->fixtures = new RoutingFixtures(); @@ -78,6 +85,7 @@ protected function setUp() { $this->currentPath = new CurrentPathStack(new RequestStack()); $this->cache = new MemoryBackend('data'); $this->pathProcessor = \Drupal::service('path_processor_manager'); + $this->cacheTagsInvalidator = \Drupal::service('cache_tags.invalidator'); $this->installSchema('system', 'url_alias'); } @@ -107,7 +115,7 @@ protected function tearDown() { public function testCandidateOutlines() { $connection = Database::getConnection(); - $provider = new RouteProvider($connection, $this->state, $this->currentPath, $this->cache, $this->pathProcessor, 'test_routes'); + $provider = new RouteProvider($connection, $this->state, $this->currentPath, $this->cache, $this->cacheTagsInvalidator, $this->pathProcessor, 'test_routes'); $parts = array('node', '5', 'edit'); @@ -130,7 +138,7 @@ public function testCandidateOutlines() { */ function testExactPathMatch() { $connection = Database::getConnection(); - $provider = new RouteProvider($connection, $this->state, $this->currentPath, $this->cache, $this->pathProcessor, 'test_routes'); + $provider = new RouteProvider($connection, $this->state, $this->currentPath, $this->cache, $this->cacheTagsInvalidator, $this->pathProcessor, 'test_routes'); $this->fixtures->createTables($connection); @@ -154,7 +162,7 @@ function testExactPathMatch() { */ function testOutlinePathMatch() { $connection = Database::getConnection(); - $provider = new RouteProvider($connection, $this->state, $this->currentPath, $this->cache, $this->pathProcessor, 'test_routes'); + $provider = new RouteProvider($connection, $this->state, $this->currentPath, $this->cache, $this->cacheTagsInvalidator, $this->pathProcessor, 'test_routes'); $this->fixtures->createTables($connection); @@ -183,7 +191,7 @@ function testOutlinePathMatch() { */ function testOutlinePathMatchTrailingSlash() { $connection = Database::getConnection(); - $provider = new RouteProvider($connection, $this->state, $this->currentPath, $this->cache, $this->pathProcessor, 'test_routes'); + $provider = new RouteProvider($connection, $this->state, $this->currentPath, $this->cache, $this->cacheTagsInvalidator, $this->pathProcessor, 'test_routes'); $this->fixtures->createTables($connection); @@ -212,7 +220,7 @@ function testOutlinePathMatchTrailingSlash() { */ function testOutlinePathMatchDefaults() { $connection = Database::getConnection(); - $provider = new RouteProvider($connection, $this->state, $this->currentPath, $this->cache, $this->pathProcessor, 'test_routes'); + $provider = new RouteProvider($connection, $this->state, $this->currentPath, $this->cache, $this->cacheTagsInvalidator, $this->pathProcessor, 'test_routes'); $this->fixtures->createTables($connection); @@ -250,7 +258,7 @@ function testOutlinePathMatchDefaults() { */ function testOutlinePathMatchDefaultsCollision() { $connection = Database::getConnection(); - $provider = new RouteProvider($connection, $this->state, $this->currentPath, $this->cache, $this->pathProcessor, 'test_routes'); + $provider = new RouteProvider($connection, $this->state, $this->currentPath, $this->cache, $this->cacheTagsInvalidator, $this->pathProcessor, 'test_routes'); $this->fixtures->createTables($connection); @@ -289,7 +297,7 @@ function testOutlinePathMatchDefaultsCollision() { */ function testOutlinePathMatchDefaultsCollision2() { $connection = Database::getConnection(); - $provider = new RouteProvider($connection, $this->state, $this->currentPath, $this->cache, $this->pathProcessor, 'test_routes'); + $provider = new RouteProvider($connection, $this->state, $this->currentPath, $this->cache, $this->cacheTagsInvalidator, $this->pathProcessor, 'test_routes'); $this->fixtures->createTables($connection); @@ -328,7 +336,7 @@ function testOutlinePathMatchDefaultsCollision2() { */ public function testOutlinePathMatchZero() { $connection = Database::getConnection(); - $provider = new RouteProvider($connection, $this->state, $this->currentPath, $this->cache, $this->pathProcessor, 'test_routes'); + $provider = new RouteProvider($connection, $this->state, $this->currentPath, $this->cache, $this->cacheTagsInvalidator, $this->pathProcessor, 'test_routes'); $this->fixtures->createTables($connection); @@ -363,7 +371,7 @@ public function testOutlinePathMatchZero() { */ function testOutlinePathNoMatch() { $connection = Database::getConnection(); - $provider = new RouteProvider($connection, $this->state, $this->currentPath, $this->cache, $this->pathProcessor, 'test_routes'); + $provider = new RouteProvider($connection, $this->state, $this->currentPath, $this->cache, $this->cacheTagsInvalidator, $this->pathProcessor, 'test_routes'); $this->fixtures->createTables($connection); @@ -388,7 +396,7 @@ function testOutlinePathNoMatch() { */ public function testRouteCaching() { $connection = Database::getConnection(); - $provider = new RouteProvider($connection, $this->state, $this->currentPath, $this->cache, $this->pathProcessor, 'test_routes'); + $provider = new RouteProvider($connection, $this->state, $this->currentPath, $this->cache, $this->cacheTagsInvalidator, $this->pathProcessor, 'test_routes'); $this->fixtures->createTables($connection); @@ -450,7 +458,7 @@ public function testRouteCaching() { */ public function testRouteByName() { $connection = Database::getConnection(); - $provider = new RouteProvider($connection, $this->state, $this->currentPath, $this->cache, $this->pathProcessor, 'test_routes'); + $provider = new RouteProvider($connection, $this->state, $this->currentPath, $this->cache, $this->cacheTagsInvalidator, $this->pathProcessor, 'test_routes'); $this->fixtures->createTables($connection); @@ -485,7 +493,7 @@ public function testRouteByName() { */ public function testGetRoutesByPatternWithLongPatterns() { $connection = Database::getConnection(); - $provider = new RouteProvider($connection, $this->state, $this->currentPath, $this->cache, $this->pathProcessor, 'test_routes'); + $provider = new RouteProvider($connection, $this->state, $this->currentPath, $this->cache, $this->cacheTagsInvalidator, $this->pathProcessor, 'test_routes'); $this->fixtures->createTables($connection); // This pattern has only 3 parts, so we will get candidates, but no routes, @@ -543,7 +551,7 @@ public function testGetRoutesByPatternWithLongPatterns() { */ public function testGetRoutesPaged() { $connection = Database::getConnection(); - $provider = new RouteProvider($connection, $this->state, $this->currentPath, $this->cache, $this->pathProcessor, 'test_routes'); + $provider = new RouteProvider($connection, $this->state, $this->currentPath, $this->cache, $this->cacheTagsInvalidator, $this->pathProcessor, 'test_routes'); $this->fixtures->createTables($connection); $dumper = new MatcherDumper($connection, $this->state, 'test_routes');