Skip to content

Commit edf08be

Browse files
committed
Added docs about PSR-17 and PSR-18
1 parent 70c64ec commit edf08be

File tree

1 file changed

+55
-4
lines changed

1 file changed

+55
-4
lines changed

discovery.rst

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Currently available discovery services:
1313
- PSR-7 Message Factory Discovery
1414
- PSR-7 URI Factory Discovery
1515
- PSR-7 Stream Factory Discovery
16+
- PSR-17 Factory Discovery
17+
- PSR-18 Client Discovery
1618
- Mock Client Discovery (not enabled by default)
1719

1820
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::
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.
@@ -199,7 +201,7 @@ implementation::
199201
/**
200202
* @var MessageFactory
201203
*/
202-
protected $messageFactory;
204+
private $messageFactory;
203205

204206
/**
205207
* @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::
223225
/**
224226
* @var UriFactory
225227
*/
226-
protected $uriFactory;
228+
private $uriFactory;
227229

228230
/**
229231
* @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::
233235
$this->uriFactory = $uriFactory ?: UriFactoryDiscovery::find();
234236
}
235237
}
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+
}
236287

237288
Mock Client Discovery
238289
---------------------------

0 commit comments

Comments
 (0)