Skip to content

Commit d0492d6

Browse files
[HttpFoundation][FrameworkBundle] Reset Request's formats using the service resetter
1 parent e8fdc47 commit d0492d6

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

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
}

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)