|
| 1 | +Buzz Adapter |
| 2 | +============ |
| 3 | + |
| 4 | +An HTTPlug adapter for the `Buzz HTTP client`_. |
| 5 | + |
| 6 | +Installation |
| 7 | +------------ |
| 8 | + |
| 9 | +To install the Buzz adapter, which will also install Buzz itself (if it was |
| 10 | +not yet included in your project), run: |
| 11 | + |
| 12 | +.. code-block:: bash |
| 13 | +
|
| 14 | + $ composer require php-http/buzz-adapter |
| 15 | +
|
| 16 | +.. include:: includes/install-message-factory.inc |
| 17 | + |
| 18 | +.. include:: includes/install-discovery.inc |
| 19 | + |
| 20 | +Usage |
| 21 | +----- |
| 22 | + |
| 23 | +Begin by creating a Buzz client, you may pass any listener or configuration parameters to it |
| 24 | +like:: |
| 25 | + |
| 26 | + use Buzz\Browser; |
| 27 | + use Buzz\Client\Curl; |
| 28 | + use Buzz\Listener\CookieListener; |
| 29 | + |
| 30 | + $browser = new Browser(); |
| 31 | + |
| 32 | + $client = new Curl(); |
| 33 | + $client->setMaxRedirects(0); |
| 34 | + $browser->setClient($client); |
| 35 | + |
| 36 | + // Create CookieListener |
| 37 | + $listener = new CookieListener(); |
| 38 | + $browser->addListener($listener); |
| 39 | + |
| 40 | +Then create the adapter:: |
| 41 | + |
| 42 | + use Http\Adapter\Buzz\Client as BuzzAdapter; |
| 43 | + use Http\Message\MessageFactory\GuzzleMessageFactory; |
| 44 | + |
| 45 | + $adapter = new BuzzAdapter($browser, new GuzzleMessageFactory()); |
| 46 | + |
| 47 | +Or if you installed the :doc:`discovery </discovery>` layer:: |
| 48 | + |
| 49 | + use Http\Adapter\Buzz\Client as BuzzAdapter; |
| 50 | + |
| 51 | + $adapter = new BuzzAdapter($browser); |
| 52 | + |
| 53 | +.. warning:: |
| 54 | + |
| 55 | + The message factory parameter is mandatory if the discovery layer is not installed. |
| 56 | + |
| 57 | +.. include:: includes/further-reading-sync.inc |
| 58 | + |
| 59 | +.. _Buzz HTTP client: https://github.com/kriswallsmith/Buzz |
0 commit comments