diff --git a/Command/CacheClearCommand.php b/Command/CacheClearCommand.php index 4ef2f5a1d..0e48ead59 100644 --- a/Command/CacheClearCommand.php +++ b/Command/CacheClearCommand.php @@ -146,6 +146,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int } $this->warmupOptionals($useBuildDir ? $realCacheDir : $warmupDir, $warmupDir, $io); } + + // fix references to cached files with the real cache directory name + $search = [$warmupDir, str_replace('/', '\\/', $warmupDir), str_replace('\\', '\\\\', $warmupDir)]; + $replace = str_replace('\\', '/', $realBuildDir); + foreach (Finder::create()->files()->in($warmupDir) as $file) { + $content = str_replace($search, $replace, $this->filesystem->readFile($file), $count); + if ($count) { + file_put_contents($file, $content); + } + } } if (!$fs->exists($warmupDir.'/'.$containerDir)) { @@ -227,16 +237,6 @@ private function warmup(string $warmupDir, string $realBuildDir): void throw new \LogicException('Calling "cache:clear" with a kernel that does not implement "Symfony\Component\HttpKernel\RebootableInterface" is not supported.'); } $kernel->reboot($warmupDir); - - // fix references to cached files with the real cache directory name - $search = [$warmupDir, str_replace('\\', '\\\\', $warmupDir)]; - $replace = str_replace('\\', '/', $realBuildDir); - foreach (Finder::create()->files()->in($warmupDir) as $file) { - $content = str_replace($search, $replace, $this->filesystem->readFile($file), $count); - if ($count) { - file_put_contents($file, $content); - } - } } private function warmupOptionals(string $cacheDir, string $warmupDir, SymfonyStyle $io): void diff --git a/Command/ContainerDebugCommand.php b/Command/ContainerDebugCommand.php index 46cdca9ab..2c5b8291b 100644 --- a/Command/ContainerDebugCommand.php +++ b/Command/ContainerDebugCommand.php @@ -287,7 +287,9 @@ private function findProperServiceName(InputInterface $input, SymfonyStyle $io, return $matchingServices[0]; } - return $io->choice('Select one of the following services to display its information', $matchingServices); + natsort($matchingServices); + + return $io->choice('Select one of the following services to display its information', array_values($matchingServices)); } private function findProperTagName(InputInterface $input, SymfonyStyle $io, ContainerBuilder $container, string $tagName): string @@ -305,7 +307,9 @@ private function findProperTagName(InputInterface $input, SymfonyStyle $io, Cont return $matchingTags[0]; } - return $io->choice('Select one of the following tags to display its information', $matchingTags); + natsort($matchingTags); + + return $io->choice('Select one of the following tags to display its information', array_values($matchingTags)); } private function findServiceIdsContaining(ContainerBuilder $container, string $name, bool $showHidden): array diff --git a/DependencyInjection/FrameworkExtension.php b/DependencyInjection/FrameworkExtension.php index 3106ee30e..556a0cff6 100644 --- a/DependencyInjection/FrameworkExtension.php +++ b/DependencyInjection/FrameworkExtension.php @@ -2552,11 +2552,13 @@ private function registerHttpClientConfiguration(array $config, ContainerBuilder ->setFactory([ScopingHttpClient::class, 'forBaseUri']) ->setArguments([new Reference('http_client.transport'), $baseUri, $scopeConfig]) ->addTag('http_client.client') + ->addTag('kernel.reset', ['method' => 'reset', 'on_invalid' => 'ignore']) ; } else { $container->register($name, ScopingHttpClient::class) ->setArguments([new Reference('http_client.transport'), [$scope => $scopeConfig], $scope]) ->addTag('http_client.client') + ->addTag('kernel.reset', ['method' => 'reset', 'on_invalid' => 'ignore']) ; } diff --git a/EventListener/ConsoleProfilerListener.php b/EventListener/ConsoleProfilerListener.php index 4a8c9015e..712e2ead3 100644 --- a/EventListener/ConsoleProfilerListener.php +++ b/EventListener/ConsoleProfilerListener.php @@ -38,6 +38,8 @@ final class ConsoleProfilerListener implements EventSubscriberInterface /** @var \SplObjectStorage */ private \SplObjectStorage $parents; + private bool $disabled = false; + public function __construct( private readonly Profiler $profiler, private readonly RequestStack $requestStack, @@ -66,7 +68,7 @@ public function initialize(ConsoleCommandEvent $event): void $input = $event->getInput(); if (!$input->hasOption('profile') || !$input->getOption('profile')) { - $this->profiler->disable(); + $this->disabled = true; return; } @@ -92,7 +94,12 @@ public function catch(ConsoleErrorEvent $event): void public function profile(ConsoleTerminateEvent $event): void { - if (!$this->cliMode || !$this->profiler->isEnabled()) { + $error = $this->error; + $this->error = null; + + if (!$this->cliMode || $this->disabled) { + $this->disabled = false; + return; } @@ -114,8 +121,7 @@ public function profile(ConsoleTerminateEvent $event): void $request->command->exitCode = $event->getExitCode(); $request->command->interruptedBySignal = $event->getInterruptingSignal(); - $profile = $this->profiler->collect($request, $request->getResponse(), $this->error); - $this->error = null; + $profile = $this->profiler->collect($request, $request->getResponse(), $error); $this->profiles[$request] = $profile; if ($this->parents[$request] = $this->requestStack->getParentRequest()) { diff --git a/Resources/config/http_client.php b/Resources/config/http_client.php index 12a5c01f6..a562c2598 100644 --- a/Resources/config/http_client.php +++ b/Resources/config/http_client.php @@ -39,6 +39,7 @@ ->factory('current') ->args([[service('http_client.transport')]]) ->tag('http_client.client') + ->tag('kernel.reset', ['method' => 'reset', 'on_invalid' => 'ignore']) ->alias(HttpClientInterface::class, 'http_client') diff --git a/Resources/config/profiling.php b/Resources/config/profiling.php index eaef79597..4ae34649b 100644 --- a/Resources/config/profiling.php +++ b/Resources/config/profiling.php @@ -40,7 +40,7 @@ ->set('console_profiler_listener', ConsoleProfilerListener::class) ->args([ - service('profiler'), + service('.lazy_profiler'), service('.virtual_request_stack'), service('debug.stopwatch'), param('kernel.runtime_mode.cli'), @@ -48,6 +48,11 @@ ]) ->tag('kernel.event_subscriber') + ->set('.lazy_profiler', Profiler::class) + ->factory('current') + ->args([[service('profiler')]]) + ->lazy() + ->set('.virtual_request_stack', VirtualRequestStack::class) ->args([service('request_stack')]) ->public() diff --git a/Resources/config/schema/symfony-1.0.xsd b/Resources/config/schema/symfony-1.0.xsd index ed7cc744f..491cd1e4f 100644 --- a/Resources/config/schema/symfony-1.0.xsd +++ b/Resources/config/schema/symfony-1.0.xsd @@ -278,6 +278,7 @@ + @@ -310,6 +311,11 @@ + + + + + diff --git a/Resources/config/serializer.php b/Resources/config/serializer.php index d689d4299..4686a88f6 100644 --- a/Resources/config/serializer.php +++ b/Resources/config/serializer.php @@ -60,7 +60,7 @@ $container->services() ->set('serializer', Serializer::class) - ->args([[], []]) + ->args([[], [], []]) ->alias(SerializerInterface::class, 'serializer') ->alias(NormalizerInterface::class, 'serializer') diff --git a/Resources/config/services.php b/Resources/config/services.php index 6abe1b6d8..e5a86d8f4 100644 --- a/Resources/config/services.php +++ b/Resources/config/services.php @@ -100,6 +100,7 @@ class_exists(WorkflowEvents::class) ? WorkflowEvents::ALIASES : [] ->alias(HttpKernelInterface::class, 'http_kernel') ->set('request_stack', RequestStack::class) + ->tag('kernel.reset', ['method' => 'resetRequestFormats', 'on_invalid' => 'ignore']) ->public() ->alias(RequestStack::class, 'request_stack') @@ -197,6 +198,7 @@ class_exists(WorkflowEvents::class) ? WorkflowEvents::ALIASES : [] tagged_iterator('container.env_var_loader'), ]) ->tag('container.env_var_processor') + ->tag('kernel.reset', ['method' => 'reset']) ->set('slugger', AsciiSlugger::class) ->args([ diff --git a/Tests/DependencyInjection/FrameworkExtensionTestCase.php b/Tests/DependencyInjection/FrameworkExtensionTestCase.php index 798217191..37cdc4cf6 100644 --- a/Tests/DependencyInjection/FrameworkExtensionTestCase.php +++ b/Tests/DependencyInjection/FrameworkExtensionTestCase.php @@ -1950,8 +1950,12 @@ public function testHttpClientDefaultOptions() ]; $this->assertSame([$defaultOptions, 4], $container->getDefinition('http_client.transport')->getArguments()); + $this->assertTrue($container->getDefinition('http_client')->hasTag('kernel.reset')); + $this->assertTrue($container->hasDefinition('foo'), 'should have the "foo" service.'); - $this->assertSame(ScopingHttpClient::class, $container->getDefinition('foo')->getClass()); + $definition = $container->getDefinition('foo'); + $this->assertSame(ScopingHttpClient::class, $definition->getClass()); + $this->assertTrue($definition->hasTag('kernel.reset')); } public function testScopedHttpClientWithoutQueryOption() diff --git a/Tests/Functional/CachePoolsTest.php b/Tests/Functional/CachePoolsTest.php index 260896658..23f4a116e 100644 --- a/Tests/Functional/CachePoolsTest.php +++ b/Tests/Functional/CachePoolsTest.php @@ -88,10 +88,6 @@ private function doTestCachePools($options, $adapterClass) $pool2 = $container->get('cache.pool2'); $pool2->save($item); - $container->get('cache_clearer.alias')->clear($container->getParameter('kernel.cache_dir')); - $item = $pool1->getItem($key); - $this->assertFalse($item->isHit()); - $item = $pool2->getItem($key); $this->assertTrue($item->isHit()); diff --git a/Tests/Functional/ContainerDebugCommandTest.php b/Tests/Functional/ContainerDebugCommandTest.php index bb80a4484..5067a880d 100644 --- a/Tests/Functional/ContainerDebugCommandTest.php +++ b/Tests/Functional/ContainerDebugCommandTest.php @@ -139,14 +139,18 @@ public function testTagsPartialSearch() $tester->setInputs(['0']); $tester->run(['command' => 'debug:container', '--tag' => 'kernel.'], ['decorated' => false]); - $this->assertStringContainsString('Select one of the following tags to display its information', $tester->getDisplay()); - $this->assertStringContainsString('[0] kernel.event_subscriber', $tester->getDisplay()); - $this->assertStringContainsString('[1] kernel.locale_aware', $tester->getDisplay()); - $this->assertStringContainsString('[2] kernel.cache_warmer', $tester->getDisplay()); - $this->assertStringContainsString('[3] kernel.fragment_renderer', $tester->getDisplay()); - $this->assertStringContainsString('[4] kernel.reset', $tester->getDisplay()); - $this->assertStringContainsString('[5] kernel.cache_clearer', $tester->getDisplay()); - $this->assertStringContainsString('Symfony Container Services Tagged with "kernel.event_subscriber" Tag', $tester->getDisplay()); + $this->assertStringMatchesFormat(<<getDisplay() + ); } public function testDescribeEnvVars() diff --git a/Tests/Functional/app/CachePools/default.yml b/Tests/Functional/app/CachePools/default.yml index c03efedd0..377d3e785 100644 --- a/Tests/Functional/app/CachePools/default.yml +++ b/Tests/Functional/app/CachePools/default.yml @@ -1,7 +1,2 @@ imports: - { resource: ../config/default.yml } - -services: - cache_clearer.alias: - alias: cache_clearer - public: true