diff --git a/core/includes/utility.inc b/core/includes/utility.inc index 4ac4bb8..4918719 100644 --- a/core/includes/utility.inc +++ b/core/includes/utility.inc @@ -36,8 +36,8 @@ function drupal_rebuild(ClassLoader $class_loader, Request $request) { $kernel = new DrupalKernel('prod', $class_loader); $kernel->setSitePath(DrupalKernel::findSitePath($request)); - // Rebuild the container on boot(). - $kernel->boot(TRUE); + // Invalidate the container. + $kernel->invalidateContainer(); // Prepare a NULL request. $kernel->prepareLegacyRequest($request); diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php index f4ca50f..cbb9118 100644 --- a/core/lib/Drupal/Core/DrupalKernel.php +++ b/core/lib/Drupal/Core/DrupalKernel.php @@ -127,6 +127,13 @@ class DrupalKernel implements DrupalKernelInterface, TerminableInterface { protected $allowDumping; /** + * Whether the container needs to be rebuild the next time it is initialized. + * + * @var bool + */ + protected $containerNeedsRebuild = FALSE; + + /** * Whether the container needs to be dumped once booting is complete. * * @var bool @@ -357,7 +364,7 @@ public function getAppRoot() { /** * {@inheritdoc} */ - public function boot($rebuild = FALSE) { + public function boot() { if ($this->booted) { return $this; } @@ -389,7 +396,7 @@ public function boot($rebuild = FALSE) { FileCacheFactory::setPrefix(Settings::getApcuPrefix('file_cache', $this->root)); // Initialize the container. - $this->initializeContainer($rebuild); + $this->initializeContainer(); // Ensure mt_rand() is reseeded to prevent random values from one page load // being exploited to predict random values in subsequent page loads. @@ -695,11 +702,13 @@ public function updateModules(array $module_list, array $module_filenames = arra } // If we haven't yet booted, we don't need to do anything: the new module - // list will take effect when boot() is called. If we have already booted, - // then rebuild the container in order to refresh the serviceProvider list - // and container. + // list will take effect when boot() is called. However we set the + // containerNeedsRebuild flag so that a potentially cached container is not + // used. If we have already booted, then rebuild the container in order to + // refresh the serviceProvider list and container. + $this->containerNeedsRebuild = TRUE; if ($this->booted) { - $this->initializeContainer(TRUE); + $this->initializeContainer(); } } @@ -738,11 +747,9 @@ protected function getKernelParameters() { /** * Initializes the service container. * - * @param bool $rebuild - * Force a container rebuild. * @return \Symfony\Component\DependencyInjection\ContainerInterface */ - protected function initializeContainer($rebuild = FALSE) { + protected function initializeContainer() { $this->containerNeedsDumping = FALSE; $session_started = FALSE; if (isset($this->container)) { @@ -764,7 +771,7 @@ protected function initializeContainer($rebuild = FALSE) { // If the module list hasn't already been set in updateModules and we are // not forcing a rebuild, then try and load the container from the disk. - if (empty($this->moduleList) && !$rebuild) { + if (empty($this->moduleList) && !$this->containerNeedsRebuild) { $fully_qualified_class_name = '\\' . $this->getClassNamespace() . '\\' . $this->getClassName(); // First, try to load from storage. @@ -781,6 +788,11 @@ protected function initializeContainer($rebuild = FALSE) { $container = $this->compileContainer(); } + // The container was rebuild successfully. + if ($this->containerNeedsRebuild) { + $this->containerNeedsRebuild = FALSE; + } + $this->attachSynthetic($container); $this->container = $container; @@ -1004,15 +1016,27 @@ public function rebuildContainer() { // Empty module properties and for them to be reloaded from scratch. $this->moduleList = NULL; $this->moduleData = array(); - return $this->initializeContainer(TRUE); + $this->containerNeedsRebuild = TRUE; + return $this->initializeContainer(); } /** * {@inheritdoc} */ public function invalidateContainer() { - // Wipe the PHP Storage caches. - PhpStorageFactory::get('service_container')->deleteAll(); + // An invalidated container needs a rebuild. + $this->containerNeedsRebuild = TRUE; + + // If we have not yet booted, settings or bootstrap services might not yet + // be available. In that case the container will not be loaded from cache + // due to the above setting when the Kernel is booted. + if (!$this->booted) { + return; + } + + // Also wipe the PHP Storage caches, so that the container is rebuild + // for the next request. + $this->storage()->deleteAll(); } /** diff --git a/core/lib/Drupal/Core/DrupalKernelInterface.php b/core/lib/Drupal/Core/DrupalKernelInterface.php index 739b48c..892952a 100644 --- a/core/lib/Drupal/Core/DrupalKernelInterface.php +++ b/core/lib/Drupal/Core/DrupalKernelInterface.php @@ -21,12 +21,9 @@ /** * Boots the current kernel. * - * @param bool $rebuild - * (optional) Whether to rebuild the container or not. - * * @return $this */ - public function boot($rebuild = FALSE); + public function boot(); /** * Shuts down the kernel. diff --git a/core/lib/Drupal/Core/Installer/InstallerKernel.php b/core/lib/Drupal/Core/Installer/InstallerKernel.php index 41e8cbe..cd3977c 100644 --- a/core/lib/Drupal/Core/Installer/InstallerKernel.php +++ b/core/lib/Drupal/Core/Installer/InstallerKernel.php @@ -16,13 +16,11 @@ class InstallerKernel extends DrupalKernel { /** * {@inheritdoc} - * - * @param bool $rebuild - * Force a container rebuild. Unlike the parent method, this defaults to - * TRUE. */ - protected function initializeContainer($rebuild = TRUE) { - $container = parent::initializeContainer($rebuild); + protected function initializeContainer() { + // Always force a container rebuild. + $this->containerNeedsRebuild = TRUE; + $container = parent::initializeContainer(); return $container; } diff --git a/core/lib/Drupal/Core/Test/TestRunnerKernel.php b/core/lib/Drupal/Core/Test/TestRunnerKernel.php index 8c35baa..f19afb3 100644 --- a/core/lib/Drupal/Core/Test/TestRunnerKernel.php +++ b/core/lib/Drupal/Core/Test/TestRunnerKernel.php @@ -50,7 +50,7 @@ public function __construct($environment, $class_loader) { /** * {@inheritdoc} */ - public function boot($rebuild = FALSE) { + public function boot() { // Ensure that required Settings exist. if (!Settings::getAll()) { new Settings(array( @@ -70,7 +70,7 @@ public function boot($rebuild = FALSE) { // In addition, ensure that PHP errors are not hidden away in logs. ini_set('display_errors', TRUE); - parent::boot($rebuild); + parent::boot(); $this->getContainer()->get('module_handler')->loadAll();