Skip to content

Commit 807bc97

Browse files
committed
further clarify the third party user documentation
1 parent e814241 commit 807bc97

File tree

1 file changed

+36
-21
lines changed

1 file changed

+36
-21
lines changed

httplug/users.rst

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,44 @@
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 php-http/discovery
15+
16+
Background
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.
23+
24+
The client-implementation is provided by all HTTPlug compliant clients and
25+
adapters. Read about the clients and adapters provided by the PHP-HTTP
26+
organization at :doc:`this page </clients>`.
1927

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

2232
.. code-block:: bash
2333
24-
$ composer require some/awesome-library
34+
$ composer require php-http/curl-client some/awesome-library
2535
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:
36+
You can pick any of the clients or adapters :doc:`provided by PHP-HTTP </clients>`.
37+
Popular choices are ``php-http/curl-client`` and ``php-http/guzzle6-adapter``.
38+
39+
Many libraries also need a PSR-7 implementation and the PHP-HTTP message
40+
factories to create messages. The PSR-7 implementations are Zend's Diactoros
41+
and Guzzle's PSR-7. Do one of the following:
2842

2943
.. code-block:: bash
3044
@@ -58,16 +72,17 @@ You can solve this by including a HTTP client or adapter, as described above.
5872
No message factories
5973
`````````````````````
6074

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.
75+
You may get an exception telling you that "No message factories found", this
76+
means that either you have not installed a PSR-7 implementation or that there
77+
are no factories installed to create HTTP messages.
6378

6479
.. code-block:: none
6580
66-
No message factories found. To use Guzzle or Diactoros factories install php-http/message and
67-
the chosen message implementation.
68-
81+
No message factories found. To use Guzzle or Diactoros factories install
82+
php-http/message and the chosen message implementation.
6983
70-
You can solve this by including ``php-http/message`` and ``zendframework/zend-diactoros``, as described above.
84+
You can solve this by including ``php-http/message`` and Zend Diactoros or
85+
Guzzle PSR-7, as described above.
7186

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

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

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

0 commit comments

Comments
 (0)