diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php index 0f103e67cd3d..6a5ce77e1f71 100644 --- a/core/lib/Drupal/Core/DrupalKernel.php +++ b/core/lib/Drupal/Core/DrupalKernel.php @@ -52,8 +52,6 @@ use Symfony\Component\Routing\Route; */ class DrupalKernel implements DrupalKernelInterface, TerminableInterface { - const CONTAINER_BASE_CLASS = '\Drupal\Core\DependencyInjection\Container'; - /** * Holds the container instance. * @@ -815,7 +813,8 @@ class DrupalKernel implements DrupalKernelInterface, TerminableInterface { \Drupal::setContainer($this->container); // If needs dumping flag was set, dump the container. - if ($this->containerNeedsDumping && !$this->dumpDrupalContainer($this->container, static::CONTAINER_BASE_CLASS)) { + $base_class = Settings::get('container_base_class', '\Drupal\Core\DependencyInjection\Container'); + if ($this->containerNeedsDumping && !$this->dumpDrupalContainer($this->container, $base_class)) { $this->container->get('logger.factory')->get('DrupalKernel')->notice('Container cannot be written to disk'); } diff --git a/core/modules/system/src/Tests/System/ErrorContainerRebuildKernel.php b/core/modules/system/src/Tests/System/ErrorContainerRebuildKernel.php deleted file mode 100644 index 8e8db22ef720..000000000000 --- a/core/modules/system/src/Tests/System/ErrorContainerRebuildKernel.php +++ /dev/null @@ -1,22 +0,0 @@ -prepareRequestForGenerator(), $this->classLoader, 'prod', TRUE); - $kernel->rebuildContainer(); + $settings = []; + $settings['settings']['container_base_class'] = (object) [ + 'value' => '\Drupal\system\Tests\Bootstrap\ErrorContainer', + 'required' => TRUE, + ]; + $this->writeSettings($settings); + + // Need to rebuild the container, so the dumped container can be tested + // and not the container builder. + \Drupal::service('kernel')->rebuildContainer(); - $this->prepareRequestForGenerator(); // Ensure that we don't use the now broken generated container on the test // process. \Drupal::setContainer($this->container); @@ -137,10 +144,17 @@ class UncaughtExceptionTest extends WebTestBase { * Tests a container which has an exception really early. */ public function testExceptionContainer() { - $kernel = ExceptionContainerRebuildKernel::createFromRequest($this->prepareRequestForGenerator(), $this->classLoader, 'prod', TRUE); - $kernel->rebuildContainer(); + $settings = []; + $settings['settings']['container_base_class'] = (object) [ + 'value' => '\Drupal\system\Tests\Bootstrap\ExceptionContainer', + 'required' => TRUE, + ]; + $this->writeSettings($settings); + + // Need to rebuild the container, so the dumped container can be tested + // and not the container builder. + \Drupal::service('kernel')->rebuildContainer(); - $this->prepareRequestForGenerator(); // Ensure that we don't use the now broken generated container on the test // process. \Drupal::setContainer($this->container); diff --git a/sites/default/default.settings.php b/sites/default/default.settings.php index 330cc560e8b3..9ad5cae550b9 100644 --- a/sites/default/default.settings.php +++ b/sites/default/default.settings.php @@ -632,6 +632,15 @@ if ($settings['hash_salt']) { */ $settings['container_yamls'][] = __DIR__ . '/services.yml'; +/** + * Override the default service container class. + * + * This is useful for example to trace the service container for performance + * tracking purposes, for testing a service container with an error condition or + * to test a service container that throws an exception. + */ +# $settings['container_base_class'] = '\Drupal\Core\DependencyInjection\Container'; + /** * Trusted host configuration. *