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 @@ -58,6 +58,11 @@ protected $dump; /** + * @var array + */ + protected $bundleClasses; + + /** * Constructs a DrupalKernel object. * * @param string $environment @@ -143,6 +148,7 @@ $class = "Drupal\\{$module}\\{$camelized}Bundle"; if (class_exists($class)) { $bundles[] = new $class(); + $this->bundleClasses[] = $class; } } return $bundles; @@ -192,6 +198,12 @@ $this->container = new $fully_qualified_class_name; } + 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); + } + } if (!isset($this->container)) { $this->container = $this->buildContainer(); if ($this->dump && !$this->dumpDrupalContainer($this->container, $this->getContainerBaseClass())) { @@ -219,6 +231,8 @@ // init bundles $this->initializeBundles(); $container = $this->getContainerBuilder(); + $container->setParameter('container.bundles', $this->bundleClasses); + $container->setParameter('container.modules', array_keys($this->moduleList)); // Merge in the minimal bootstrap container. if ($bootstrap_container = drupal_container()) { only in patch2: unchanged: --- a/core/modules/system/lib/Drupal/system/Tests/DrupalKernel/DrupalKernelTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/DrupalKernel/DrupalKernelTest.php @@ -7,7 +7,6 @@ namespace Drupal\system\Tests\DrupalKernel; -use Drupal\Core\Cache\MemoryBackend; use Drupal\Core\DrupalKernel; use Drupal\simpletest\UnitTestBase; use ReflectionClass; @@ -39,16 +38,15 @@ function testCompileDIC() { 'class' => 'Drupal\Component\PhpStorage\MTimeProtectedFileStorage', 'secret' => $GLOBALS['drupal_hash_salt'], ); - $cache = new MemoryBackend('test'); $module_enabled = array( 'system' => 'system', 'user' => 'user', ); - $kernel = new DrupalKernel('testing', FALSE, $module_enabled, $cache); + $kernel = new DrupalKernel('testing', FALSE, $module_enabled, TRUE); $kernel->boot(); // Instantiate it a second time and we should get the compiled Container // class. - $kernel = new DrupalKernel('testing', FALSE, $module_enabled, $cache); + $kernel = new DrupalKernel('testing', FALSE, $module_enabled, TRUE); $kernel->boot(); $container = $kernel->getContainer(); $refClass = new ReflectionClass($container); @@ -66,7 +64,7 @@ function testCompileDIC() { $conf['php_storage']['service_container'] = array( 'class' => 'Drupal\Component\PhpStorage\FileReadOnlyStorage', ); - $kernel = new DrupalKernel('testing', FALSE, $module_enabled, $cache); + $kernel = new DrupalKernel('testing', FALSE, $module_enabled, TRUE); $kernel->boot(); $container = $kernel->getContainer(); $refClass = new ReflectionClass($container); @@ -91,12 +89,11 @@ function testCompileDIC() { 'user' => 'user', 'bundle_test' => 'bundle_test', ); - $cache->flush(); - $kernel = new DrupalKernel('testing', FALSE, $module_enabled, $cache); + $kernel = new DrupalKernel('testing', FALSE, $module_enabled, TRUE); $kernel->boot(); // Instantiate it a second time and we should still get a ContainerBuilder // class because we are using the read-only PHP storage. - $kernel = new DrupalKernel('testing', FALSE, $module_enabled, $cache); + $kernel = new DrupalKernel('testing', FALSE, $module_enabled, TRUE); $kernel->boot(); $container = $kernel->getContainer(); $refClass = new ReflectionClass($container);