diff --git a/lib/Drush/Boot/DrupalBoot8.php b/lib/Drush/Boot/DrupalBoot8.php index f427571b37..468e963aae 100644 --- a/lib/Drush/Boot/DrupalBoot8.php +++ b/lib/Drush/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; @@ -128,7 +126,7 @@ function bootstrap_drupal_configuration() { $this->kernel = DrushDrupalKernel::createFromRequest($this->request, $classloader, 'prod'); } // @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(); @@ -145,7 +143,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/lib/Drush/Drupal/DrupalKernel.php b/lib/Drush/Drupal/DrupalKernel.php index 73456ed46a..39fa15c0f9 100644 --- a/lib/Drush/Drupal/DrupalKernel.php +++ b/lib/Drush/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/lib/Drush/Drupal/DrushServiceModfier.php b/lib/Drush/Drupal/DrushServiceModifier.php similarity index 65% rename from lib/Drush/Drupal/DrushServiceModfier.php rename to lib/Drush/Drupal/DrushServiceModifier.php index 7d6dec4aac..14a8a292ee 100644 --- a/lib/Drush/Drupal/DrushServiceModfier.php +++ b/lib/Drush/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,15 @@ 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']); + } }