Loading core/lib/Drupal/Core/CoreServiceProvider.php +5 −0 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ use Drupal\Core\Site\Settings; use Psr\Log\LoggerAwareInterface; use Symfony\Component\DependencyInjection\Compiler\PassConfig; use Symfony\Component\DependencyInjection\Compiler\RemoveBuildParametersPass; use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass; use Symfony\Component\EventDispatcher\EventSubscriberInterface; Loading Loading @@ -65,6 +66,10 @@ public function register(ContainerBuilder $container) { $container->addCompilerPass(new HookCollectorPass()); $container->addCompilerPass(new ThemeHookCollectorPass()); $container->addCompilerPass(new HookCollectorKeyValueWritePass(), PassConfig::TYPE_OPTIMIZE); // Remove dot-prefixed build parameters (e.g. '.hook_data', // '.theme_hook_data') that are used to pass data between compiler // passes but should not leak into the cached container. $container->addCompilerPass(new RemoveBuildParametersPass(), PassConfig::TYPE_REMOVE); // Add the compiler pass that lets service providers modify existing // service definitions. This pass must come before all passes operating on // services so that later list-building passes are operating on the Loading core/tests/Drupal/KernelTests/Core/DrupalKernel/DrupalKernelTest.php +23 −0 Original line number Diff line number Diff line Loading @@ -162,6 +162,29 @@ public function testCompileDIC(): void { $this->assertNotContains('service_container', $persist_ids); } /** * Tests that dot-prefixed build parameters are removed from the container. * * Build parameters (e.g. '.hook_data') are used to pass data between * compiler passes. RemoveBuildParametersPass strips them so they don't * bloat the cached container definition with data that is only needed at * build time. */ public function testBuildParametersRemoved(): void { $request = Request::createFromGlobals(); $kernel = $this->getTestKernel($request); $container = $kernel->getContainer(); $build_only = array_filter( array_keys($container->getParameterBag()->all()), fn(string $name) => str_starts_with($name, '.'), ); $this->assertEmpty($build_only, sprintf( 'Dot-prefixed build parameters should not be in the compiled container, but found: %s', implode(', ', $build_only), )); } /** * Tests repeated loading of compiled DIC with different environment. */ Loading Loading
core/lib/Drupal/Core/CoreServiceProvider.php +5 −0 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ use Drupal\Core\Site\Settings; use Psr\Log\LoggerAwareInterface; use Symfony\Component\DependencyInjection\Compiler\PassConfig; use Symfony\Component\DependencyInjection\Compiler\RemoveBuildParametersPass; use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass; use Symfony\Component\EventDispatcher\EventSubscriberInterface; Loading Loading @@ -65,6 +66,10 @@ public function register(ContainerBuilder $container) { $container->addCompilerPass(new HookCollectorPass()); $container->addCompilerPass(new ThemeHookCollectorPass()); $container->addCompilerPass(new HookCollectorKeyValueWritePass(), PassConfig::TYPE_OPTIMIZE); // Remove dot-prefixed build parameters (e.g. '.hook_data', // '.theme_hook_data') that are used to pass data between compiler // passes but should not leak into the cached container. $container->addCompilerPass(new RemoveBuildParametersPass(), PassConfig::TYPE_REMOVE); // Add the compiler pass that lets service providers modify existing // service definitions. This pass must come before all passes operating on // services so that later list-building passes are operating on the Loading
core/tests/Drupal/KernelTests/Core/DrupalKernel/DrupalKernelTest.php +23 −0 Original line number Diff line number Diff line Loading @@ -162,6 +162,29 @@ public function testCompileDIC(): void { $this->assertNotContains('service_container', $persist_ids); } /** * Tests that dot-prefixed build parameters are removed from the container. * * Build parameters (e.g. '.hook_data') are used to pass data between * compiler passes. RemoveBuildParametersPass strips them so they don't * bloat the cached container definition with data that is only needed at * build time. */ public function testBuildParametersRemoved(): void { $request = Request::createFromGlobals(); $kernel = $this->getTestKernel($request); $container = $kernel->getContainer(); $build_only = array_filter( array_keys($container->getParameterBag()->all()), fn(string $name) => str_starts_with($name, '.'), ); $this->assertEmpty($build_only, sprintf( 'Dot-prefixed build parameters should not be in the compiled container, but found: %s', implode(', ', $build_only), )); } /** * Tests repeated loading of compiled DIC with different environment. */ Loading