@@ -13,6 +13,8 @@ Currently available discovery services:
13
13
- PSR-7 Message Factory Discovery
14
14
- PSR-7 URI Factory Discovery
15
15
- PSR-7 Stream Factory Discovery
16
+ - PSR-17 Factory Discovery
17
+ - PSR-18 Client Discovery
16
18
- Mock Client Discovery (not enabled by default)
17
19
18
20
The principle is always the same: you call the static ``find `` method on the discovery service if no explicit
@@ -150,7 +152,7 @@ This type of discovery finds an HTTP Client implementation::
150
152
/**
151
153
* @var HttpClient
152
154
*/
153
- protected $httpClient;
155
+ private $httpClient;
154
156
155
157
/**
156
158
* @param HttpClient|null $httpClient Client to do HTTP requests, if not set, auto discovery will be used to find a HTTP client.
@@ -174,7 +176,7 @@ This type of discovery finds a HTTP asynchronous Client implementation::
174
176
/**
175
177
* @var HttpAsyncClient
176
178
*/
177
- protected $httpAsyncClient;
179
+ private $httpAsyncClient;
178
180
179
181
/**
180
182
* @param HttpAsyncClient|null $httpAsyncClient Client to do HTTP requests, if not set, auto discovery will be used to find an asynchronous client.
@@ -199,7 +201,7 @@ implementation::
199
201
/**
200
202
* @var MessageFactory
201
203
*/
202
- protected $messageFactory;
204
+ private $messageFactory;
203
205
204
206
/**
205
207
* @param MessageFactory|null $messageFactory to create PSR-7 requests.
@@ -223,7 +225,7 @@ This type of discovery finds a URI factory for a PSR-7_ URI implementation::
223
225
/**
224
226
* @var UriFactory
225
227
*/
226
- protected $uriFactory;
228
+ private $uriFactory;
227
229
228
230
/**
229
231
* @param UriFactory|null $uriFactory to create UriInterface instances from strings.
@@ -233,6 +235,55 @@ This type of discovery finds a URI factory for a PSR-7_ URI implementation::
233
235
$this->uriFactory = $uriFactory ?: UriFactoryDiscovery::find();
234
236
}
235
237
}
238
+
239
+ PSR-17 Factory Discovery
240
+ ------------------------
241
+
242
+ This type of discovery finds a factory for a PSR-17 _ implementation::
243
+
244
+ use Psr\Http\Message\RequestFactoryInterface;
245
+ use Psr\Http\Message\ResponseFactoryInterface;
246
+ use Http\Discovery\Psr17FactoryDiscovery;
247
+
248
+ class MyClass
249
+ {
250
+ /**
251
+ * @var RequestFactoryInterface
252
+ */
253
+ private $requestFactory;
254
+
255
+ /**
256
+ * @var ResponseFactoryInterface
257
+ */
258
+ private $responseFactory;
259
+
260
+ public function __construct(RequestFactoryInterface $requestFactory = null, ResponseFactoryInterface $responseFactory = null)
261
+ {
262
+ $this->requestFactory = $requestFactory ?: Psr17FactoryDiscovery::findRequestFactory();
263
+ $this->responseFactory = $responseFactory ?: Psr17FactoryDiscovery::findResponseFactory();
264
+ }
265
+ }
266
+
267
+ PSR-18 Client Discovery
268
+ -----------------------
269
+
270
+ This type of discovery finds a PSR-18 HTTP Client implementation::
271
+
272
+ use Psr\Http\Client\ClientInterface;
273
+ use Http\Discovery\Psr18ClientDiscovery;
274
+
275
+ class MyClass
276
+ {
277
+ /**
278
+ * @var ClientInterface
279
+ */
280
+ private $httpClient;
281
+
282
+ public function __construct(ClientInterface $httpClient = null)
283
+ {
284
+ $this->httpClient = $httpClient ?: Psr18ClientDiscovery::find();
285
+ }
286
+ }
236
287
237
288
Mock Client Discovery
238
289
---------------------------
0 commit comments