diff --git a/clients.rst b/clients.rst index 1f49f2e..8409555 100644 --- a/clients.rst +++ b/clients.rst @@ -22,6 +22,7 @@ interface and forwarding the calls to an HTTP client not implementing the interf clients/cakephp-adapter clients/guzzle5-adapter clients/guzzle6-adapter + clients/guzzle7-adapter clients/react-adapter clients/zend-adapter @@ -38,6 +39,7 @@ interface and forwarding the calls to an HTTP client not implementing the interf "``php-http/cakephp-adapter``", "Adapter", ":doc:`Docs `, `Repo `__", "|cakephp_version| |cakephp_downloads| " "``php-http/guzzle5-adapter``", "Adapter", ":doc:`Docs `, `Repo `__", "|guzzle5_version| |guzzle5_downloads| " "``php-http/guzzle6-adapter``", "Adapter", ":doc:`Docs `, `Repo `__", "|guzzle6_version| |guzzle6_downloads| " + "``php-http/guzzle7-adapter``", "Adapter", ":doc:`Docs `, `Repo `__", "|guzzle7_version| |guzzle7_downloads| " "``php-http/react-adapter``", "Adapter", ":doc:`Docs `, `Repo `__", "|react_version| |react_downloads| " "``php-http/zend-adapter``", "Adapter", ":doc:`Docs `, `Repo `__", "|zend_version| |zend_downloads| " @@ -120,6 +122,13 @@ HTTPlug use the ``provide`` section to tell composer that they do provide the cl :target: https://github.com/php-http/guzzle6-adapter/releases :alt: Latest Version +.. |guzzle7_downloads| image:: https://img.shields.io/packagist/dt/php-http/guzzle7-adapter.svg?style=flat-square + :target: https://packagist.org/packages/php-http/guzzle7-adapter + :alt: Total Downloads +.. |guzzle7_version| image:: https://img.shields.io/github/release/php-http/guzzle7-adapter.svg?style=flat-square + :target: https://github.com/php-http/guzzle7-adapter/releases + :alt: Latest Version + .. |react_downloads| image:: https://img.shields.io/packagist/dt/php-http/react-adapter.svg?style=flat-square :target: https://packagist.org/packages/php-http/react-adapter :alt: Total Downloads diff --git a/clients/guzzle6-adapter.rst b/clients/guzzle6-adapter.rst index 0d5a3bc..7688599 100644 --- a/clients/guzzle6-adapter.rst +++ b/clients/guzzle6-adapter.rst @@ -41,7 +41,7 @@ to the client:: $guzzle = new GuzzleClient($config); // ... $adapter = new GuzzleAdapter($guzzle); - + If you pass a Guzzle instance to the adapter, make sure to configure Guzzle to not throw exceptions on HTTP error status codes, or this adapter will violate PSR-18. And use it to send synchronous requests:: @@ -65,4 +65,4 @@ Or send asynchronous ones:: .. include:: includes/further-reading-async.inc -.. _Guzzle 6 HTTP client: http://docs.guzzlephp.org/ +.. _Guzzle 6 HTTP client: http://docs.guzzlephp.org/en/6.5/ diff --git a/clients/guzzle7-adapter.rst b/clients/guzzle7-adapter.rst new file mode 100644 index 0000000..dfa7f79 --- /dev/null +++ b/clients/guzzle7-adapter.rst @@ -0,0 +1,70 @@ +Guzzle 7 Adapter +================ + +An HTTPlug adapter for the `Guzzle 7 HTTP client`_. Guzzle 7 supports PSR-18 +out of the box. This adapter makes sense if you want to use HTTPlug async interface or to use +Guzzle 7 with a library that did not upgrade to PSR-18 yet and depends on ``php-http/client-implementation``. + +Installation +------------ + +To install the Guzzle adapter, which will also install Guzzle itself (if it was +not yet included in your project), run: + +.. code-block:: bash + + $ composer require php-http/guzzle7-adapter + +Usage +----- + +To create a Guzzle7 adapter you should use the `createWithConfig()` function. It will let you to pass Guzzle configuration +to the client:: + + use Http\Adapter\Guzzle7\Client as GuzzleAdapter; + + $config = [ + 'timeout' => 2, + 'handler' => //... + // ... + ]; + $adapter = GuzzleAdapter::createWithConfig($config); + +.. note:: + + If you want even more control over your Guzzle object, you may give a Guzzle client as first argument to the adapter's + constructor:: + + use GuzzleHttp\Client as GuzzleClient; + use Http\Adapter\Guzzle7\Client as GuzzleAdapter; + + $config = ['timeout' => 5]; + // ... + $guzzle = new GuzzleClient($config); + // ... + $adapter = new GuzzleAdapter($guzzle); + + If you pass a Guzzle instance to the adapter, make sure to configure Guzzle to not throw exceptions on HTTP error status codes, or this adapter will violate PSR-18. + +And use it to send synchronous requests:: + + use GuzzleHttp\Psr7\Request; + + $request = new Request('GET', 'http://httpbin.org'); + + // Returns a Psr\Http\Message\ResponseInterface + $response = $adapter->sendRequest($request); + +Or send asynchronous ones:: + + use GuzzleHttp\Psr7\Request; + + $request = new Request('GET', 'http://httpbin.org'); + + // Returns a Http\Promise\Promise + $promise = $adapter->sendAsyncRequest(request); + + +.. include:: includes/further-reading-async.inc + +.. _Guzzle 7 HTTP client: http://docs.guzzlephp.org/en/7.0/