Skip to content

Commit

Permalink
[HttpFoundation] Allow array style callable setting for Request setFa…
Browse files Browse the repository at this point in the history
…ctory method
  • Loading branch information
simbera authored and derrabus committed Mar 19, 2024
1 parent 439fdfd commit 8789625
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(...);
}

/**
Expand Down
17 changes: 17 additions & 0 deletions Tests/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 8789625

Please sign in to comment.