From bfd1cf72eeed80da9fdf1e1fcca2d706d91cf1b1 Mon Sep 17 00:00:00 2001 From: HypeMC Date: Wed, 11 Dec 2024 21:13:32 +0100 Subject: [PATCH 1/8] [HttpClient] Fix reset not called on decorated clients --- DependencyInjection/FrameworkExtension.php | 2 ++ Resources/config/http_client.php | 1 + Tests/DependencyInjection/FrameworkExtensionTestCase.php | 6 +++++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/DependencyInjection/FrameworkExtension.php b/DependencyInjection/FrameworkExtension.php index 36984e739..1dfc418cc 100644 --- a/DependencyInjection/FrameworkExtension.php +++ b/DependencyInjection/FrameworkExtension.php @@ -2565,11 +2565,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/Resources/config/http_client.php b/Resources/config/http_client.php index a4c78d0ec..593b78fdd 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/Tests/DependencyInjection/FrameworkExtensionTestCase.php b/Tests/DependencyInjection/FrameworkExtensionTestCase.php index 8ae5b7713..c891ec143 100644 --- a/Tests/DependencyInjection/FrameworkExtensionTestCase.php +++ b/Tests/DependencyInjection/FrameworkExtensionTestCase.php @@ -1976,8 +1976,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() From 66b7df1af8241815386cd2a038911c602f3bbecb Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 7 Jan 2025 18:11:41 +0100 Subject: [PATCH 2/8] [HttpFoundation][FrameworkBundle] Reset Request's formats using the service resetter --- Command/ContainerDebugCommand.php | 8 ++++++-- Resources/config/services.php | 1 + Tests/Functional/ContainerDebugCommandTest.php | 12 ++++++------ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Command/ContainerDebugCommand.php b/Command/ContainerDebugCommand.php index df6aef5dd..3000da51a 100644 --- a/Command/ContainerDebugCommand.php +++ b/Command/ContainerDebugCommand.php @@ -284,7 +284,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 @@ -302,7 +304,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/Resources/config/services.php b/Resources/config/services.php index 905e16f9b..5f280bdfb 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') diff --git a/Tests/Functional/ContainerDebugCommandTest.php b/Tests/Functional/ContainerDebugCommandTest.php index efbc1f54a..1adddd183 100644 --- a/Tests/Functional/ContainerDebugCommandTest.php +++ b/Tests/Functional/ContainerDebugCommandTest.php @@ -140,13 +140,13 @@ public function testTagsPartialSearch() $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('[0] kernel.cache_clearer', $tester->getDisplay()); + $this->assertStringContainsString('[1] kernel.cache_warmer', $tester->getDisplay()); + $this->assertStringContainsString('[2] kernel.event_subscriber', $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->assertStringContainsString('[4] kernel.locale_aware', $tester->getDisplay()); + $this->assertStringContainsString('[5] kernel.reset', $tester->getDisplay()); + $this->assertStringContainsString('Symfony Container Services Tagged with "kernel.cache_clearer" Tag', $tester->getDisplay()); } public function testDescribeEnvVars() From f2c4d746119824062a2252675cacca8b8f0e2e18 Mon Sep 17 00:00:00 2001 From: Faizan Akram Date: Sun, 8 Dec 2024 10:46:43 +0100 Subject: [PATCH 3/8] fix(dependency-injection): reset env vars with kernel.reset - fixes #59128 --- Resources/config/services.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Resources/config/services.php b/Resources/config/services.php index c85ccf5d0..a7e1c5198 100644 --- a/Resources/config/services.php +++ b/Resources/config/services.php @@ -195,6 +195,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([ From 45e3acf88f82d2494c48e93ec57b8c2f87c544f5 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 15 Jan 2025 19:35:52 +0100 Subject: [PATCH 4/8] [FrameworkBundle] Fix wiring ConsoleProfilerListener --- EventListener/ConsoleProfilerListener.php | 14 ++++++++++---- Resources/config/profiling.php | 7 ++++++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/EventListener/ConsoleProfilerListener.php b/EventListener/ConsoleProfilerListener.php index c2a71d0a7..03274450d 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/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() From 5791a99752abd452dd51165c3dec5a82202ab4a5 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 22 Jan 2025 12:30:12 +0100 Subject: [PATCH 5/8] [FrameworkBundle] Fix patching refs to the tmp warmup dir in files generated by optional cache warmers --- Command/CacheClearCommand.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Command/CacheClearCommand.php b/Command/CacheClearCommand.php index cdfc7f34f..eeafd1bd3 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, file_get_contents($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, file_get_contents($file), $count); - if ($count) { - file_put_contents($file, $content); - } - } } private function warmupOptionals(string $cacheDir, string $warmupDir, SymfonyStyle $io): void From f14292bb8daf1998350fc42d6536880b47d3b9c8 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 22 Jan 2025 14:48:49 +0100 Subject: [PATCH 6/8] [Cache] Don't clear system caches on cache:clear --- Tests/Functional/CachePoolsTest.php | 4 ---- .../Functional/ContainerDebugCommandTest.php | 20 +++++++++++-------- Tests/Functional/app/CachePools/default.yml | 5 ----- 3 files changed, 12 insertions(+), 17 deletions(-) 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 1adddd183..24c6faf33 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.cache_clearer', $tester->getDisplay()); - $this->assertStringContainsString('[1] kernel.cache_warmer', $tester->getDisplay()); - $this->assertStringContainsString('[2] kernel.event_subscriber', $tester->getDisplay()); - $this->assertStringContainsString('[3] kernel.fragment_renderer', $tester->getDisplay()); - $this->assertStringContainsString('[4] kernel.locale_aware', $tester->getDisplay()); - $this->assertStringContainsString('[5] kernel.reset', $tester->getDisplay()); - $this->assertStringContainsString('Symfony Container Services Tagged with "kernel.cache_clearer" 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 From 132ab27cf7a6fdc429721771cf8e412b3b22c923 Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Mon, 27 Jan 2025 11:11:56 +0100 Subject: [PATCH 7/8] [FrameworkBundle] Add missing `not-compromised-password` entry in XSD --- Resources/config/schema/symfony-1.0.xsd | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Resources/config/schema/symfony-1.0.xsd b/Resources/config/schema/symfony-1.0.xsd index cdc4fa5d5..7d9828eeb 100644 --- a/Resources/config/schema/symfony-1.0.xsd +++ b/Resources/config/schema/symfony-1.0.xsd @@ -266,6 +266,7 @@ + @@ -299,6 +300,11 @@ + + + + + From 91df8ee37543ebc01756c9e5eaf94d1878ff1ccd Mon Sep 17 00:00:00 2001 From: Valmonzo Date: Fri, 15 Nov 2024 16:13:35 +0100 Subject: [PATCH 8/8] [Serializer] fix default context in Serializer --- Resources/config/serializer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Resources/config/serializer.php b/Resources/config/serializer.php index 85231d0bf..c29258d52 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')