17
17
use Http \Message \RequestFactory ;
18
18
use Psr \Http \Client \ClientInterface ;
19
19
use Psr \Http \Message \RequestFactoryInterface ;
20
+ use Psr \Http \Message \StreamFactoryInterface ;
20
21
21
22
class HttpPluginClientBuilder
22
23
{
@@ -26,14 +27,19 @@ class HttpPluginClientBuilder
26
27
private $ pluginClient ;
27
28
/** @var RequestFactory|RequestFactoryInterface */
28
29
private $ requestFactory ;
30
+ private $ streamFactory ;
29
31
/** @var Plugin[] */
30
32
private $ plugins = [];
31
33
32
34
/**
33
35
* @param RequestFactory|RequestFactoryInterface|null $requestFactory
36
+ * @param StreamFactoryInterface|null $streamFactory
34
37
*/
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
+ ) {
37
43
$ requestFactory = $ requestFactory ?? Psr17FactoryDiscovery::findRequestFactory ();
38
44
if ($ requestFactory instanceof RequestFactory) {
39
45
// Use same format as symfony/deprecation-contracts.
@@ -57,6 +63,7 @@ public function __construct(?ClientInterface $httpClient = null, $requestFactory
57
63
58
64
$ this ->httpClient = $ httpClient ?? Psr18ClientDiscovery::find ();
59
65
$ this ->requestFactory = $ requestFactory ;
66
+ $ this ->streamFactory = $ streamFactory ?? Psr17FactoryDiscovery::findStreamFactory ();
60
67
}
61
68
62
69
public function addPlugin (Plugin $ plugin )
@@ -83,7 +90,8 @@ public function getHttpClient()
83
90
if (!$ this ->pluginClient ) {
84
91
$ this ->pluginClient = new HttpMethodsClient (
85
92
new PluginClient ($ this ->httpClient , $ this ->plugins ),
86
- $ this ->requestFactory
93
+ $ this ->requestFactory ,
94
+ $ this ->streamFactory
87
95
);
88
96
}
89
97
0 commit comments