@@ -88,11 +88,12 @@ Usage
88
88
$response = $this->container->get('httplug.client.acme')->sendRequest($request);
89
89
90
90
Autowiring
91
- ----------
91
+ ``````````
92
92
93
- The first configured client is considered the "default" client. It is available
94
- for `autowiring `_ both for ``HttpClient `` and ``HttpAsyncClient ``. This can be
95
- convenient to build your application.
93
+ The first configured client is considered the "default" client. The default
94
+ clients are available for `autowiring `_: The PSR-18 ``Psr\Http\Client\ClientInterface ``
95
+ (or the deprecated ``Http\Client\HttpClient ``) and the ``Http\Client\HttpAsyncClient ``.
96
+ Autowiring can be convenient to build your application.
96
97
97
98
However, if you configured several different clients and need to be sure that
98
99
the correct client is used in each service, it can also hide mistakes.
@@ -103,15 +104,18 @@ Therefore you can disable autowiring with a configuration option:
103
104
httplug :
104
105
default_client_autowiring : false
105
106
106
- When using this bundle with Symfony 5.3 or newer, you can use the `#[Target] ` attribute to select a
107
- client by name:
107
+ When using this bundle with Symfony 5.3 or newer, you can use the Symfony
108
+ `#[Target] ` attribute to select a client by name. For a client configured as
109
+ ``httplug.clients.acme ``, this would be:
108
110
109
111
.. code-block :: php
110
112
113
+ use Symfony\Component\DependencyInjection\Attribute as DI;
114
+
111
115
final class MyService
112
116
{
113
117
public function __construct(
114
- #[Target('acme')] HttpClient $client
118
+ #[DI\ Target('acme')] HttpClient $client
115
119
) {}
116
120
}
117
121
@@ -255,6 +259,7 @@ services are:
255
259
* ``httplug.factory.buzz ``
256
260
* ``httplug.factory.guzzle5 ``
257
261
* ``httplug.factory.guzzle6 ``
262
+ * ``httplug.factory.guzzle7 ``
258
263
* ``httplug.factory.react ``
259
264
* ``httplug.factory.socket ``
260
265
* ``httplug.factory.mock `` (Install ``php-http/mock-client `` first)
@@ -312,6 +317,15 @@ Additionally you can configure any of the ``php-http/plugins`` specifically on
312
317
a client. For some plugins this is the only place where they can be configured.
313
318
The order in which you specify the plugins **does ** matter.
314
319
320
+ See :doc: `the plugin documentation <../plugins/index >` for more information on
321
+ the plugins.
322
+
323
+ See :doc: `full configuration </integrations/symfony-full-configuration >` for
324
+ the full list of plugins you can configure through this bundle. If a plugin is
325
+ not available in the configuration, you can configure it as a service and
326
+ reference the plugin by service id as you would do for a
327
+ :ref: `custom plugin <symfony_custom_plugin >`.
328
+
315
329
You can configure many of the plugins directly on the client:
316
330
317
331
.. code-block :: yaml
@@ -335,10 +349,6 @@ You can configure many of the plugins directly on the client:
335
349
username : ' my_username'
336
350
password : ' p4ssw0rd'
337
351
338
-
339
- See :doc: `full configuration </integrations/symfony-full-configuration >` for
340
- the full list of plugins you can configure.
341
-
342
352
Alternatively, the same configuration also works on a global level. With this,
343
353
you can configure plugins once and then use them in several clients. The plugin
344
354
service names follow the pattern ``httplug.plugin.<name> ``:
@@ -364,6 +374,11 @@ service names follow the pattern ``httplug.plugin.<name>``:
364
374
To configure HTTP caching, you need to require ``php-http/cache-plugin `` in
365
375
your project. It is available as a separate composer package.
366
376
377
+ .. _symfony_custom_plugin :
378
+
379
+ Configure a Custom Plugin
380
+ -------------------------
381
+
367
382
To use a custom plugin or when you need specific configuration that is not
368
383
covered by the bundle configuration, you can configure the plugin as a normal
369
384
Symfony service and then reference that service name in the plugin list of your
@@ -387,7 +402,7 @@ client:
387
402
- ' acme_plugin'
388
403
389
404
Authentication
390
- ``````````````
405
+ --------------
391
406
392
407
You can configure a client with authentication. Valid authentication types are
393
408
``basic ``, ``bearer ``, ``service ``, ``wsse `` and ``query_param ``. See more examples at the
@@ -415,7 +430,7 @@ You can configure a client with authentication. Valid authentication types are
415
430
The auth params will appear on the URL and we recommend to NOT log your request, especially on production side.
416
431
417
432
VCR Plugin
418
- ``````````
433
+ ----------
419
434
420
435
The :doc: `VCR Plugin </plugins/vcr >` allows to record and/or replay HTTP requests. You can configure the mode you want,
421
436
how to find recorded responses and how to match requests with responses. The mandatory options are:
@@ -549,6 +564,9 @@ To mock a response in your tests, do:
549
564
If you do not specify the factory in your configuration, you can also directly
550
565
overwrite the httplug services:
551
566
567
+
568
+ .. code-block :: yaml
569
+
552
570
# config/services_test.yaml
553
571
services :
554
572
# overwrite the http clients for mocking
0 commit comments