Skip to content

Commit 8789625

Browse files
simberaderrabus
authored andcommitted
[HttpFoundation] Allow array style callable setting for Request setFactory method
1 parent 439fdfd commit 8789625

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Request.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ public static function create(string $uri, string $method = 'GET', array $parame
382382
*/
383383
public static function setFactory(?callable $callable): void
384384
{
385-
self::$requestFactory = $callable;
385+
self::$requestFactory = null === $callable ? null : $callable(...);
386386
}
387387

388388
/**

Tests/RequestTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2197,6 +2197,23 @@ public function testFactory()
21972197
Request::setFactory(null);
21982198
}
21992199

2200+
public function testFactoryCallable()
2201+
{
2202+
$requestFactory = new class {
2203+
public function createRequest(): Request
2204+
{
2205+
return new NewRequest();
2206+
}
2207+
};
2208+
2209+
Request::setFactory([$requestFactory, 'createRequest']);
2210+
2211+
$this->assertEquals('foo', Request::create('/')->getFoo());
2212+
2213+
Request::setFactory(null);
2214+
2215+
}
2216+
22002217
/**
22012218
* @dataProvider getLongHostNames
22022219
*/

0 commit comments

Comments
 (0)