Skip to content

Commit cb6afc2

Browse files
authored
Merge pull request #249 from php-http/Nyholm-patch-1
Added docs about PSR-17 and PSR-18
2 parents 70c64ec + 9da775d commit cb6afc2

File tree

1 file changed

+66
-7
lines changed

1 file changed

+66
-7
lines changed

discovery.rst

Lines changed: 66 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ Currently available discovery services:
1010

1111
- HTTP Client Discovery
1212
- 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
1615
- 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)
1719

1820
The principle is always the same: you call the static ``find`` method on the discovery service if no explicit
1921
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::
150152
/**
151153
* @var HttpClient
152154
*/
153-
protected $httpClient;
155+
private $httpClient;
154156

155157
/**
156158
* @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::
174176
/**
175177
* @var HttpAsyncClient
176178
*/
177-
protected $httpAsyncClient;
179+
private $httpAsyncClient;
178180

179181
/**
180182
* @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::
185187
}
186188
}
187189

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+
188239
PSR-7 Message Factory Discovery
189240
-------------------------------
190241

242+
.. versionadded:: 1.6
243+
This is deprecated and will be removed in 2.0. Consider using PSR-17 Factory Discovery.
244+
191245
This type of discovery finds a :ref:`message-factory` for a PSR-7_ Message
192246
implementation::
193247

@@ -199,7 +253,7 @@ implementation::
199253
/**
200254
* @var MessageFactory
201255
*/
202-
protected $messageFactory;
256+
private $messageFactory;
203257

204258
/**
205259
* @param MessageFactory|null $messageFactory to create PSR-7 requests.
@@ -213,6 +267,9 @@ implementation::
213267
PSR-7 URI Factory Discovery
214268
---------------------------
215269

270+
.. versionadded:: 1.6
271+
This is deprecated and will be removed in 2.0. Consider using PSR-17 Factory Discovery.
272+
216273
This type of discovery finds a URI factory for a PSR-7_ URI implementation::
217274

218275
use Http\Message\UriFactory;
@@ -223,7 +280,7 @@ This type of discovery finds a URI factory for a PSR-7_ URI implementation::
223280
/**
224281
* @var UriFactory
225282
*/
226-
protected $uriFactory;
283+
private $uriFactory;
227284

228285
/**
229286
* @param UriFactory|null $uriFactory to create UriInterface instances from strings.
@@ -301,3 +358,5 @@ Read more in Puli's documentation (`Providing Resources`_).
301358
.. _`binding`: http://docs.puli.io/en/latest/glossary.html#glossary-binding
302359
.. _`binding-type`: http://docs.puli.io/en/latest/glossary.html#glossary-binding-type
303360
.. _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

Comments
 (0)