Skip to content

Commit 3ceff1d

Browse files
bug #59403 [FrameworkBundle][HttpFoundation] Reset Request's formats using the service resetter (nicolas-grekas)
This PR was merged into the 6.4 branch. Discussion ---------- [FrameworkBundle][HttpFoundation] Reset Request's formats using the service resetter | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | #59036 | License | MIT Commits ------- 56f3df4 [HttpFoundation][FrameworkBundle] Reset Request's formats using the service resetter
2 parents 351a2ec + 56f3df4 commit 3ceff1d

File tree

5 files changed

+34
-8
lines changed

5 files changed

+34
-8
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,9 @@ private function findProperServiceName(InputInterface $input, SymfonyStyle $io,
284284
return $matchingServices[0];
285285
}
286286

287-
return $io->choice('Select one of the following services to display its information', $matchingServices);
287+
natsort($matchingServices);
288+
289+
return $io->choice('Select one of the following services to display its information', array_values($matchingServices));
288290
}
289291

290292
private function findProperTagName(InputInterface $input, SymfonyStyle $io, ContainerBuilder $container, string $tagName): string
@@ -302,7 +304,9 @@ private function findProperTagName(InputInterface $input, SymfonyStyle $io, Cont
302304
return $matchingTags[0];
303305
}
304306

305-
return $io->choice('Select one of the following tags to display its information', $matchingTags);
307+
natsort($matchingTags);
308+
309+
return $io->choice('Select one of the following tags to display its information', array_values($matchingTags));
306310
}
307311

308312
private function findServiceIdsContaining(ContainerBuilder $container, string $name, bool $showHidden): array

src/Symfony/Bundle/FrameworkBundle/Resources/config/services.php

+1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ class_exists(WorkflowEvents::class) ? WorkflowEvents::ALIASES : []
100100
->alias(HttpKernelInterface::class, 'http_kernel')
101101

102102
->set('request_stack', RequestStack::class)
103+
->tag('kernel.reset', ['method' => 'resetRequestFormats', 'on_invalid' => 'ignore'])
103104
->public()
104105
->alias(RequestStack::class, 'request_stack')
105106

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ContainerDebugCommandTest.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,13 @@ public function testTagsPartialSearch()
140140
$tester->run(['command' => 'debug:container', '--tag' => 'kernel.'], ['decorated' => false]);
141141

142142
$this->assertStringContainsString('Select one of the following tags to display its information', $tester->getDisplay());
143-
$this->assertStringContainsString('[0] kernel.event_subscriber', $tester->getDisplay());
144-
$this->assertStringContainsString('[1] kernel.locale_aware', $tester->getDisplay());
145-
$this->assertStringContainsString('[2] kernel.cache_warmer', $tester->getDisplay());
143+
$this->assertStringContainsString('[0] kernel.cache_clearer', $tester->getDisplay());
144+
$this->assertStringContainsString('[1] kernel.cache_warmer', $tester->getDisplay());
145+
$this->assertStringContainsString('[2] kernel.event_subscriber', $tester->getDisplay());
146146
$this->assertStringContainsString('[3] kernel.fragment_renderer', $tester->getDisplay());
147-
$this->assertStringContainsString('[4] kernel.reset', $tester->getDisplay());
148-
$this->assertStringContainsString('[5] kernel.cache_clearer', $tester->getDisplay());
149-
$this->assertStringContainsString('Symfony Container Services Tagged with "kernel.event_subscriber" Tag', $tester->getDisplay());
147+
$this->assertStringContainsString('[4] kernel.locale_aware', $tester->getDisplay());
148+
$this->assertStringContainsString('[5] kernel.reset', $tester->getDisplay());
149+
$this->assertStringContainsString('Symfony Container Services Tagged with "kernel.cache_clearer" Tag', $tester->getDisplay());
150150
}
151151

152152
public function testDescribeEnvVars()

src/Symfony/Component/HttpFoundation/RequestStack.php

+7
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,11 @@ public function getSession(): SessionInterface
106106

107107
throw new SessionNotFoundException();
108108
}
109+
110+
public function resetRequestFormats(): void
111+
{
112+
static $resetRequestFormats;
113+
$resetRequestFormats ??= \Closure::bind(static fn () => self::$formats = null, null, Request::class);
114+
$resetRequestFormats();
115+
}
109116
}

src/Symfony/Component/HttpFoundation/Tests/RequestStackTest.php

+14
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,18 @@ public function testGetParentRequest()
6767
$requestStack->push($secondSubRequest);
6868
$this->assertSame($firstSubRequest, $requestStack->getParentRequest());
6969
}
70+
71+
public function testResetRequestFormats()
72+
{
73+
$requestStack = new RequestStack();
74+
75+
$request = Request::create('/foo');
76+
$request->setFormat('foo', ['application/foo']);
77+
78+
$this->assertSame(['application/foo'], $request->getMimeTypes('foo'));
79+
80+
$requestStack->resetRequestFormats();
81+
82+
$this->assertSame([], $request->getMimeTypes('foo'));
83+
}
7084
}

0 commit comments

Comments
 (0)