diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index 5fa7c07a40ada..617628aa66a3e 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -382,7 +382,7 @@ public static function create(string $uri, string $method = 'GET', array $parame */ public static function setFactory(?callable $callable): void { - self::$requestFactory = $callable; + self::$requestFactory = null === $callable ? null : $callable(...); } /** diff --git a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php index ad5b29850bbee..68cb6ee43bed5 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php @@ -2197,6 +2197,23 @@ public function testFactory() Request::setFactory(null); } + public function testFactoryCallable() + { + $requestFactory = new class { + public function createRequest(): Request + { + return new NewRequest(); + } + }; + + Request::setFactory([$requestFactory, 'createRequest']); + + $this->assertEquals('foo', Request::create('/')->getFoo()); + + Request::setFactory(null); + + } + /** * @dataProvider getLongHostNames */