@@ -10,10 +10,12 @@ Currently available discovery services:
10
10
11
11
- HTTP Client Discovery
12
12
- HTTP Async Client Discovery
13
- - PSR-7 Message Factory Discovery
14
- - PSR-7 URI Factory Discovery
15
- - PSR-7 Stream Factory Discovery
13
+ - PSR-17 Factory Discovery
14
+ - PSR-18 HTTP Client Discovery
16
15
- Mock Client Discovery (not enabled by default)
16
+ - PSR-7 Message Factory Discovery (deprecated)
17
+ - PSR-7 URI Factory Discovery (deprecated)
18
+ - PSR-7 Stream Factory Discovery (deprecated)
17
19
18
20
The principle is always the same: you call the static ``find `` method on the discovery service if no explicit
19
21
implementation was specified. The discovery service will try to locate a suitable implementation.
@@ -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.
@@ -185,9 +187,61 @@ This type of discovery finds a HTTP asynchronous Client implementation::
185
187
}
186
188
}
187
189
190
+ PSR-17 Factory Discovery
191
+ ------------------------
192
+
193
+ This type of discovery finds a factory for a PSR-17 _ implementation::
194
+
195
+ use Psr\Http\Message\RequestFactoryInterface;
196
+ use Psr\Http\Message\ResponseFactoryInterface;
197
+ use Http\Discovery\Psr17FactoryDiscovery;
198
+
199
+ class MyClass
200
+ {
201
+ /**
202
+ * @var RequestFactoryInterface
203
+ */
204
+ private $requestFactory;
205
+
206
+ /**
207
+ * @var ResponseFactoryInterface
208
+ */
209
+ private $responseFactory;
210
+
211
+ public function __construct(RequestFactoryInterface $requestFactory = null, ResponseFactoryInterface $responseFactory = null)
212
+ {
213
+ $this->requestFactory = $requestFactory ?: Psr17FactoryDiscovery::findRequestFactory();
214
+ $this->responseFactory = $responseFactory ?: Psr17FactoryDiscovery::findResponseFactory();
215
+ }
216
+ }
217
+
218
+ PSR-18 Client Discovery
219
+ -----------------------
220
+
221
+ This type of discovery finds a PSR-18 _ HTTP Client implementation::
222
+
223
+ use Psr\Http\Client\ClientInterface;
224
+ use Http\Discovery\Psr18ClientDiscovery;
225
+
226
+ class MyClass
227
+ {
228
+ /**
229
+ * @var ClientInterface
230
+ */
231
+ private $httpClient;
232
+
233
+ public function __construct(ClientInterface $httpClient = null)
234
+ {
235
+ $this->httpClient = $httpClient ?: Psr18ClientDiscovery::find();
236
+ }
237
+ }
238
+
188
239
PSR-7 Message Factory Discovery
189
240
-------------------------------
190
241
242
+ .. versionadded :: 1.6
243
+ This is deprecated and will be removed in 2.0. Consider using PSR-17 Factory Discovery.
244
+
191
245
This type of discovery finds a :ref: `message-factory ` for a PSR-7 _ Message
192
246
implementation::
193
247
@@ -199,7 +253,7 @@ implementation::
199
253
/**
200
254
* @var MessageFactory
201
255
*/
202
- protected $messageFactory;
256
+ private $messageFactory;
203
257
204
258
/**
205
259
* @param MessageFactory|null $messageFactory to create PSR-7 requests.
@@ -213,6 +267,9 @@ implementation::
213
267
PSR-7 URI Factory Discovery
214
268
---------------------------
215
269
270
+ .. versionadded :: 1.6
271
+ This is deprecated and will be removed in 2.0. Consider using PSR-17 Factory Discovery.
272
+
216
273
This type of discovery finds a URI factory for a PSR-7 _ URI implementation::
217
274
218
275
use Http\Message\UriFactory;
@@ -223,7 +280,7 @@ This type of discovery finds a URI factory for a PSR-7_ URI implementation::
223
280
/**
224
281
* @var UriFactory
225
282
*/
226
- protected $uriFactory;
283
+ private $uriFactory;
227
284
228
285
/**
229
286
* @param UriFactory|null $uriFactory to create UriInterface instances from strings.
@@ -301,3 +358,5 @@ Read more in Puli's documentation (`Providing Resources`_).
301
358
.. _`binding` : http://docs.puli.io/en/latest/glossary.html#glossary-binding
302
359
.. _`binding-type` : http://docs.puli.io/en/latest/glossary.html#glossary-binding-type
303
360
.. _Providing Resources : http://docs.puli.io/en/latest/discovery/providing-resources.html
361
+ .. _PSR-17 : http://www.php-fig.org/psr/psr-17
362
+ .. _PSR-18 : http://www.php-fig.org/psr/psr-18
0 commit comments