1
1
HTTPlug for library users
2
2
=========================
3
3
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.
7
5
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
+ -----
11
8
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:
15
11
16
12
.. code-block :: bash
17
13
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.
19
23
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:
21
27
22
28
.. code-block :: bash
23
29
24
- $ composer require some/awesome-library
30
+ $ composer require php-http/curl-client some/awesome-library
25
31
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:
28
38
29
39
.. code-block :: bash
30
40
@@ -58,16 +68,17 @@ You can solve this by including a HTTP client or adapter, as described above.
58
68
No message factories
59
69
`````````````````````
60
70
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.
63
74
64
75
.. code-block :: none
65
76
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.
69
79
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.
71
82
72
83
Background
73
84
----------
@@ -76,7 +87,7 @@ Reusable libraries do not depend on a concrete implementation but only on the vi
76
87
``php-http/client-implementation ``. This is to avoid hard coupling and allows the user of the
77
88
library to choose the implementation. You can think of this as an "interface" or "contract" for packages.
78
89
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
80
91
choose an implementation yourself.
81
92
82
93
.. _`php-http/client-implementation` : https://packagist.org/providers/php-http/client-implementation
0 commit comments