Commit 4e0e15b2 authored by catch's avatar catch

Issue #2352641 by chx, alexpott: Break router.builder dependency.

parent 06e18f51
......@@ -290,7 +290,7 @@ services:
arguments: ['%container.modules%', '@cache.bootstrap']
theme_handler:
class: Drupal\Core\Extension\ThemeHandler
arguments: ['@config.factory', '@module_handler', '@state', '@info_parser', '@logger.channel.default', '@asset.css.collection_optimizer', '@config.installer', '@config.manager', '@router.builder']
arguments: ['@config.factory', '@module_handler', '@state', '@info_parser', '@logger.channel.default', '@asset.css.collection_optimizer', '@config.installer', '@config.manager', '@router.builder_indicator']
entity.manager:
class: Drupal\Core\Entity\EntityManager
arguments: ['@container.namespaces', '@module_handler', '@cache.discovery', '@language_manager', '@string_translation', '@class_resolver', '@typed_data_manager', '@entity.definitions.installed']
......@@ -529,9 +529,12 @@ services:
arguments: ['@database', '@state']
tags:
- { name: backend_overridable }
router.builder_indicator:
class: Drupal\Core\Routing\RouteBuilderIndicator
arguments: ['@state']
router.builder:
class: Drupal\Core\Routing\RouteBuilder
arguments: ['@router.dumper', '@lock', '@event_dispatcher', '@module_handler', '@controller_resolver', '@state']
arguments: ['@router.dumper', '@lock', '@event_dispatcher', '@module_handler', '@controller_resolver', '@router.builder_indicator']
router.rebuild_subscriber:
class: Drupal\Core\EventSubscriber\RouterRebuildSubscriber
arguments: ['@router.builder']
......
......@@ -812,7 +812,7 @@ public function install(array $module_list, $enable_dependencies = TRUE) {
// Clear plugin manager caches and flag router to rebuild if requested.
\Drupal::getContainer()->get('plugin.cache_clearer')->clearCachedDefinitions();
\Drupal::service('router.builder')->setRebuildNeeded();
\Drupal::service('router.builder_indicator')->setRebuildNeeded();
// Set the schema version to the number of the last update provided by
// the module, or the minimum core schema version.
......@@ -1002,7 +1002,7 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) {
// Clear plugin manager caches and flag router to rebuild if requested.
\Drupal::getContainer()->get('plugin.cache_clearer')->clearCachedDefinitions();
\Drupal::service('router.builder')->setRebuildNeeded();
\Drupal::service('router.builder_indicator')->setRebuildNeeded();
// Update the kernel to exclude the uninstalled modules.
\Drupal::service('kernel')->updateModules($module_filenames, $module_filenames);
......
......@@ -13,8 +13,8 @@
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Config\ConfigInstallerInterface;
use Drupal\Core\Config\ConfigManagerInterface;
use Drupal\Core\Routing\RouteBuilderIndicatorInterface;
use Drupal\Core\State\StateInterface;
use Drupal\Core\Routing\RouteBuilder;
use Psr\Log\LoggerInterface;
/**
......@@ -87,11 +87,11 @@ class ThemeHandler implements ThemeHandlerInterface {
protected $logger;
/**
* The route builder to rebuild the routes if a theme is installed.
* The route builder indicator to rebuild the routes if a theme is installed.
*
* @var \Drupal\Core\Routing\RouteBuilder
* @var \Drupal\Core\Routing\RouteBuilderIndicatorInterface
*/
protected $routeBuilder;
protected $routeBuilderIndicator;
/**
* An extension discovery instance.
......@@ -135,13 +135,13 @@ class ThemeHandler implements ThemeHandlerInterface {
* database.
* @param \Drupal\Core\Config\ConfigManagerInterface $config_manager
* The config manager used to uninstall a theme.
* @param \Drupal\Core\Routing\RouteBuilder $route_builder
* (optional) The route builder to rebuild the routes if a theme is
* installed.
* @param \Drupal\Core\Routing\RouteBuilderIndicatorInterface $route_builder_indicator
* (optional) The route builder indicator service to rebuild the routes if a
* theme is installed.
* @param \Drupal\Core\Extension\ExtensionDiscovery $extension_discovery
* (optional) A extension discovery instance (for unit tests).
*/
public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, StateInterface $state, InfoParserInterface $info_parser,LoggerInterface $logger, AssetCollectionOptimizerInterface $css_collection_optimizer = NULL, ConfigInstallerInterface $config_installer = NULL, ConfigManagerInterface $config_manager = NULL, RouteBuilder $route_builder = NULL, ExtensionDiscovery $extension_discovery = NULL) {
public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, StateInterface $state, InfoParserInterface $info_parser,LoggerInterface $logger, AssetCollectionOptimizerInterface $css_collection_optimizer = NULL, ConfigInstallerInterface $config_installer = NULL, ConfigManagerInterface $config_manager = NULL, RouteBuilderIndicatorInterface $route_builder_indicator = NULL, ExtensionDiscovery $extension_discovery = NULL) {
$this->configFactory = $config_factory;
$this->moduleHandler = $module_handler;
$this->state = $state;
......@@ -150,7 +150,7 @@ public function __construct(ConfigFactoryInterface $config_factory, ModuleHandle
$this->cssCollectionOptimizer = $css_collection_optimizer;
$this->configInstaller = $config_installer;
$this->configManager = $config_manager;
$this->routeBuilder = $route_builder;
$this->routeBuilderIndicator = $route_builder_indicator;
$this->extensionDiscovery = $extension_discovery;
}
......@@ -648,8 +648,8 @@ protected function getExtensionDiscovery() {
* Resets some other systems like rebuilding the route information or caches.
*/
protected function resetSystem() {
if ($this->routeBuilder) {
$this->routeBuilder->setRebuildNeeded();
if ($this->routeBuilderIndicator) {
$this->routeBuilderIndicator->setRebuildNeeded();
}
$this->systemListReset();
......
......@@ -58,6 +58,13 @@ class RouteBuilder implements RouteBuilderInterface {
*/
protected $moduleHandler;
/**
* The route builder indicator.
*
* @var \Drupal\Core\Routing\RouteBuilderIndicatorInterface
*/
protected $routeBuilderIndicator;
/**
* The controller resolver.
*
......@@ -92,16 +99,16 @@ class RouteBuilder implements RouteBuilderInterface {
* The module handler.
* @param \Drupal\Core\Controller\ControllerResolverInterface $controller_resolver
* The controller resolver.
* @param \Drupal\Core\KeyValueStore\StateInterface $state
* The state.
* @param \Drupal\Core\Routing\RouteBuilderIndicatorInterface $route_build_indicator
* The route build indicator.
*/
public function __construct(MatcherDumperInterface $dumper, LockBackendInterface $lock, EventDispatcherInterface $dispatcher, ModuleHandlerInterface $module_handler, ControllerResolverInterface $controller_resolver, StateInterface $state = NULL) {
public function __construct(MatcherDumperInterface $dumper, LockBackendInterface $lock, EventDispatcherInterface $dispatcher, ModuleHandlerInterface $module_handler, ControllerResolverInterface $controller_resolver, RouteBuilderIndicatorInterface $route_build_indicator = NULL) {
$this->dumper = $dumper;
$this->lock = $lock;
$this->dispatcher = $dispatcher;
$this->moduleHandler = $module_handler;
$this->controllerResolver = $controller_resolver;
$this->state = $state;
$this->routeBuilderIndicator = $route_build_indicator;
}
/**
......@@ -175,7 +182,7 @@ public function rebuild() {
$this->dumper->addRoutes($collection);
$this->dumper->dump();
$this->state->delete(static::REBUILD_NEEDED);
$this->routeBuilderIndicator->setRebuildDone();
$this->lock->release('router_rebuild');
$this->dispatcher->dispatch(RoutingEvents::FINISHED, new Event());
$this->building = FALSE;
......@@ -196,7 +203,7 @@ public function getCollectionDuringRebuild() {
* {@inheritdoc}
*/
public function rebuildIfNeeded() {
if ($this->state->get(static::REBUILD_NEEDED, FALSE)) {
if ($this->routeBuilderIndicator->isRebuildNeeded()) {
return $this->rebuild();
}
return FALSE;
......@@ -206,7 +213,7 @@ public function rebuildIfNeeded() {
* {@inheritdoc}
*/
public function setRebuildNeeded() {
$this->state->set(static::REBUILD_NEEDED, TRUE);
$this->routeBuilderIndicator->setRebuildNeeded();
}
/**
......
<?php
/**
* @file
* Contains \Drupal\Core\Routing\RouteBuilderIndicator.
*/
namespace Drupal\Core\Routing;
use Drupal\Core\State\StateInterface;
use Symfony\Component\DependencyInjection\ContainerAware;
/**
* A simple service to be used instead of the route builder.
*
* The route builder service is required by quite a few other services,
* however it has a lot of dependencies. Use this service to ensure that the
* router is rebuilt.
*/
class RouteBuilderIndicator implements RouteBuilderIndicatorInterface {
/**
* @var \Drupal\Core\State\StateInterface
*/
protected $state;
/**
* @param \Drupal\Core\State\StateInterface $state
*/
public function __construct(StateInterface $state) {
$this->state = $state;
}
/**
* {@inheritdoc}
*/
public function setRebuildNeeded() {
$this->state->set(static::REBUILD_NEEDED, TRUE);
}
/**
* {@inheritdoc}
*/
public function isRebuildNeeded() {
return $this->state->get(static::REBUILD_NEEDED, FALSE);
}
/**
* {@inheritdoc}
*/
public function setRebuildDone() {
$this->state->set(static::REBUILD_NEEDED, FALSE);
}
}
<?php
/**
* @file
* Definition of Drupal\Core\Routing\RouteBuilderIndicatorInterface.
*/
namespace Drupal\Core\Routing;
interface RouteBuilderIndicatorInterface {
/**
* The state key to use.
*/
const REBUILD_NEEDED = 'router_rebuild_needed';
/**
* Sets the router to be rebuilt next time the kernel is terminated.
*
* @see \Drupal\Core\EventSubscriber\RouterRebuildSubscriber::onKernelTerminate()
* @see \Drupal\Core\Routing\RouteBuilderInterface::rebuildIfNeeded()
*
*/
public function setRebuildNeeded();
/**
* Sets the router rebuild indicator to FALSE.
*/
public function setRebuildDone();
/**
* Checks if the router needs to be rebuilt.
*
* @return bool
* TRUE if the router needs to be rebuilt, FALSE if not.
*/
public function isRebuildNeeded();
}
......@@ -9,8 +9,6 @@
interface RouteBuilderInterface {
const REBUILD_NEEDED = 'router_rebuild_needed';
/**
* Rebuilds the route info and dumps to dumper.
*
......
......@@ -337,5 +337,5 @@ function content_translation_form_language_content_settings_submit(array $form,
// Ensure entity and menu router information are correctly rebuilt.
\Drupal::entityManager()->clearCachedDefinitions();
\Drupal::service('router.builder')->setRebuildNeeded();
\Drupal::service('router.builder_indicator')->setRebuildNeeded();
}
......@@ -701,7 +701,7 @@ function content_translation_language_configuration_element_submit(array $form,
if (content_translation_enabled($context['entity_type'], $context['bundle']) != $enabled) {
content_translation_set_config($context['entity_type'], $context['bundle'], 'enabled', $enabled);
\Drupal::entityManager()->clearCachedDefinitions();
\Drupal::service('router.builder')->setRebuildNeeded();
\Drupal::service('router.builder_indicator')->setRebuildNeeded();
}
}
......
......@@ -98,7 +98,7 @@ function field_ui_entity_type_build(array &$entity_types) {
function field_ui_entity_bundle_create($entity_type, $bundle) {
// When a new bundle is created, the menu needs to be rebuilt to add our
// menu item tabs.
\Drupal::service('router.builder')->setRebuildNeeded();
\Drupal::service('router.builder_indicator')->setRebuildNeeded();
}
/**
......@@ -107,7 +107,7 @@ function field_ui_entity_bundle_create($entity_type, $bundle) {
function field_ui_entity_bundle_rename($entity_type, $bundle_old, $bundle_new) {
// When a bundle is renamed, the menu needs to be rebuilt to add our
// menu item tabs.
\Drupal::service('router.builder')->setRebuildNeeded();
\Drupal::service('router.builder_indicator')->setRebuildNeeded();
}
/**
......@@ -182,14 +182,14 @@ function field_ui_form_node_type_form_submit($form, FormStateInterface $form_sta
* Implements hook_view_mode_presave().
*/
function field_ui_view_mode_presave(EntityViewModeInterface $view_mode) {
\Drupal::service('router.builder')->setRebuildNeeded();
\Drupal::service('router.builder_indicator')->setRebuildNeeded();
}
/**
* Implements hook_view_mode_delete().
*/
function field_ui_view_mode_delete(EntityViewModeInterface $view_mode) {
\Drupal::service('router.builder')->setRebuildNeeded();
\Drupal::service('router.builder_indicator')->setRebuildNeeded();
}
/**
......
......@@ -21,5 +21,5 @@ function menu_ui_install() {
* Implements hook_uninstall().
*/
function menu_ui_uninstall() {
\Drupal::service('router.builder')->setRebuildNeeded();
\Drupal::service('router.builder_indicator')->setRebuildNeeded();
}
......@@ -961,7 +961,7 @@ function node_form_system_themes_admin_form_submit($form, FormStateInterface $fo
\Drupal::config('node.settings')
->set('use_admin_theme', $form_state->getValue('use_admin_theme'))
->save();
\Drupal::service('router.builder')->setRebuildNeeded();
\Drupal::service('router.builder_indicator')->setRebuildNeeded();
}
/**
......
......@@ -184,7 +184,7 @@ public function postCreate(EntityStorageInterface $storage) {
*/
public function postSave(EntityStorageInterface $storage, $update = TRUE) {
parent::postSave($storage, $update);
$this->routeBuilder()->setRebuildNeeded();
$this->routeBuilderIndicator()->setRebuildNeeded();
}
/**
......@@ -216,11 +216,11 @@ public static function sort(ConfigEntityInterface $a, ConfigEntityInterface $b)
/**
* Wraps the route builder.
*
* @return \Drupal\Core\Routing\RouteBuilderInterface
* @return \Drupal\Core\Routing\RouteBuilderIndicatorInterface
* An object for state storage.
*/
protected function routeBuilder() {
return \Drupal::service('router.builder');
protected function routeBuilderIndicator() {
return \Drupal::service('router.builder_indicator');
}
/**
......
......@@ -723,7 +723,7 @@ function hook_entity_bundle_info_alter(&$bundles) {
function hook_entity_bundle_create($entity_type_id, $bundle) {
// When a new bundle is created, the menu needs to be rebuilt to add the
// Field UI menu item tabs.
\Drupal::service('router.builder')->setRebuildNeeded();
\Drupal::service('router.builder_indicator')->setRebuildNeeded();
}
/**
......
......@@ -9,7 +9,7 @@
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Extension\ThemeHandlerInterface;
use Drupal\Core\Routing\RouteBuilderInterface;
use Drupal\Core\Routing\RouteBuilderIndicatorInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
......@@ -29,21 +29,21 @@ class ThemeController extends ControllerBase {
/**
* The route builder service.
*
* @var \Drupal\Core\Routing\RouteBuilderInterface
* @var \Drupal\Core\Routing\RouteBuilderIndicatorInterface
*/
protected $routeBuilder;
protected $routeBuilderIndicator;
/**
* Constructs a new ThemeController.
*
* @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler
* The theme handler.
* @param \Drupal\Core\Routing\RouteBuilderInterface $route_builder
* @param \Drupal\Core\Routing\RouteBuilderInterface $route_builder_indicator
* The route builder.
*/
public function __construct(ThemeHandlerInterface $theme_handler, RouteBuilderInterface $route_builder) {
public function __construct(ThemeHandlerInterface $theme_handler, RouteBuilderIndicatorInterface $route_builder_indicator) {
$this->themeHandler = $theme_handler;
$this->routeBuilder = $route_builder;
$this->routeBuilderIndicator = $route_builder_indicator;
}
/**
......@@ -52,7 +52,7 @@ public function __construct(ThemeHandlerInterface $theme_handler, RouteBuilderIn
public static function create(ContainerInterface $container) {
return new static(
$container->get('theme_handler'),
$container->get('router.builder')
$container->get('router.builder_indicator')
);
}
......@@ -157,7 +157,7 @@ public function setDefaultTheme(Request $request) {
// Set the default theme.
$config->set('default', $theme)->save();
$this->routeBuilder->setRebuildNeeded();
$this->routeBuilderIndicator->setRebuildNeeded();
// The status message depends on whether an admin theme is currently in
// use: a value of 0 means the admin theme is set to be the default
......
......@@ -1393,11 +1393,9 @@ function user_modules_installed($modules) {
// Assign all available permissions to the administrator role.
$rid = \Drupal::config('user.settings')->get('admin_role');
if ($rid) {
/** @var \Drupal\Core\Routing\RouteBuilderInterface $route_builder */
$route_builder = \Drupal::service('router.builder');
// Some permissions call the url generator, so ensure that the routes are
// up to date.
$route_builder->setRebuildNeeded();
\Drupal::service('router.builder_indicator')->setRebuildNeeded();
/** @var \Drupal\user\PermissionHandlerInterface $permission_handler */
$permission_handler = \Drupal::service('user.permissions');
$permissions = $permission_handler->getPermissions();
......
......@@ -348,9 +348,7 @@ public function postSave(EntityStorageInterface $storage, $update = TRUE) {
// Rebuild the router case the view got enabled.
if (!isset($this->original) || ($this->status() != $this->original->status())) {
/** @var \Drupal\Core\Routing\RouteBuilderInterface $router_builder */
$router_builder = \Drupal::service('router.builder');
$router_builder->setRebuildNeeded();
\Drupal::service('router.builder_indicator')->setRebuildNeeded();
}
}
......
......@@ -486,7 +486,7 @@ function views_invalidate_cache() {
Cache::deleteTags(array('extension' => 'views'));
// Set the menu as needed to be rebuilt.
\Drupal::service('router.builder')->setRebuildNeeded();
\Drupal::service('router.builder_indicator')->setRebuildNeeded();
$module_handler = \Drupal::moduleHandler();
......
......@@ -22,11 +22,11 @@
class ThemeHandlerTest extends UnitTestCase {
/**
* The mocked route builder.
* The mocked route builder indicator.
*
* @var \Drupal\Core\Routing\RouteBuilder|\PHPUnit_Framework_MockObject_MockObject
* @var \Drupal\Core\Routing\RouteBuilderIndicatorInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $routeBuilder;
protected $routeBuilderIndicator;
/**
* The mocked info parser.
......@@ -109,9 +109,7 @@ protected function setUp() {
$this->infoParser = $this->getMock('Drupal\Core\Extension\InfoParserInterface');
$this->configInstaller = $this->getMock('Drupal\Core\Config\ConfigInstallerInterface');
$this->configManager = $this->getMock('Drupal\Core\Config\ConfigManagerInterface');
$this->routeBuilder = $this->getMockBuilder('Drupal\Core\Routing\RouteBuilder')
->disableOriginalConstructor()
->getMock();
$this->routeBuilderIndicator = $this->getMock('Drupal\Core\Routing\RouteBuilderIndicatorInterface');
$this->extensionDiscovery = $this->getMockBuilder('Drupal\Core\Extension\ExtensionDiscovery')
->disableOriginalConstructor()
->getMock();
......@@ -119,7 +117,7 @@ protected function setUp() {
->disableOriginalConstructor()
->getMock();
$logger = $this->getMock('Psr\Log\LoggerInterface');
$this->themeHandler = new TestThemeHandler($this->configFactory, $this->moduleHandler, $this->state, $this->infoParser, $logger, $this->cssCollectionOptimizer, $this->configInstaller, $this->configManager, $this->routeBuilder, $this->extensionDiscovery);
$this->themeHandler = new TestThemeHandler($this->configFactory, $this->moduleHandler, $this->state, $this->infoParser, $logger, $this->cssCollectionOptimizer, $this->configInstaller, $this->configManager, $this->routeBuilderIndicator, $this->extensionDiscovery);
$cache_backend = $this->getMock('Drupal\Core\Cache\CacheBackendInterface');
$this->getContainerWithCacheBins($cache_backend);
......
......@@ -74,9 +74,9 @@ class RouteBuilderTest extends UnitTestCase {
/**
* The key value store.
*
* @var \Drupal\Core\State\StateInterface|\PHPUnit_Framework_MockObject_MockObject
* @var \Drupal\Core\Routing\RouteBuilderIndicatorInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $state;
protected $routeBuilderIndicator;
protected function setUp() {
$this->dumper = $this->getMock('Drupal\Core\Routing\MatcherDumperInterface');
......@@ -87,9 +87,9 @@ protected function setUp() {
$this->yamlDiscovery = $this->getMockBuilder('\Drupal\Component\Discovery\YamlDiscovery')
->disableOriginalConstructor()
->getMock();
$this->state = $this->getMock('\Drupal\Core\State\StateInterface');
$this->routeBuilderIndicator = $this->getMock('\Drupal\Core\Routing\RouteBuilderIndicatorInterface');
$this->routeBuilder = new TestRouteBuilder($this->dumper, $this->lock, $this->dispatcher, $this->moduleHandler, $this->controllerResolver, $this->state);
$this->routeBuilder = new TestRouteBuilder($this->dumper, $this->lock, $this->dispatcher, $this->moduleHandler, $this->controllerResolver, $this->routeBuilderIndicator);
$this->routeBuilder->setYamlDiscovery($this->yamlDiscovery);
}
......@@ -106,9 +106,8 @@ public function testRebuildLockingUnlocking() {
->method('release')
->with('router_rebuild');
$this->state->expects($this->once())
->method('delete')
->with('router_rebuild_needed');
$this->routeBuilderIndicator->expects($this->once())
->method('setRebuildDone');
$this->yamlDiscovery->expects($this->any())
->method('findAll')
......@@ -257,17 +256,14 @@ public function testRebuildIfNecessary() {
->method('release')
->with('router_rebuild');
$this->state->expects($this->once())
->method('set')
->with('router_rebuild_needed');
$this->routeBuilderIndicator->expects($this->once())
->method('setRebuildNeeded');
$this->state->expects($this->once())
->method('delete')
->with('router_rebuild_needed');
$this->routeBuilderIndicator->expects($this->once())
->method('setRebuildDone');
$this->state->expects($this->exactly(2))
->method('get')
->with('router_rebuild_needed')
$this->routeBuilderIndicator->expects($this->exactly(2))
->method('isRebuildNeeded')
->will($this->onConsecutiveCalls(TRUE, FALSE));
$this->yamlDiscovery->expects($this->any())
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment