Skip to content

Commit 7350b24

Browse files
committed
document seekable body plugin configuration and generally improved symfony plugin configuration documentation
1 parent c2d063b commit 7350b24

File tree

3 files changed

+49
-15
lines changed

3 files changed

+49
-15
lines changed

Diff for: integrations/symfony-bundle.rst

+31-13
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,12 @@ Usage
8888
$response = $this->container->get('httplug.client.acme')->sendRequest($request);
8989
9090
Autowiring
91-
----------
91+
``````````
9292

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

9798
However, if you configured several different clients and need to be sure that
9899
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:
103104
httplug:
104105
default_client_autowiring: false
105106
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:
108110

109111
.. code-block:: php
110112
113+
use Symfony\Component\DependencyInjection\Attribute as DI;
114+
111115
final class MyService
112116
{
113117
public function __construct(
114-
#[Target('acme')] HttpClient $client
118+
#[DI\Target('acme')] HttpClient $client
115119
) {}
116120
}
117121
@@ -255,6 +259,7 @@ services are:
255259
* ``httplug.factory.buzz``
256260
* ``httplug.factory.guzzle5``
257261
* ``httplug.factory.guzzle6``
262+
* ``httplug.factory.guzzle7``
258263
* ``httplug.factory.react``
259264
* ``httplug.factory.socket``
260265
* ``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
312317
a client. For some plugins this is the only place where they can be configured.
313318
The order in which you specify the plugins **does** matter.
314319

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+
315329
You can configure many of the plugins directly on the client:
316330

317331
.. code-block:: yaml
@@ -335,10 +349,6 @@ You can configure many of the plugins directly on the client:
335349
username: 'my_username'
336350
password: 'p4ssw0rd'
337351
338-
339-
See :doc:`full configuration </integrations/symfony-full-configuration>` for
340-
the full list of plugins you can configure.
341-
342352
Alternatively, the same configuration also works on a global level. With this,
343353
you can configure plugins once and then use them in several clients. The plugin
344354
service names follow the pattern ``httplug.plugin.<name>``:
@@ -364,6 +374,11 @@ service names follow the pattern ``httplug.plugin.<name>``:
364374
To configure HTTP caching, you need to require ``php-http/cache-plugin`` in
365375
your project. It is available as a separate composer package.
366376

377+
.. _symfony_custom_plugin:
378+
379+
Configure a Custom Plugin
380+
-------------------------
381+
367382
To use a custom plugin or when you need specific configuration that is not
368383
covered by the bundle configuration, you can configure the plugin as a normal
369384
Symfony service and then reference that service name in the plugin list of your
@@ -387,7 +402,7 @@ client:
387402
- 'acme_plugin'
388403
389404
Authentication
390-
``````````````
405+
--------------
391406

392407
You can configure a client with authentication. Valid authentication types are
393408
``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
415430
The auth params will appear on the URL and we recommend to NOT log your request, especially on production side.
416431

417432
VCR Plugin
418-
``````````
433+
----------
419434

420435
The :doc:`VCR Plugin </plugins/vcr>` allows to record and/or replay HTTP requests. You can configure the mode you want,
421436
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:
549564
If you do not specify the factory in your configuration, you can also directly
550565
overwrite the httplug services:
551566

567+
568+
.. code-block:: yaml
569+
552570
# config/services_test.yaml
553571
services:
554572
# overwrite the http clients for mocking

Diff for: integrations/symfony-full-configuration.rst

+16
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ Full configuration
33

44
This page shows an example of all configuration values provided by the bundle.
55

6+
.. hint::
7+
8+
See :doc:`the plugin documentation <../plugins/index>` for more information
9+
on the plugins.
10+
11+
If a plugin is not listed in the configuration reference below, you can
12+
configure it as a service and reference the plugin by service id as you
13+
would do for a :ref:`custom plugin <symfony_custom_plugin>`.
14+
615
.. code-block:: yaml
716
817
// config.yml
@@ -141,6 +150,13 @@ This page shows an example of all configuration values provided by the bundle.
141150
- query_defaults:
142151
parameters:
143152
locale: en
153+
# Plugins to ensure the request resp response body is seekable
154+
- request_seekable_body:
155+
use_file_buffer: true
156+
memory_buffer_size: 2097152
157+
- response_seekable_body:
158+
use_file_buffer: true
159+
memory_buffer_size: 2097152
144160
# Enable VCR plugin integration (Must be installed first).
145161
- vcr:
146162
mode: replay # record | replay | replay_or_record

Diff for: plugins/seekable-body-plugins.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Seekable Body Plugins
22
=====================
33

44
``RequestSeekableBodyPlugin`` and ``ResponseSeekableBodyPlugin`` ensure that body used in request and response is always seekable.
5-
This allows a lot of components, reading the stream, to rewind it in order to be used later by another component::
5+
Use this plugin if you want plugins to read the stream and then be able to rewind it::
66

77
use Http\Discovery\HttpClientDiscovery;
88
use Http\Client\Common\PluginClient;
@@ -26,5 +26,5 @@ Those plugins support the following options (which are passed to the ``BufferedS
2626
* ``use_file_buffer``: Whether it should use a temporary file to buffer the body of a stream if it's too big
2727
* ``memory_buffer_size``: Maximum memory to use for buffering the stream before it switch to a file
2828

29-
``RequestSeekableBodyPlugin`` should be added in top of your plugins, then next plugins can seek request body (i.e. for logging purpose).
29+
``RequestSeekableBodyPlugin`` should be the first of your plugins, then the following plugins can seek in the request body (i.e. for logging purpose).
3030
``ResponseSeekableBodyPlugin`` should be the last plugin, then previous plugins can seek response body.

0 commit comments

Comments
 (0)