Skip to content

Commit

Permalink
[HttpFoundation][FrameworkBundle] Reset Request's formats using the s…
Browse files Browse the repository at this point in the history
…ervice resetter
  • Loading branch information
nicolas-grekas committed Jan 9, 2025
1 parent e8fdc47 commit d0492d6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions RequestStack.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,11 @@ public function getSession(): SessionInterface

throw new SessionNotFoundException();
}

public function resetRequestFormats(): void
{
static $resetRequestFormats;
$resetRequestFormats ??= \Closure::bind(static fn () => self::$formats = null, null, Request::class);
$resetRequestFormats();
}
}
14 changes: 14 additions & 0 deletions Tests/RequestStackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,18 @@ public function testGetParentRequest()
$requestStack->push($secondSubRequest);
$this->assertSame($firstSubRequest, $requestStack->getParentRequest());
}

public function testResetRequestFormats()
{
$requestStack = new RequestStack();

$request = Request::create('/foo');
$request->setFormat('foo', ['application/foo']);

$this->assertSame(['application/foo'], $request->getMimeTypes('foo'));

$requestStack->resetRequestFormats();

$this->assertSame([], $request->getMimeTypes('foo'));
}
}

0 comments on commit d0492d6

Please # to comment.