57
57
*
58
58
* @author Nicolas Grekas <p@tchwork.com>
59
59
*/
60
- final class HttplugClient implements HttplugInterface, HttpAsyncClient, RequestFactory, StreamFactory, UriFactory, ResetInterface
60
+ final class HttplugClient implements HttplugInterface, HttpAsyncClient, RequestFactoryInterface, StreamFactoryInterface, UriFactoryInterface, RequestFactory, StreamFactory, UriFactory, ResetInterface
61
61
{
62
62
private HttpClientInterface $ client ;
63
63
private ResponseFactoryInterface $ responseFactory ;
@@ -142,8 +142,15 @@ public function wait(float $maxDuration = null, float $idleTimeout = null): int
142
142
return $ this ->waitLoop ->wait (null , $ maxDuration , $ idleTimeout );
143
143
}
144
144
145
+ /**
146
+ * @param string $method
147
+ * @param UriInterface|string $uri
148
+ */
145
149
public function createRequest ($ method , $ uri , array $ headers = [], $ body = null , $ protocolVersion = '1.1 ' ): RequestInterface
146
150
{
151
+ if (2 < \func_num_args ()) {
152
+ trigger_deprecation ('symfony/http-client ' , '6.2 ' , 'Passing more than 2 arguments to "%s()" is deprecated. ' , __METHOD__ );
153
+ }
147
154
if ($ this ->responseFactory instanceof RequestFactoryInterface) {
148
155
$ request = $ this ->responseFactory ->createRequest ($ method , $ uri );
149
156
} elseif (class_exists (Request::class)) {
@@ -156,7 +163,7 @@ public function createRequest($method, $uri, array $headers = [], $body = null,
156
163
157
164
$ request = $ request
158
165
->withProtocolVersion ($ protocolVersion )
159
- ->withBody ($ this ->createStream ($ body ))
166
+ ->withBody ($ this ->createStream ($ body ?? '' ))
160
167
;
161
168
162
169
foreach ($ headers as $ name => $ value ) {
@@ -166,18 +173,25 @@ public function createRequest($method, $uri, array $headers = [], $body = null,
166
173
return $ request ;
167
174
}
168
175
169
- public function createStream ($ body = null ): StreamInterface
176
+ /**
177
+ * @param string $content
178
+ */
179
+ public function createStream ($ content = '' ): StreamInterface
170
180
{
171
- if ($ body instanceof StreamInterface ) {
172
- return $ body ;
181
+ if (! \is_string ( $ content ) ) {
182
+ trigger_deprecation ( ' symfony/http-client ' , ' 6.2 ' , ' Passing a "%s" to "%s()" is deprecated, use "createStreamFrom*()" instead. ' , get_debug_type ( $ content ), __METHOD__ ) ;
173
183
}
174
184
175
- if (\is_string ($ body ?? '' )) {
176
- $ stream = $ this ->streamFactory ->createStream ($ body ?? '' );
177
- } elseif (\is_resource ($ body )) {
178
- $ stream = $ this ->streamFactory ->createStreamFromResource ($ body );
185
+ if ($ content instanceof StreamInterface) {
186
+ return $ content ;
187
+ }
188
+
189
+ if (\is_string ($ content ?? '' )) {
190
+ $ stream = $ this ->streamFactory ->createStream ($ content ?? '' );
191
+ } elseif (\is_resource ($ content )) {
192
+ $ stream = $ this ->streamFactory ->createStreamFromResource ($ content );
179
193
} else {
180
- throw new \InvalidArgumentException (sprintf ('"%s()" expects string, resource or StreamInterface, "%s" given. ' , __METHOD__ , get_debug_type ($ body )));
194
+ throw new \InvalidArgumentException (sprintf ('"%s()" expects string, resource or StreamInterface, "%s" given. ' , __METHOD__ , get_debug_type ($ content )));
181
195
}
182
196
183
197
if ($ stream ->isSeekable ()) {
@@ -187,8 +201,25 @@ public function createStream($body = null): StreamInterface
187
201
return $ stream ;
188
202
}
189
203
190
- public function createUri ( $ uri ): UriInterface
204
+ public function createStreamFromFile ( string $ filename , string $ mode = ' r ' ): StreamInterface
191
205
{
206
+ return $ this ->streamFactory ->createStreamFromFile ($ filename , $ mode );
207
+ }
208
+
209
+ public function createStreamFromResource ($ resource ): StreamInterface
210
+ {
211
+ return $ this ->streamFactory ->createStreamFromResource ($ resource );
212
+ }
213
+
214
+ /**
215
+ * @param string $uri
216
+ */
217
+ public function createUri ($ uri = '' ): UriInterface
218
+ {
219
+ if (!\is_string ($ uri )) {
220
+ trigger_deprecation ('symfony/http-client ' , '6.2 ' , 'Passing a "%s" to "%s()" is deprecated, pass a string instead. ' , get_debug_type ($ uri ), __METHOD__ );
221
+ }
222
+
192
223
if ($ uri instanceof UriInterface) {
193
224
return $ uri ;
194
225
}
0 commit comments