Skip to content

Commit 3f8000e

Browse files
committed
Add Support for Stream Factory Autodiscovery
1 parent a8e6b70 commit 3f8000e

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/HttpClient/HttpPluginClientBuilder.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Http\Message\RequestFactory;
1818
use Psr\Http\Client\ClientInterface;
1919
use Psr\Http\Message\RequestFactoryInterface;
20+
use Psr\Http\Message\StreamFactoryInterface;
2021

2122
class HttpPluginClientBuilder
2223
{
@@ -26,14 +27,19 @@ class HttpPluginClientBuilder
2627
private $pluginClient;
2728
/** @var RequestFactory|RequestFactoryInterface */
2829
private $requestFactory;
30+
private $streamFactory;
2931
/** @var Plugin[] */
3032
private $plugins = [];
3133

3234
/**
3335
* @param RequestFactory|RequestFactoryInterface|null $requestFactory
36+
* @param StreamFactoryInterface|null $streamFactory
3437
*/
35-
public function __construct(?ClientInterface $httpClient = null, $requestFactory = null)
36-
{
38+
public function __construct(
39+
?ClientInterface $httpClient = null,
40+
$requestFactory = null,
41+
?StreamFactoryInterface $streamFactory= null
42+
) {
3743
$requestFactory = $requestFactory ?? Psr17FactoryDiscovery::findRequestFactory();
3844
if ($requestFactory instanceof RequestFactory) {
3945
// Use same format as symfony/deprecation-contracts.
@@ -57,6 +63,7 @@ public function __construct(?ClientInterface $httpClient = null, $requestFactory
5763

5864
$this->httpClient = $httpClient ?? Psr18ClientDiscovery::find();
5965
$this->requestFactory = $requestFactory;
66+
$this->streamFactory = $streamFactory ?? Psr17FactoryDiscovery::findStreamFactory();
6067
}
6168

6269
public function addPlugin(Plugin $plugin)
@@ -83,7 +90,8 @@ public function getHttpClient()
8390
if (!$this->pluginClient) {
8491
$this->pluginClient = new HttpMethodsClient(
8592
new PluginClient($this->httpClient, $this->plugins),
86-
$this->requestFactory
93+
$this->requestFactory,
94+
$this->streamFactory
8795
);
8896
}
8997

0 commit comments

Comments
 (0)