diff --git a/core/modules/simpletest/src/RouteBuilder.php b/core/modules/simpletest/src/RouteBuilder.php index 3672af4..3b7100f 100644 --- a/core/modules/simpletest/src/RouteBuilder.php +++ b/core/modules/simpletest/src/RouteBuilder.php @@ -8,7 +8,6 @@ namespace Drupal\simpletest; use Drupal\Core\DependencyInjection\DependencySerializationTrait; -use Drupal\Core\DestructableInterface; use Drupal\Core\Routing\RouteBuilderInterface; /** @@ -16,67 +15,48 @@ * * @see \Drupal\Component\ProxyBuilder */ -class RouteBuilder implements RouteBuilderInterface, DestructableInterface { +class RouteBuilder implements RouteBuilderInterface { use DependencySerializationTrait; /** + * Flag that indicates if we should rebuild at the end of the request. + * * @var bool */ - protected $tableInstalled; + protected $rebuildNeeded = FALSE; /** - * Loads the router builder and installs the router table. - * - * @param bool $table_needed - * TRUE when the table needs to be installed. - * - * @return \Drupal\Core\Routing\RouteBuilderInterface|\Drupal\Core\DestructableInterface - * Returns the real route builder. + * {@inheritdoc} */ - protected function lazyLoadItself($table_needed = FALSE) { - if (!isset($this->service)) { - $container = \Drupal::getContainer(); - $this->service = $container->get('simpletest.router.builder'); + public function rebuildIfNeeded() { + if ($this->rebuildNeeded) { + return $this->rebuild(); } - if ($table_needed && !$this->tableInstalled) { - $container = \Drupal::getContainer(); - $schema = $container->get('database')->schema(); - if (!$schema->tableExists('router')) { - include_once $container->get('app.root') . '/core/modules/system/system.install'; - $schema->createTable('router', system_schema()['router']); - $this->tableInstalled = TRUE; - } - } - return $this->service; + return FALSE; } /** * {@inheritdoc} */ public function setRebuildNeeded() { - return $this->lazyLoadItself()->setRebuildNeeded(); + $this->rebuildNeeded = TRUE; } /** * {@inheritdoc} */ public function rebuild() { - return $this->lazyLoadItself(TRUE)->rebuild(); - } - - /** - * {@inheritdoc} - */ - public function rebuildIfNeeded() { - return $this->lazyLoadItself()->rebuildIfNeeded(); - } - - /** - * {@inheritdoc} - */ - public function destruct() { - return $this->lazyLoadItself()->destruct(); + if (!isset($this->service)) { + $container = \Drupal::getContainer(); + $this->service = $container->get('simpletest.router.builder'); + $schema = $container->get('database')->schema(); + if (!$schema->tableExists('router')) { + include_once $container->get('app.root') . '/core/modules/system/system.install'; + $schema->createTable('router', system_schema()['router']); + } + } + return $this->service->rebuild(); } } diff --git a/core/modules/simpletest/src/RouteProvider.php b/core/modules/simpletest/src/RouteProvider.php index 04c6383..acff99a 100644 --- a/core/modules/simpletest/src/RouteProvider.php +++ b/core/modules/simpletest/src/RouteProvider.php @@ -9,13 +9,12 @@ use Drupal\Core\Routing\PreloadableRouteProviderInterface; use Symfony\Cmf\Component\Routing\PagedRouteProviderInterface; -use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\Request; /** * Rebuilds the router when the provider is instantiated. */ -class RouteProvider implements PreloadableRouteProviderInterface, PagedRouteProviderInterface, EventSubscriberInterface { +class RouteProvider implements PreloadableRouteProviderInterface, PagedRouteProviderInterface { use \Drupal\Core\DependencyInjection\DependencySerializationTrait; @@ -101,13 +100,6 @@ public function reset() { /** * {@inheritdoc} */ - public static function getSubscribedEvents() { - RouteProvider::getSubscribedEvents(); - } - - /** - * {@inheritdoc} - */ public function getRoutesPaged($offset, $length = NULL) { return $this->lazyLoadItself()->getRoutesPaged($offset, $length); } diff --git a/core/modules/simpletest/src/TestServiceProvider.php b/core/modules/simpletest/src/TestServiceProvider.php index 9f16419..e88fe9a 100644 --- a/core/modules/simpletest/src/TestServiceProvider.php +++ b/core/modules/simpletest/src/TestServiceProvider.php @@ -37,7 +37,9 @@ public function alter(ContainerBuilder $container) { // not, so do it ourselves. foreach (['router.route_provider' => 'RouteProvider', 'router.builder' => 'RouteBuilder'] as $original_id => $class) { for ($id = $original_id; $container->hasAlias($id); $id = (string) $container->getAlias($id)); - $container->setDefinition("simpletest.$original_id", $container->getDefinition($id)); + $definition = $container->getDefinition($id); + $definition->clearTag('needs_destruction'); + $container->setDefinition("simpletest.$original_id", $definition); $container->setDefinition($id, new Definition('Drupal\simpletest\\' . $class)); } }