@@ -5,7 +5,7 @@ If you’re developing a library or framework that performs HTTP requests, you
5
5
should not be dependent on concrete HTTP client libraries (such as Guzzle).
6
6
Instead, you should only make sure that *some * HTTP client is available. It is
7
7
then up to your users to decide which HTTP client they want to include in their
8
- projects.
8
+ projects. This complies with the ` dependency inversion principle `_.
9
9
10
10
Manage dependencies
11
11
-------------------
@@ -38,14 +38,12 @@ to include the Socket client:
38
38
}
39
39
}
40
40
41
- Standalone installation
42
- -----------------------
41
+ Testing you library
42
+ -------------------
43
43
44
- This is sufficient for your library’s users. For the library’s developers,
45
- however, it’s best if some specific client is installed when they run
46
- ``composer install `` in the library’s directory. So specify any concrete client
47
- in the ``require-dev `` section in your library’s ``composer.json ``. In this
48
- example, we chose the Guzzle 6 adapter:
44
+ When you install your library on a CI-server (like Travis) you need to include a client. So specify any concrete client
45
+ in the ``require-dev `` section in your library’s ``composer.json ``. You could use any client but the
46
+ :doc: `/clients/mock-client ` will make it easier to write good tests.
49
47
50
48
.. code-block :: json
51
49
@@ -55,19 +53,23 @@ example, we chose the Guzzle 6 adapter:
55
53
"php-http/client-implementation" : " ^1.0"
56
54
},
57
55
"require-dev" : {
58
- "php-http/guzzle6-adapter " : " ^1.0 "
56
+ "php-http/mock-client " : " ^0.3 "
59
57
}
60
58
}
61
59
62
- For extra convenience, you can use :doc: `/discovery ` to free your users from
63
- having to instantiate the client.
60
+
64
61
65
62
Messages
66
63
--------
67
64
68
- When you construct HTTP message objects in your library, you should not depend
69
- on a concrete PSR-7 message implementation. Instead, use the
70
- :ref: `PHP-HTTP message factory <message-factory >`.
65
+ When you construct HTTP message objects in your library, you should not depend on a concrete PSR-7 message
66
+ implementation. Instead, use the :ref: `PHP-HTTP message factory <message-factory >`.
67
+
68
+ Discovery
69
+ ---------
70
+
71
+ To make it as convenient as possible for your users you should use the :doc: `/discovery ` component. It will help you
72
+ find factories to create ``Request ``, ``Streams `` etc. That component is light weight and has no hard dependencies.
71
73
72
74
Plugins
73
75
-------
@@ -81,3 +83,29 @@ User documentation
81
83
82
84
To explain to your users that they need to install a concrete HTTP client,
83
85
you can point them to :doc: `users `.
86
+
87
+
88
+ You final ``composer.json ``
89
+ ---------------------------
90
+
91
+ Putting it all together your final ``composer.json `` is much likely to look similar to this:
92
+
93
+ .. code-block :: json
94
+
95
+ {
96
+ "name" : " you/and-your-awesome-library" ,
97
+ "require" : {
98
+ "psr/http-message" : " ^1.0" ,
99
+ "php-http/client-implementation" : " ^1.0" ,
100
+ "php-http/httplug" : " ^1.0" ,
101
+ "php-http/message-factory" : " ^1.0" ,
102
+ "php-http/discovery" : " ^1.0"
103
+ },
104
+ "require-dev" : {
105
+ "php-http/mock-client" : " ^0.3" ,
106
+ "php-http/message" : " ^1.0" ,
107
+ "guzzlehttp/psr7" : " ^1.0"
108
+ }
109
+ }
110
+
111
+ .. _`dependency inversion principle` : https://en.wikipedia.org/wiki/Dependency_inversion_principle
0 commit comments