You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The usage documentation is split into two parts. First we explain how to configure the bundle in an application. The second part is for developing reusable Symfony bundles that depend on an HTTP client defined by the Httplug interface.
5
-
6
-
For information how to write applications with the services provided by this bundle, have a look at the [Httplug documentation](http://docs.php-http.org).
\* *These services are always an alias to another service. You can specify your own service or leave the default, which is the same name with `.default` appended. The default services in turn use the service discovery mechanism to provide the best available implementation. You can specify a class for each of the default services to use instead of discovery, as long as those classes can be instantiated without arguments.*
44
-
45
-
46
-
If you need a more custom setup, define the services in your application configuration and specify your service in the `main_alias` section. For example, to add authentication headers, you could define a service that decorates the service `httplug.client.default` with a plugin that injects the authentication headers into the request and configure `httplug.main_alias.client` to the name of your service.
4
+
This bundle integrate HTTPlug with the Symfony framework. The bundle helps to register services for all your clients and makes sure all the configuration is in one place. The bundle also feature a toolbar plugin with information about your requests.
5
+
6
+
7
+
Installation
8
+
````````````
9
+
10
+
Install the Httplug bundle with composer and enable it in your AppKernel.php.
11
+
12
+
.. code-block:: bash
13
+
14
+
$ composer require php-http/httplug-bundle
15
+
16
+
.. code-block:: php
17
+
18
+
public function registerBundles()
19
+
{
20
+
$bundles = array(
21
+
// ...
22
+
new Http\HttplugBundle\HttplugBundle(),
23
+
);
24
+
}
25
+
26
+
You will find all available configuration at the :doc:`full configuration </integrations/symfony-full-configuration>` page.
By default we use Puli to auto discover factories. If you do not want to use auto discovery you could use the following configuration (Guzzle):
50
+
Web Debug Toolbar
51
+
`````````````````
52
+
.. image:: /assets/img/debug-toolbar.png
53
+
:align:right
54
+
:width:120px
55
+
56
+
When using a client configured with HttplugBundle, you will get debug information in the web debug toolbar. It will tell you how many request were made and how many of those that were successful or not. It will also show you detailed information about each request.
57
+
58
+
Discovery of Factory Classes
59
+
````````````````````````````
60
+
61
+
If you want the bundle to automatically find usable factory classes, install and enable ``puli/symfony-bundle``. If you do not want use auto discovery, you need to specify all the factory classes for you client. The following example show how you configure factory classes using Guzzle:
72
62
73
63
.. code-block:: yaml
74
64
@@ -80,10 +70,11 @@ By default we use Puli to auto discover factories. If you do not want to use aut
You can configure your clients with some good default options. The clients are later registered as services.
74
+
Configure Clients
75
+
`````````````````
76
+
77
+
You can configure your clients with default options. These default values will be specific to you client you are using. The clients are later registered as services.
87
78
88
79
.. code-block:: yaml
89
80
@@ -100,77 +91,110 @@ You can configure your clients with some good default options. The clients are l
The bundle has client factory services that you can use to build your client. If you need a very custom made client you could create your own factory service implementing ``Http\HttplugBudle\ClientFactory\ClientFactory``. The build in services are:
107
+
108
+
* ``httplug.factory.curl``
109
+
* ``httplug.factory.guzzle5``
110
+
* ``httplug.factory.guzzle6``
111
+
* ``httplug.factory.react``
112
+
* ``httplug.factory.socket``
112
113
113
114
Plugins
114
115
```````
115
116
116
-
You can configure the clients with plugins.
117
+
You can configure the clients with plugins. You can choose to use a built in plugin in the ``php-http/plugins`` package or provide a plugin of your own. The order of the specified plugin does matter.
You can configure a client with authentication. Valid authentication types are ``basic``, ``bearer``, ``service`` and ``wsse``. See more examples at the :doc:`full configuration </integrations/symfony-full-configuration>`.
Rather than code against specific HTTP clients, you want to use the Httplug `Client` interface. To avoid building your own infrastructure to define services for the client, simply `require: php-http/httplug-bundle` in your bundles `composer.json`. You SHOULD provide configuration for each of your services that needs an HTTP client to specify the service to use, defaulting to `httplug.client`. This way, the default case needs no additional configuration for your users.
175
-
176
-
The only steps they need is `require` one of the adapter implementations in their projects `composer.json` and instantiating the HttplugBundle in their kernel.
\* *These services are always an alias to another service. You can specify your own service or leave the default, which is the same name with `.default` appended.*
193
+
194
+
195
+
Useage for Reusable Bundles
196
+
``````````````````````````
197
+
198
+
Rather than code against specific HTTP clients, you want to use the Httplug ``Client`` interface. To avoid building your own infrastructure to define services for the client, simply ``require: php-http/httplug-bundle`` in your bundles ``composer.json``. You SHOULD provide a configuration option to specify the which HTTP client service to use for each of your services. This option should default to ``httplug.client``. This way, the default case needs no additional configuration for your users, but they have the option of using specific clients with each of your services.
199
+
200
+
The only steps they need is ``require`` one of the adapter implementations in their projects ``composer.json`` and instantiating the HttplugBundle in their kernel.
0 commit comments