Skip to content

Commit 9abf1f2

Browse files
authored
Merge pull request #316 from glaubinix/psr17-client-interface
Update Symfony integration docs to match PSR-17/PSR-18 changes in 2.x of the bundle
2 parents b1f61a3 + 39e99e1 commit 9abf1f2

File tree

2 files changed

+32
-26
lines changed

2 files changed

+32
-26
lines changed

integrations/symfony-bundle.rst

+24-20
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,15 @@ Usage
8484
8585
.. code-block:: php
8686
87-
$request = $this->container->get('httplug.message_factory')->createRequest('GET', 'http://example.com');
87+
$request = $this->container->get('httplug.psr17_request_factory')->createRequest('GET', 'http://example.com');
8888
$response = $this->container->get('httplug.client.acme')->sendRequest($request);
8989
9090
Autowiring
9191
``````````
9292

9393
The first configured client is considered the "default" client. The default
9494
clients are available for `autowiring`_: The PSR-18 ``Psr\Http\Client\ClientInterface``
95-
(or the deprecated ``Http\Client\HttpClient``) and the ``Http\Client\HttpAsyncClient``.
95+
and the ``Http\Client\HttpAsyncClient``.
9696
Autowiring can be convenient to build your application.
9797

9898
However, if you configured several different clients and need to be sure that
@@ -110,12 +110,13 @@ When using this bundle with Symfony 5.3 or newer, you can use the Symfony
110110

111111
.. code-block:: php
112112
113+
use Psr\Http\Client\ClientInterface;
113114
use Symfony\Component\DependencyInjection\Attribute as DI;
114115
115116
final class MyService
116117
{
117118
public function __construct(
118-
#[DI\Target('acme')] HttpClient $client
119+
#[DI\Target('acme')] ClientInterface $client
119120
) {}
120121
}
121122
@@ -175,8 +176,8 @@ also disable the profiling by configuration.
175176
You can configure the bundle to show debug information for clients found with
176177
discovery. You may also force a specific client to be found when a third party
177178
library is using discovery. The configuration below makes sure the client with
178-
service id ``httplug.client.my_guzzle5`` is returned when calling
179-
``HttpClientDiscovery::find()`` . It does also make sure to show debug info for
179+
service id ``httplug.client.my_guzzle7`` is returned when calling
180+
``Psr18ClientDiscovery::find()`` . It does also make sure to show debug info for
180181
asynchronous clients.
181182

182183
.. note::
@@ -187,10 +188,10 @@ asynchronous clients.
187188
188189
httplug:
189190
clients:
190-
my_guzzle5:
191-
factory: 'httplug.factory.guzzle5'
191+
my_guzzle7:
192+
factory: 'httplug.factory.guzzle7'
192193
discovery:
193-
client: 'httplug.client.my_guzzle5'
194+
client: 'httplug.client.my_guzzle7'
194195
async_client: 'auto'
195196
196197
For normal clients, the auto discovery debug info is enabled by default. For
@@ -211,10 +212,11 @@ example shows how you configure factory classes using Guzzle:
211212
212213
httplug:
213214
classes:
214-
client: Http\Adapter\Guzzle6\Client
215-
message_factory: Http\Message\MessageFactory\GuzzleMessageFactory
216-
uri_factory: Http\Message\UriFactory\GuzzleUriFactory
217-
stream_factory: Http\Message\StreamFactory\GuzzleStreamFactory
215+
client: Http\Adapter\Guzzle7\Client
216+
psr17_request_factory: GuzzleHttp\Psr7\HttpFactory
217+
psr17_response_factory: GuzzleHttp\Psr7\HttpFactory
218+
psr17_uri_factory: GuzzleHttp\Psr7\HttpFactory
219+
psr17_stream_factory: GuzzleHttp\Psr7\HttpFactory
218220
219221
Configure Clients
220222
`````````````````
@@ -227,8 +229,8 @@ services.
227229
228230
httplug:
229231
clients:
230-
my_guzzle5:
231-
factory: 'httplug.factory.guzzle5'
232+
my_guzzle7:
233+
factory: 'httplug.factory.guzzle7'
232234
config:
233235
# These options are given to Guzzle without validation.
234236
defaults:
@@ -244,10 +246,10 @@ services.
244246
245247
.. code-block:: php
246248
247-
$httpClient = $this->container->get('httplug.client.my_guzzle5');
249+
$httpClient = $this->container->get('httplug.client.my_guzzle7');
248250
$httpClient = $this->container->get('httplug.client.acme');
249251
250-
// will be the same as ``httplug.client.my_guzzle5``
252+
// will be the same as ``httplug.client.my_guzzle7``
251253
$httpClient = $this->container->get('httplug.client');
252254
253255
The bundle has client factory services that you can use to build your client.
@@ -257,11 +259,11 @@ services are:
257259

258260
* ``httplug.factory.curl``
259261
* ``httplug.factory.buzz``
260-
* ``httplug.factory.guzzle5``
261262
* ``httplug.factory.guzzle6``
262263
* ``httplug.factory.guzzle7``
263264
* ``httplug.factory.react``
264265
* ``httplug.factory.socket``
266+
* ``httplug.factory.symfony``
265267
* ``httplug.factory.mock`` (Install ``php-http/mock-client`` first)
266268

267269
.. note::
@@ -479,11 +481,13 @@ List of Services
479481
+-------------------------------------+-------------------------------------------------------------------------+
480482
| Service id | Description |
481483
+=====================================+=========================================================================+
482-
| ``httplug.message_factory`` | Service* that provides the `Http\Message\MessageFactory` |
484+
| ``httplug.psr17_request_factory`` | Service* that provides the `Psr\Http\Message\RequestFactoryInterface` |
483485
+-------------------------------------+-------------------------------------------------------------------------+
484-
| ``httplug.uri_factory`` | Service* that provides the `Http\Message\UriFactory` |
486+
| ``httplug.psr17_response_factory`` | Service* that provides the `Psr\Http\Message\ResponseFactoryInterface` |
485487
+-------------------------------------+-------------------------------------------------------------------------+
486-
| ``httplug.stream_factory`` | Service* that provides the `Http\Message\StreamFactory` |
488+
| ``httplug.psr17_uri_factory`` | Service* that provides the `Psr\Http\Message\UriFactoryInterface` |
489+
+-------------------------------------+-------------------------------------------------------------------------+
490+
| ``httplug.psr17_stream_factory`` | Service* that provides the `Psr\Http\Message\StreamFactoryInterface` |
487491
+-------------------------------------+-------------------------------------------------------------------------+
488492
| ``httplug.client.[name]`` | There is one service per named client. |
489493
+-------------------------------------+-------------------------------------------------------------------------+

integrations/symfony-full-configuration.rst

+8-6
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,17 @@ This page shows an example of all configuration values provided by the bundle.
2222
# this does NOT change autowiring, which will always go to the "default" client
2323
main_alias:
2424
client: httplug.client.default
25-
message_factory: httplug.message_factory.default
26-
uri_factory: httplug.uri_factory.default
27-
stream_factory: httplug.stream_factory.default
25+
psr17_request_factory: httplug.psr17_request_factory.default
26+
psr17_response_factory: httplug.psr17_response_factory.default
27+
psr17_uri_factory: httplug.psr17_uri_factory.default
28+
psr17_stream_factory: httplug.psr17_stream_factory.default
2829
classes:
2930
# uses discovery if not specified
3031
client: ~
31-
message_factory: ~
32-
uri_factory: ~
33-
stream_factory: ~
32+
psr17_request_factory: ~
33+
psr17_response_factory: ~
34+
psr17_uri_factory: ~
35+
psr17_stream_factory: ~
3436
3537
plugins: # Global plugin configuration. When configured here, plugins need to be explicitly added to clients by service name.
3638
authentication:

0 commit comments

Comments
 (0)