Skip to content

Added docs about PSR-17 and PSR-18 #249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 23, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 66 additions & 7 deletions discovery.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ Currently available discovery services:

- HTTP Client Discovery
- HTTP Async Client Discovery
- PSR-7 Message Factory Discovery
- PSR-7 URI Factory Discovery
- PSR-7 Stream Factory Discovery
- PSR-17 Factory Discovery
- PSR-18 HTTP Client Discovery
- Mock Client Discovery (not enabled by default)
- PSR-7 Message Factory Discovery (deprecated)
- PSR-7 URI Factory Discovery (deprecated)
- PSR-7 Stream Factory Discovery (deprecated)

The principle is always the same: you call the static ``find`` method on the discovery service if no explicit
implementation was specified. The discovery service will try to locate a suitable implementation.
Expand Down Expand Up @@ -150,7 +152,7 @@ This type of discovery finds an HTTP Client implementation::
/**
* @var HttpClient
*/
protected $httpClient;
private $httpClient;

/**
* @param HttpClient|null $httpClient Client to do HTTP requests, if not set, auto discovery will be used to find a HTTP client.
Expand All @@ -174,7 +176,7 @@ This type of discovery finds a HTTP asynchronous Client implementation::
/**
* @var HttpAsyncClient
*/
protected $httpAsyncClient;
private $httpAsyncClient;

/**
* @param HttpAsyncClient|null $httpAsyncClient Client to do HTTP requests, if not set, auto discovery will be used to find an asynchronous client.
Expand All @@ -185,9 +187,61 @@ This type of discovery finds a HTTP asynchronous Client implementation::
}
}

PSR-17 Factory Discovery
------------------------

This type of discovery finds a factory for a PSR-17_ implementation::

use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\ResponseFactoryInterface;
use Http\Discovery\Psr17FactoryDiscovery;

class MyClass
{
/**
* @var RequestFactoryInterface
*/
private $requestFactory;

/**
* @var ResponseFactoryInterface
*/
private $responseFactory;

public function __construct(RequestFactoryInterface $requestFactory = null, ResponseFactoryInterface $responseFactory = null)
{
$this->requestFactory = $requestFactory ?: Psr17FactoryDiscovery::findRequestFactory();
$this->responseFactory = $responseFactory ?: Psr17FactoryDiscovery::findResponseFactory();
}
}

PSR-18 Client Discovery
-----------------------

This type of discovery finds a PSR-18_ HTTP Client implementation::

use Psr\Http\Client\ClientInterface;
use Http\Discovery\Psr18ClientDiscovery;

class MyClass
{
/**
* @var ClientInterface
*/
private $httpClient;

public function __construct(ClientInterface $httpClient = null)
{
$this->httpClient = $httpClient ?: Psr18ClientDiscovery::find();
}
}

PSR-7 Message Factory Discovery
-------------------------------

.. versionadded:: 1.6
This is deprecated and will be removed in 2.0. Consider using PSR-17 Factory Discovery.

This type of discovery finds a :ref:`message-factory` for a PSR-7_ Message
implementation::

Expand All @@ -199,7 +253,7 @@ implementation::
/**
* @var MessageFactory
*/
protected $messageFactory;
private $messageFactory;

/**
* @param MessageFactory|null $messageFactory to create PSR-7 requests.
Expand All @@ -213,6 +267,9 @@ implementation::
PSR-7 URI Factory Discovery
---------------------------

.. versionadded:: 1.6
This is deprecated and will be removed in 2.0. Consider using PSR-17 Factory Discovery.

This type of discovery finds a URI factory for a PSR-7_ URI implementation::

use Http\Message\UriFactory;
Expand All @@ -223,7 +280,7 @@ This type of discovery finds a URI factory for a PSR-7_ URI implementation::
/**
* @var UriFactory
*/
protected $uriFactory;
private $uriFactory;

/**
* @param UriFactory|null $uriFactory to create UriInterface instances from strings.
Expand Down Expand Up @@ -301,3 +358,5 @@ Read more in Puli's documentation (`Providing Resources`_).
.. _`binding`: http://docs.puli.io/en/latest/glossary.html#glossary-binding
.. _`binding-type`: http://docs.puli.io/en/latest/glossary.html#glossary-binding-type
.. _Providing Resources: http://docs.puli.io/en/latest/discovery/providing-resources.html
.. _PSR-17: http://www.php-fig.org/psr/psr-17
.. _PSR-18: http://www.php-fig.org/psr/psr-18