diff --git a/src/Symfony/Component/Routing/RequestContext.php b/src/Symfony/Component/Routing/RequestContext.php index 5e9e79d91680..cf7fd0985d8a 100644 --- a/src/Symfony/Component/Routing/RequestContext.php +++ b/src/Symfony/Component/Routing/RequestContext.php @@ -33,7 +33,7 @@ class RequestContext private string $queryString; private array $parameters = []; - public function __construct(string $baseUrl = '', string $method = 'GET', string $host = 'localhost', string $scheme = 'http', int $httpPort = 80, int $httpsPort = 443, string $path = '/', string $queryString = '') + public function __construct(string $baseUrl = '', string $method = 'GET', string $host = 'localhost', string $scheme = 'http', int $httpPort = 80, int $httpsPort = 443, string $path = '/', string $queryString = '', array $parameters = []) { $this->setBaseUrl($baseUrl); $this->setMethod($method); @@ -43,6 +43,10 @@ public function __construct(string $baseUrl = '', string $method = 'GET', string $this->setHttpsPort($httpsPort); $this->setPathInfo($path); $this->setQueryString($queryString); + + if ($parameters) { + $this->parameters = $parameters; + } } public static function fromUri(string $uri, string $host = 'localhost', string $scheme = 'http', int $httpPort = 80, int $httpsPort = 443): self diff --git a/src/Symfony/Component/Routing/Tests/RequestContextTest.php b/src/Symfony/Component/Routing/Tests/RequestContextTest.php index fcc42ff593a9..0f92c9af5d68 100644 --- a/src/Symfony/Component/Routing/Tests/RequestContextTest.php +++ b/src/Symfony/Component/Routing/Tests/RequestContextTest.php @@ -27,7 +27,10 @@ public function testConstruct() 8080, 444, '/baz', - 'bar=foobar' + 'bar=foobar', + [ + 'foo' => 'bar', + ] ); $this->assertEquals('foo', $requestContext->getBaseUrl()); @@ -38,6 +41,20 @@ public function testConstruct() $this->assertSame(444, $requestContext->getHttpsPort()); $this->assertEquals('/baz', $requestContext->getPathInfo()); $this->assertEquals('bar=foobar', $requestContext->getQueryString()); + $this->assertEquals(['foo' => 'bar'], $requestContext->getParameters()); + } + + public function testConstructParametersBcLayer() + { + $requestContext = new class() extends RequestContext { + public function __construct() + { + $this->setParameters(['foo' => 'bar']); + parent::__construct(); + } + }; + + $this->assertEquals(['foo' => 'bar'], $requestContext->getParameters()); } public function testFromUriWithBaseUrl()