Skip to content

Commit 78ab096

Browse files
[HttpFoundation][FrameworkBundle] Reset Request's formats using the service resetter
1 parent 86b9250 commit 78ab096

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
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/Component/HttpFoundation/RequestStack.php

Lines changed: 7 additions & 0 deletions
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

Lines changed: 14 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy