diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php index 92054d7..f167755 100644 --- a/core/lib/Drupal/Core/DrupalKernel.php +++ b/core/lib/Drupal/Core/DrupalKernel.php @@ -34,8 +34,19 @@ class DrupalKernel extends Kernel implements DrupalKernelInterface { * Holds the list of enabled modules. * * @var array + * An associative array whose keys are module names and whose values are + * ignored. */ - protected $moduleList = array(); + protected $moduleList; + + /** + * Holds an updated list of enabled modules. + * + * @var array + * An associative array whose keys are module names and whose values are + * ignored. + */ + protected $newModuleList; /** * An array of module data objects. @@ -123,11 +134,10 @@ public function registerBundles() { $bundles = array( new CoreBundle(), ); - if (!$this->moduleList) { + if (!isset($this->moduleList)) { $storage = new FileStorage(config_get_config_directory()); $module_list = $storage->read('system.module'); - $module_list = $module_list['enabled']; - $this->moduleList = $module_list; + $this->moduleList = isset($module_list['enabled']) ? $module_list['enabled'] : array(); } $namespaces = $this->classLoader->getNamespaces(); @@ -186,7 +196,7 @@ protected function moduleData($module) { * Implements Drupal\Core\DrupalKernelInterface::updateModules(). */ public function updateModules(array $module_list, array $module_paths = array(), ContainerBuilder $base_container = NULL) { - $this->moduleList = $module_list; + $this->newModuleList = $module_list; foreach ($module_paths as $module => $path) { $this->moduleData[$module] = (object) array('uri' => $path); } @@ -223,25 +233,27 @@ protected function getClassName() { */ protected function initializeContainer() { $this->container = NULL; - $class = $this->getClassName(); - $cache_file = $class . '.php'; - // First, try to load. - if ($this->storage && !class_exists($class, FALSE)) { - $this->storage->load($cache_file); - } - // If the load succeeded or the class already existed, use it. - if (class_exists($class, FALSE)) { - $fully_qualified_class_name = '\\' . $class; - $this->container = new $fully_qualified_class_name; - } + if ($this->storage) { + $class = $this->getClassName(); + $cache_file = $class . '.php'; - if (isset($this->container)) { - $module_list = array_keys($this->moduleList ?: $this->container->get('config.factory')->get('system.module')->load()->get('enabled')); - if ($module_list !== $this->container->getParameter('container.modules')) { - unset($this->container); + // First, try to load. + if (!class_exists($class, FALSE)) { + $this->storage->load($cache_file); + } + // If the load succeeded or the class already existed, use it. + if (class_exists($class, FALSE)) { + $fully_qualified_class_name = '\\' . $class; + $this->container = new $fully_qualified_class_name; } } + + if (isset($this->moduleList) && isset($this->newModuleList) && array_keys($this->moduleList) !== array_keys($this->newModuleList)) { + unset($this->container); + $this->moduleList = $this->newModuleList; + unset($this->newModuleList); + } if (!isset($this->container)) { $this->container = $this->buildContainer(); if ($this->storage && !$this->dumpDrupalContainer($this->container, $this->getContainerBaseClass())) { diff --git a/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php index bfbca8f..84022d5 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php @@ -98,7 +98,7 @@ protected function setUp() { $this->baseContainer = clone $this->container; // Bootstrap the kernel. - $this->kernel = new DrupalKernel('testing', TRUE, array_keys($this->moduleList)); + $this->kernel = new DrupalKernel('testing', TRUE, drupal_classloader()); $this->kernel->boot(); $this->container = drupal_container(); @@ -204,8 +204,11 @@ protected function installSchema($module, $table) { */ protected function enableModules(array $modules, $install = TRUE) { // Set the modules in the fixed module_list(). + $module_config = config('system.module'); + $new_enabled = array(); foreach ($modules as $module) { $this->moduleList[$module]['filename'] = drupal_get_filename('module', $module); + $new_enabled[$module] = dirname($this->moduleList[$module]['filename']); module_list(NULL, $this->moduleList); // Call module_enable() to enable (install) the new module. @@ -228,7 +231,7 @@ protected function enableModules(array $modules, $install = TRUE) { module_implements_reset(); } $kernel = $this->container->get('kernel'); - $kernel->updateModules(array_keys($this->moduleList), clone $this->baseContainer); + $kernel->updateModules($this->moduleList, $new_enabled, clone $this->baseContainer); } }