8000 bug #54333 [HttpFoundation] Allow array style callable setting for Re… · symfony/symfony@ea80120 · GitHub
[go: up one dir, main page]

Skip to content

Commit ea80120

Browse files
committed
bug #54333 [HttpFoundation] Allow array style callable setting for Request setFactory method (simbera)
This PR was squashed before being merged into the 7.0 branch. Discussion ---------- [HttpFoundation] Allow array style callable setting for Request setFactory method | Q | A | ------------- | --- | Branch? | 7.0 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #54321 | License | MIT Allowing to use the array notation for callback for the setFactory static method of the request. Unit test added to confirm bug/fixing the bug. Commits ------- 696add6 [HttpFoundation] Allow array style callable setting for Request setFactory method
2 parents e8fbd7d + 696add6 commit ea80120

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/Symfony/Component/HttpFoundation/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
/**

src/Symfony/Component/HttpFoundation/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)
0