Skip to content

Commit 8d1316c

Browse files
dbuNyholm
authored andcommitted
further clarify the third party user documentation (#137)
1 parent aff57d2 commit 8d1316c

File tree

1 file changed

+32
-21
lines changed

1 file changed

+32
-21
lines changed

httplug/users.rst

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,40 @@
11
HTTPlug for library users
22
=========================
33

4-
If you use a library that depends on HTTPlug (say, ``some/awesome-library``),
5-
you need to include an HTTPlug client in your project before you can include
6-
``awesome-library``.
4+
This page explains how to set up a library that depends on HTTPlug.
75

8-
First you need to choose library to send HTTP messages and that also provide the virtual package
9-
`php-http/client-implementation`_. In the example
10-
below we are using cURL.
6+
TL;DR
7+
-----
118

12-
.. note::
13-
14-
Read about the clients and adapters provided by the PHP-HTTP organization at :doc:`this page </clients>`.
9+
For the impatient: Require the following packages before requiring the library
10+
you plan to use:
1511

1612
.. code-block:: bash
1713
18-
$ composer require php-http/curl-client
14+
composer require php-http/curl-client guzzlehttp/psr7 php-http/message
15+
16+
Details
17+
-------
18+
19+
If a library depends on HTTPlug, it requires the virtual package
20+
`php-http/client-implementation`_. A virtual package is used to declare that
21+
the library needs *an* implementation of the HTTPlug interfaces, but does not
22+
care which implementation specifically.
1923

20-
Then you can include the library:
24+
When using such a library, you need to choose a HTTPlug client and include that
25+
in your project explicitly. Lets say you want to use ``some/awesome-library``
26+
that depends on ``php-http/client implementation``. In the example we are using cURL:
2127

2228
.. code-block:: bash
2329
24-
$ composer require some/awesome-library
30+
$ composer require php-http/curl-client some/awesome-library
2531
26-
Secondly you need to install a library that implements PSR-7 and a library containing message factories. The majority
27-
of users installs Zend's Diactoros or Guzzle's PSR-7. Do one of the following:
32+
You can pick any of the clients or adapters :doc:`provided by PHP-HTTP </clients>`.
33+
Popular choices are ``php-http/curl-client`` and ``php-http/guzzle6-adapter``.
34+
35+
Many libraries also need a PSR-7 implementation and the PHP-HTTP message
36+
factories to create messages. The PSR-7 implementations are Zend's Diactoros
37+
and Guzzle's PSR-7. Do one of the following:
2838

2939
.. code-block:: bash
3040
@@ -58,16 +68,17 @@ You can solve this by including a HTTP client or adapter, as described above.
5868
No message factories
5969
`````````````````````
6070

61-
You may get an exception telling you that "No message factories found", this means that either you have not installed a
62-
PSR-7 implementation or that there is no factories installed to create HTTP messages.
71+
You may get an exception telling you that "No message factories found", this
72+
means that either you have not installed a PSR-7 implementation or that there
73+
are no factories installed to create HTTP messages.
6374

6475
.. code-block:: none
6576
66-
No message factories found. To use Guzzle or Diactoros factories install php-http/message and
67-
the chosen message implementation.
68-
77+
No message factories found. To use Guzzle or Diactoros factories install
78+
php-http/message and the chosen message implementation.
6979
70-
You can solve this by including ``php-http/message`` and ``zendframework/zend-diactoros``, as described above.
80+
You can solve this by including ``php-http/message`` and Zend Diactoros or
81+
Guzzle PSR-7, as described above.
7182

7283
Background
7384
----------
@@ -76,7 +87,7 @@ Reusable libraries do not depend on a concrete implementation but only on the vi
7687
``php-http/client-implementation``. This is to avoid hard coupling and allows the user of the
7788
library to choose the implementation. You can think of this as an "interface" or "contract" for packages.
7889

79-
The reusable libraries have no hard coupling to the PSR-7 implementation either which gives you the flexibility to
90+
The reusable libraries have no hard coupling to the PSR-7 implementation either, which gives you the flexibility to
8091
choose an implementation yourself.
8192

8293
.. _`php-http/client-implementation`: https://packagist.org/providers/php-http/client-implementation

0 commit comments

Comments
 (0)