@@ -5,31 +5,42 @@ If you use a library that depends on HTTPlug (say, ``some/awesome-library``),
5
5
you need to include an HTTPlug client in your project before you can include
6
6
``awesome-library ``.
7
7
8
- From the list of :doc: ` clients < /clients >`, choose on that best fits your
9
- application, then include it in your project. For instance, if you decide to
10
- use the Socket client:
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.
11
11
12
- .. code-block :: bash
13
-
14
- $ composer require php-http/socket-client
12
+ .. note ::
15
13
16
- Instead of an HTTPlug client, you may want to use an adapter for your favorite
17
- HTTP client. If that turns out to be Guzzle:
14
+ Read about the clients and adapters provided by the PHP-HTTP organization at :doc: `this page </clients >`.
18
15
19
16
.. code-block :: bash
20
17
21
- $ composer require php-http/guzzle6-adapter
18
+ $ composer require php-http/curl-client
22
19
23
20
Then you can include the library:
24
21
25
22
.. code-block :: bash
26
23
27
24
$ composer require some/awesome-library
28
25
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:
28
+
29
+ .. code-block :: bash
30
+
31
+ $ composer require php-http/message zendframework/zend-diactoros
32
+
33
+ .. code-block :: bash
34
+
35
+ $ composer require php-http/message guzzlehttp/psr7
36
+
29
37
Troubleshooting
30
38
---------------
31
39
32
- If you try to include the HTTPlug-dependent library before you have included a
40
+ Composer fails
41
+ ``````````````
42
+
43
+ If you try to include the HTTPlug dependent library before you have included a
33
44
HTTP client in your project, Composer will throw an error:
34
45
35
46
.. code-block :: none
@@ -44,13 +55,28 @@ HTTP client in your project, Composer will throw an error:
44
55
45
56
You can solve this by including a HTTP client or adapter, as described above.
46
57
58
+ No message factories
59
+ `````````````````````
60
+
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.
63
+
64
+ .. code-block :: none
65
+
66
+ No message factories found. To use Guzzle or Diactoros factories install php-http/message and
67
+ the chosen message implementation.
68
+
69
+
70
+ You can solve this by including ``php-http/message `` and ``zendframework/zend-diactoros ``, as described above.
71
+
47
72
Background
48
73
----------
49
74
50
75
Reusable libraries do not depend on a concrete implementation but only on the virtual package
51
76
``php-http/client-implementation ``. This is to avoid hard coupling and allows the user of the
52
77
library to choose the implementation. You can think of this as an "interface" or "contract" for packages.
53
78
54
- When *using a reusable library * in an application, one must ``require `` a concrete implementation.
55
- Make sure the ``require `` section includes a package that provides ``php-http/client-implementation ``.
56
- Failing to do that will lead to composer reporting this error:
79
+ The reusable libraries have no hard coupling to the PSR-7 implementation either which gives you the flexibility to
80
+ choose an implementation yourself.
81
+
82
+ .. _`php-http/client-implementation` : https://packagist.org/providers/php-http/client-implementation
0 commit comments