diff --git a/core/core.services.yml b/core/core.services.yml index 9bca081cc48006f34bb6990cc674b5f51a58e5d3..ef3aefb9d07663cbfd64f4189c2d17bdcfd402cd 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -1492,10 +1492,6 @@ services: class: Drupal\Core\StreamWrapper\TemporaryStream tags: - { name: stream_wrapper, scheme: temporary } - kernel_destruct_subscriber: - class: Drupal\Core\EventSubscriber\KernelDestructionSubscriber - calls: - - [setContainer, ['@service_container']] image.toolkit.manager: class: Drupal\Core\ImageToolkit\ImageToolkitManager arguments: ['@config.factory'] diff --git a/core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterServicesForDestructionPass.php b/core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterServicesForDestructionPass.php index af11c39ca3af5bbecdab84b1c1868eda3e54258e..d15fb0b7cc88179a46c19d3bcdc7c53abb4899f7 100644 --- a/core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterServicesForDestructionPass.php +++ b/core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterServicesForDestructionPass.php @@ -6,7 +6,7 @@ use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; /** - * Adds services with specific tags to "kernel_destruct_subscriber" service. + * Adds services to the "kernel.destructable_services" container parameter. * * Only services tagged with "needs_destruction" are added. * @@ -18,15 +18,8 @@ class RegisterServicesForDestructionPass implements CompilerPassInterface { * {@inheritdoc} */ public function process(ContainerBuilder $container) { - if (!$container->hasDefinition('kernel_destruct_subscriber')) { - return; - } - - $definition = $container->getDefinition('kernel_destruct_subscriber'); $services = $container->findTaggedServiceIds('needs_destruction'); - foreach ($services as $id => $attributes) { - $definition->addMethodCall('registerService', [$id]); - } + $container->setParameter('kernel.destructable_services', array_keys($services)); } } diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php index 8d3a51468e9abd28552ef81869f937832a1e0aa3..9a9a14f1ca31471821a2ee15aa8474cb0a5a4c76 100644 --- a/core/lib/Drupal/Core/DrupalKernel.php +++ b/core/lib/Drupal/Core/DrupalKernel.php @@ -685,14 +685,21 @@ public function getServiceProviders($origin) { * @return void */ public function terminate(Request $request, Response $response) { - // Only run terminate() when essential services have been set up properly - // by preHandle() before. - if (FALSE === $this->prepared) { - return; - } - if ($this->getHttpKernel() instanceof TerminableInterface) { - $this->getHttpKernel()->terminate($request, $response); + // Only run terminate() when essential services have been set up properly + // by preHandle() before. + if ($this->prepared === TRUE) { + $this->getHttpKernel()->terminate($request, $response); + } + // For destructable services, always call the destruct method if they were + // initialized during the request. Destruction is not necessary if the + // service was not used. + foreach ($this->container->getParameter('kernel.destructable_services') as $id) { + if ($this->container->initialized($id)) { + $service = $this->container->get($id); + $service->destruct(); + } + } } } diff --git a/core/lib/Drupal/Core/EventSubscriber/KernelDestructionSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/KernelDestructionSubscriber.php index dfc7ab30b25aae129436fc0d30879b20788408bf..64b50c84d5c97666d108db0111f2f16c852e56a3 100644 --- a/core/lib/Drupal/Core/EventSubscriber/KernelDestructionSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/KernelDestructionSubscriber.php @@ -11,6 +11,9 @@ /** * Destructs services that are initiated and tagged with "needs_destruction". * + * @deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. There is no + * replacement. + * @see https://www.drupal.org/node/3416021 * @see \Drupal\Core\DestructableInterface */ class KernelDestructionSubscriber implements EventSubscriberInterface, ContainerAwareInterface { diff --git a/core/modules/user/src/EventSubscriber/UserRequestSubscriber.php b/core/modules/user/src/EventSubscriber/UserRequestSubscriber.php index 11fe4ec7304f0021f3bb277d8f46ed158a94d83a..31eff42f7be86b348a78ddd93c7d22aeab11f2bf 100644 --- a/core/modules/user/src/EventSubscriber/UserRequestSubscriber.php +++ b/core/modules/user/src/EventSubscriber/UserRequestSubscriber.php @@ -60,9 +60,7 @@ public function onKernelTerminate(TerminateEvent $event) { * {@inheritdoc} */ public static function getSubscribedEvents(): array { - // Should go before other subscribers start to write their caches. Notably - // before \Drupal\Core\EventSubscriber\KernelDestructionSubscriber to - // prevent instantiation of destructed services. + // Should go before other subscribers start to write their caches. $events[KernelEvents::TERMINATE][] = ['onKernelTerminate', 300]; return $events; } diff --git a/core/phpstan-baseline.neon b/core/phpstan-baseline.neon index d3f60bb4947d7861f8e2698af72349de10c5d87e..aa7ade41ee6de65651cee308abab77320491d3d9 100644 --- a/core/phpstan-baseline.neon +++ b/core/phpstan-baseline.neon @@ -674,22 +674,6 @@ parameters: count: 2 path: lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php - - - message: """ - #^Class Drupal\\\\Core\\\\EventSubscriber\\\\KernelDestructionSubscriber implements deprecated interface Symfony\\\\Component\\\\DependencyInjection\\\\ContainerAwareInterface\\: - since Symfony 6\\.4, use dependency injection instead$# - """ - count: 1 - path: lib/Drupal/Core/EventSubscriber/KernelDestructionSubscriber.php - - - - message: """ - #^Usage of deprecated trait Symfony\\\\Component\\\\DependencyInjection\\\\ContainerAwareTrait in class Drupal\\\\Core\\\\EventSubscriber\\\\KernelDestructionSubscriber\\: - since Symfony 6\\.4, use dependency injection instead$# - """ - count: 1 - path: lib/Drupal/Core/EventSubscriber/KernelDestructionSubscriber.php - - message: """ #^Call to deprecated method getFromDriverName\\(\\) of class Drupal\\\\Core\\\\Extension\\\\DatabaseDriverList\\: diff --git a/core/profiles/demo_umami/tests/src/FunctionalJavascript/OpenTelemetryAuthenticatedPerformanceTest.php b/core/profiles/demo_umami/tests/src/FunctionalJavascript/OpenTelemetryAuthenticatedPerformanceTest.php index a42f42b697027185cc6c9c25a48b0f146524b79b..c6ae94479d8a8981ae01359406b3fa3cf1fc6e65 100644 --- a/core/profiles/demo_umami/tests/src/FunctionalJavascript/OpenTelemetryAuthenticatedPerformanceTest.php +++ b/core/profiles/demo_umami/tests/src/FunctionalJavascript/OpenTelemetryAuthenticatedPerformanceTest.php @@ -37,7 +37,7 @@ public function testFrontPageAuthenticatedWarmCache(): void { }, 'authenticatedFrontPage'); $this->assertGreaterThanOrEqual(15, $performance_data->getQueryCount()); $this->assertLessThanOrEqual(16, $performance_data->getQueryCount()); - $this->assertSame(43, $performance_data->getCacheGetCount()); + $this->assertSame(45, $performance_data->getCacheGetCount()); $this->assertSame(0, $performance_data->getCacheSetCount()); $this->assertSame(0, $performance_data->getCacheDeleteCount()); } diff --git a/core/profiles/demo_umami/tests/src/FunctionalJavascript/OpenTelemetryFrontPagePerformanceTest.php b/core/profiles/demo_umami/tests/src/FunctionalJavascript/OpenTelemetryFrontPagePerformanceTest.php index 4730e6fcabb1dd8cefbaf2480f7bafaa1bf21183..8e896ebc6575edd2491d7a1d8f6c14695b02df95 100644 --- a/core/profiles/demo_umami/tests/src/FunctionalJavascript/OpenTelemetryFrontPagePerformanceTest.php +++ b/core/profiles/demo_umami/tests/src/FunctionalJavascript/OpenTelemetryFrontPagePerformanceTest.php @@ -48,9 +48,14 @@ public function testFrontPageHotCache() { // in the browser cache. $this->drupalGet('<front>'); $this->drupalGet('<front>'); - $this->collectPerformanceData(function () { + $performance_data = $this->collectPerformanceData(function () { $this->drupalGet('<front>'); - }, 'umamiFrontPageWarmCache'); + }, 'umamiFrontPageHotCache'); + $this->assertSession()->pageTextContains('Umami'); + $this->assertSame(1, $performance_data->getQueryCount()); + $this->assertSame(1, $performance_data->getCacheGetCount()); + $this->assertSame(0, $performance_data->getCacheSetCount()); + $this->assertSame(0, $performance_data->getCacheDeleteCount()); } /** diff --git a/core/profiles/standard/tests/src/FunctionalJavascript/StandardPerformanceTest.php b/core/profiles/standard/tests/src/FunctionalJavascript/StandardPerformanceTest.php index de771fcc4609b4da1e310866bcadd8532de7f07b..aef02c1f032dd077bbe6adcaadf9635843ed13c6 100644 --- a/core/profiles/standard/tests/src/FunctionalJavascript/StandardPerformanceTest.php +++ b/core/profiles/standard/tests/src/FunctionalJavascript/StandardPerformanceTest.php @@ -55,8 +55,8 @@ public function testAnonymous() { $this->drupalGet(''); }, 'standardFrontPage'); $this->assertNoJavaScript($performance_data); - $this->assertSame(66, $performance_data->getQueryCount()); - $this->assertSame(135, $performance_data->getCacheGetCount()); + $this->assertSame(68, $performance_data->getQueryCount()); + $this->assertSame(137, $performance_data->getCacheGetCount()); $this->assertSame(47, $performance_data->getCacheSetCount()); $this->assertSame(0, $performance_data->getCacheDeleteCount()); @@ -66,8 +66,8 @@ public function testAnonymous() { }); $this->assertNoJavaScript($performance_data); - $this->assertSame(38, $performance_data->getQueryCount()); - $this->assertSame(94, $performance_data->getCacheGetCount()); + $this->assertSame(39, $performance_data->getQueryCount()); + $this->assertSame(95, $performance_data->getCacheGetCount()); $this->assertSame(16, $performance_data->getCacheSetCount()); $this->assertSame(0, $performance_data->getCacheDeleteCount()); @@ -77,8 +77,8 @@ public function testAnonymous() { $this->drupalGet('user/' . $user->id()); }); $this->assertNoJavaScript($performance_data); - $this->assertSame(40, $performance_data->getQueryCount()); - $this->assertSame(80, $performance_data->getCacheGetCount()); + $this->assertSame(41, $performance_data->getQueryCount()); + $this->assertSame(81, $performance_data->getCacheGetCount()); $this->assertSame(16, $performance_data->getCacheSetCount()); $this->assertSame(0, $performance_data->getCacheDeleteCount()); } @@ -106,8 +106,8 @@ public function testLogin(): void { }); $this->assertGreaterThanOrEqual(38, $performance_data->getQueryCount()); - $this->assertLessThanOrEqual(39, $performance_data->getQueryCount()); - $this->assertSame(62, $performance_data->getCacheGetCount()); + $this->assertLessThanOrEqual(40, $performance_data->getQueryCount()); + $this->assertSame(64, $performance_data->getCacheGetCount()); $this->assertSame(1, $performance_data->getCacheSetCount()); $this->assertSame(1, $performance_data->getCacheDeleteCount()); } @@ -136,8 +136,8 @@ public function testLoginBlock(): void { $performance_data = $this->collectPerformanceData(function () use ($account) { $this->submitLoginForm($account); }); - $this->assertSame(47, $performance_data->getQueryCount()); - $this->assertSame(83, $performance_data->getCacheGetCount()); + $this->assertSame(49, $performance_data->getQueryCount()); + $this->assertSame(85, $performance_data->getCacheGetCount()); $this->assertSame(1, $performance_data->getCacheSetCount()); $this->assertSame(1, $performance_data->getCacheDeleteCount()); }