From 7103295b5dfed35ef05b69ad0dc4618b2a946e76 Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Fri, 2 Aug 2024 10:47:01 +0200 Subject: [PATCH] [HttpFoundation] Add `$requests` parameter to `RequestStack` constructor --- src/Symfony/Component/HttpFoundation/CHANGELOG.md | 5 +++++ src/Symfony/Component/HttpFoundation/RequestStack.php | 10 ++++++++++ .../HttpFoundation/Tests/RequestStackTest.php | 7 +++++++ 3 files changed, 22 insertions(+) diff --git a/src/Symfony/Component/HttpFoundation/CHANGELOG.md b/src/Symfony/Component/HttpFoundation/CHANGELOG.md index 0034705672dff..64c2d38f2de2f 100644 --- a/src/Symfony/Component/HttpFoundation/CHANGELOG.md +++ b/src/Symfony/Component/HttpFoundation/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +7.2 +--- + + * Add optional `$requests` argument to `RequestStack::__construct()` + 7.1 --- diff --git a/src/Symfony/Component/HttpFoundation/RequestStack.php b/src/Symfony/Component/HttpFoundation/RequestStack.php index ac8263e916618..c358ea68c3a60 100644 --- a/src/Symfony/Component/HttpFoundation/RequestStack.php +++ b/src/Symfony/Component/HttpFoundation/RequestStack.php @@ -26,6 +26,16 @@ class RequestStack */ private array $requests = []; + /** + * @param Request[] $requests + */ + public function __construct(array $requests = []) + { + foreach ($requests as $request) { + $this->push($request); + } + } + /** * Pushes a Request on the stack. * diff --git a/src/Symfony/Component/HttpFoundation/Tests/RequestStackTest.php b/src/Symfony/Component/HttpFoundation/Tests/RequestStackTest.php index 2b26ce5c64aea..6fba27589c2b0 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/RequestStackTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/RequestStackTest.php @@ -17,6 +17,13 @@ class RequestStackTest extends TestCase { + public function testConstruct() + { + $request = Request::create('/foo'); + $requestStack = new RequestStack([$request]); + $this->assertSame($request, $requestStack->getCurrentRequest()); + } + public function testGetCurrentRequest() { $requestStack = new RequestStack();