Skip to content

Commit e814241

Browse files
Nyholmdbu
authored andcommitted
Be more friendly to third party users (#125)
Be more friendly to third party users
1 parent 9970840 commit e814241

File tree

2 files changed

+40
-13
lines changed

2 files changed

+40
-13
lines changed

httplug/users.rst

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,42 @@ If you use a library that depends on HTTPlug (say, ``some/awesome-library``),
55
you need to include an HTTPlug client in your project before you can include
66
``awesome-library``.
77

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.
1111

12-
.. code-block:: bash
13-
14-
$ composer require php-http/socket-client
12+
.. note::
1513

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>`.
1815

1916
.. code-block:: bash
2017
21-
$ composer require php-http/guzzle6-adapter
18+
$ composer require php-http/curl-client
2219
2320
Then you can include the library:
2421

2522
.. code-block:: bash
2623
2724
$ composer require some/awesome-library
2825
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+
2937
Troubleshooting
3038
---------------
3139

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
3344
HTTP client in your project, Composer will throw an error:
3445

3546
.. code-block:: none
@@ -44,13 +55,28 @@ HTTP client in your project, Composer will throw an error:
4455
4556
You can solve this by including a HTTP client or adapter, as described above.
4657

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+
4772
Background
4873
----------
4974

5075
Reusable libraries do not depend on a concrete implementation but only on the virtual package
5176
``php-http/client-implementation``. This is to avoid hard coupling and allows the user of the
5277
library to choose the implementation. You can think of this as an "interface" or "contract" for packages.
5378

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

spelling_word_list.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@ whitelist
3333
wiki
3434
Wikipedia
3535
workflow
36+
Zend

0 commit comments

Comments
 (0)