diff -u b/core/includes/bootstrap.inc b/core/includes/bootstrap.inc --- b/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -2401,9 +2401,9 @@ * @see Drupal\Core\DrupalKernel * * @param $new_container - * A new container instance to reset the Drupal container to. - * @param $load - * Whether to create a new container. + * A new container instance to store. + * @param $reset + * Set to TRUE to create a new bare essentials container. * * @return Symfony\Component\DependencyInjection\Container * The instance of the Container used to set up and maintain object diff -u b/core/includes/file.inc b/core/includes/file.inc --- b/core/includes/file.inc +++ b/core/includes/file.inc @@ -2025,6 +2025,8 @@ $options['key'] = in_array($options['key'], array('uri', 'filename', 'name')) ? $options['key'] : 'uri'; $files = array(); + // Avoid warnings when opendir does not have the permissions to open a + // directory. if (is_dir($dir) && $handle = @opendir($dir)) { while (FALSE !== ($filename = readdir($handle))) { if (!preg_match($options['nomask'], $filename) && $filename[0] != '.') { diff -u b/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php --- b/core/lib/Drupal/Core/DrupalKernel.php +++ b/core/lib/Drupal/Core/DrupalKernel.php @@ -28,6 +28,18 @@ class DrupalKernel extends Kernel { /** + * @var string The name of the container class. + */ + protected $containerClassName; + + public function __construct($environment, $debug, $containerClassName = NULL) { + parent::__construct($environment, $debug); + if ($containerClassName) { + $this->containerClassName = $containerClassName; + } + } + + /** * Overrides Kernel::init(). */ public function init() { @@ -63,39 +75,30 @@ * Initializes the service container. */ protected function initializeContainer() { - $class = $this->getContainerClass(); + $class = $this->containerClassName ? $this->containerClassName : $this->getContainerClass(); $cache_file = $class . '.php'; $storage = drupal_php_storage('service_container'); - if (!$storage->exists($cache_file)) { - $container = $this->buildContainer(); - $this->dumpDrupalContainer($cache_file, $container, $class, $this->getContainerBaseClass(), $storage); + // First, try to load. + if (!class_exists($class)) { + $storage->load($cache_file); + } + // If the load succeeded or the class already existed, use it. + if (class_exists($class)) { + $this->container = new $class; + } + else { + $this->container = $this->buildContainer(); + if ($storage->writeable()) { + $this->dumpDrupalContainer($cache_file, $this->container, $class, $this->getContainerBaseClass(), $storage); + } } - - $storage->load($cache_file); - - $this->container = new $class(); $this->container->set('kernel', $this); drupal_container($this->container); } /** - * Gets the container class. - * - * @return string - */ - protected function getContainerClass() { - $class = parent::getContainerClass(); - $class_original = $class; - $prefix = 0; - while (class_exists($class)) { - $class = $class_original . $prefix++; - } - return $class; - } - - /** * Builds the service container. * * @return ContainerBuilder The compiled service container diff -u b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php --- b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php @@ -663,6 +663,7 @@ ))->fetchField(); if ($install_profile_module_exists) { module_enable(array($this->profile), FALSE); + $modules[] = $this->profile; } // Create a new DrupalKernel for testing purposes, now that all required @@ -671,7 +672,7 @@ // restores the original container. // @see Drupal\Core\DrupalKernel::initializeContainer() drupal_container(NULL, TRUE); - $this->kernel = new DrupalKernel('testing', FALSE); + $this->kernel = new DrupalKernel('testing', FALSE, hash('sha256', implode(',', $modules))); // Booting the kernel is necessary to initialize the new DIC. While // normally the kernel gets booted on demand in // Symfony\Component\HttpKernel\handle(), this kernel needs manual booting only in patch2: unchanged: --- a/core/lib/Drupal/Component/PhpStorage/FileReadOnlyStorage.php +++ b/core/lib/Drupal/Component/PhpStorage/FileReadOnlyStorage.php @@ -69,4 +69,11 @@ class FileReadOnlyStorage implements PhpStorageInterface { protected function getFullPath($name) { return $this->directory . '/' . $name; } + + /** + * Implements Drupal\Component\PhpStorage\PhpStorageInterface::writeable(). + */ + function writeable() { + return FALSE; + } } only in patch2: unchanged: --- a/core/lib/Drupal/Component/PhpStorage/FileStorage.php +++ b/core/lib/Drupal/Component/PhpStorage/FileStorage.php @@ -71,4 +71,11 @@ class FileStorage implements PhpStorageInterface { protected function getFullPath($name) { return $this->directory . '/' . $name; } + + /** + * Implements Drupal\Component\PhpStorage\PhpStorageInterface::writeable(). + */ + function writeable() { + return TRUE; + } } only in patch2: unchanged: --- a/core/lib/Drupal/Component/PhpStorage/PhpStorageInterface.php +++ b/core/lib/Drupal/Component/PhpStorage/PhpStorageInterface.php @@ -57,6 +57,13 @@ interface PhpStorageInterface { public function save($name, $code); /** + * Whether this is a writeable storage. + * + * @return bool + */ + public function writeable(); + + /** * Deletes PHP code from storage. * * @param string $name