diff --git a/src/Boot/DrupalBoot8.php b/src/Boot/DrupalBoot8.php index 7feb23a1d0..91bcd1571a 100644 --- a/src/Boot/DrupalBoot8.php +++ b/src/Boot/DrupalBoot8.php @@ -4,11 +4,9 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Psr\Log\LoggerInterface; use Drupal\Core\DrupalKernel; use Drush\Drupal\DrupalKernel as DrushDrupalKernel; -use Drush\Drupal\DrushServiceModfier; -use Symfony\Component\DependencyInjection\Reference; +use Drush\Drupal\DrushServiceModifier; use Drush\Log\LogLevel; @@ -129,7 +127,7 @@ function bootstrap_drupal_configuration() { $this->kernel = DrushDrupalKernel::createFromRequest($this->request, $classloader, 'prod', DRUPAL_ROOT); } // @see Drush\Drupal\DrupalKernel::addServiceModifier() - $this->kernel->addServiceModifier(new DrushServiceModfier()); + $this->kernel->addServiceModifier(new DrushServiceModifier()); // Unset drupal error handler and restore Drush's one. restore_error_handler(); @@ -146,7 +144,6 @@ function bootstrap_drupal_full() { if (!drush_get_context('DRUSH_QUIET', FALSE)) { ob_start(); } - $this->kernel->invalidateContainer(); $this->kernel->boot(); $this->kernel->prepareLegacyRequest($this->request); if (!drush_get_context('DRUSH_QUIET', FALSE)) { diff --git a/src/Drupal/DrupalKernel.php b/src/Drupal/DrupalKernel.php index cf09c74a89..a05ce40299 100644 --- a/src/Drupal/DrupalKernel.php +++ b/src/Drupal/DrupalKernel.php @@ -43,4 +43,21 @@ protected function getContainerBuilder() { } return $container; } + /** + * Initializes the service container. + * + * @return \Symfony\Component\DependencyInjection\ContainerInterface + */ + protected function initializeContainer() { + if (empty($this->moduleList) && !$this->containerNeedsRebuild) { + $container_definition = $this->getCachedContainerDefinition(); + foreach ($this->serviceModifiers as $serviceModifier) { + if (!$serviceModifier->check($container_definition)) { + $this->invalidateContainer(); + break; + } + } + } + return parent::initializeContainer(); + } } diff --git a/src/Drupal/DrushServiceModfier.php b/src/Drupal/DrushServiceModifier.php similarity index 65% rename from src/Drupal/DrushServiceModfier.php rename to src/Drupal/DrushServiceModifier.php index 7d6dec4aac..4bb799aab5 100644 --- a/src/Drupal/DrushServiceModfier.php +++ b/src/Drupal/DrushServiceModifier.php @@ -6,7 +6,7 @@ use Drupal\Core\DependencyInjection\ServiceModifierInterface; use Drupal\Core\DependencyInjection\ContainerBuilder; -class DrushServiceModfier implements ServiceModifierInterface +class DrushServiceModifier implements ServiceModifierInterface { /** * @inheritdoc @@ -19,4 +19,16 @@ public function alter(ContainerBuilder $container) { $container->register('drush.service.consolidationcommands', 'Drush\Command\ServiceCommandlist'); $container->addCompilerPass(new FindCommandsCompilerPass('drush.service.consolidationcommands', 'consolidation.commandhandler')); } + + /** + * Checks existing service definitions for the presence of modification. + * + * @param $container_definition + * Cached container definition + * @return bool + */ + public function check($container_definition) { + return isset($container_definition['services']['drush.service.consolecommands']) && + isset($container_definition['services']['drush.service.consolidationcommands']); + } }