Skip to content

Commit 9f02d45

Browse files
committed
Move documentation to docs repo, fixes #24
1 parent be79e50 commit 9f02d45

File tree

1 file changed

+2
-146
lines changed

1 file changed

+2
-146
lines changed

README.md

+2-146
Original file line numberDiff line numberDiff line change
@@ -33,153 +33,9 @@ public function registerBundles()
3333
}
3434
```
3535

36-
## Usage
36+
## Documentation
3737

38-
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.
39-
40-
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).
41-
42-
43-
### Use in Applications
44-
45-
#### Custom services
46-
47-
| Service id | Description |
48-
| ---------- | ----------- |
49-
| httplug.message_factory | Service* that provides the `Http\Message\MessageFactory`
50-
| httplug.uri_factory | Service* that provides the `Http\Message\UriFactory`
51-
| httplug.stream_factory | Service* that provides the `Http\Message\StreamFactory`
52-
| httplug.client.[name] | This is your Httpclient that you have configured. With the configuration below the name would be `acme_client`.
53-
| httplug.client | This is the first client configured or a client named `default`.
54-
| httplug.plugin.content_length <br> httplug.plugin.decoder<br> httplug.plugin.error<br> httplug.plugin.logger<br> httplug.plugin.redirect<br> httplug.plugin.retry<br> httplug.plugin.stopwatch | These are plugins that are enabled by default. These services are not public and may only be used when configure HttpClients or other services.
55-
| httplug.plugin.cache<br> httplug.plugin.cookie<br> httplug.plugin.history | These are plugins that are disabled by default. They need to be configured before they can be used. These services are not public and may only be used when configure HttpClients or other services.
56-
57-
\* *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.*
58-
59-
60-
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.
61-
62-
```yaml
63-
httplug:
64-
clients:
65-
acme_client: # This is the name of the client
66-
factory: 'httplug.factory.guzzle6'
67-
68-
main_alias:
69-
client: httplug.client.default
70-
message_factory: httplug.message_factory.default
71-
uri_factory: httplug.uri_factory.default
72-
stream_factory: httplug.stream_factory.default
73-
classes:
74-
# uses discovery if not specified
75-
client: ~
76-
message_factory: ~
77-
uri_factory: ~
78-
stream_factory: ~
79-
```
80-
81-
#### Configuration without auto discovery
82-
83-
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):
84-
85-
```yaml
86-
httplug:
87-
classes:
88-
client: Http\Adapter\Guzzle6\Client
89-
message_factory: Http\Message\MessageFactory\GuzzleMessageFactory
90-
uri_factory: Http\Message\UriFactory\GuzzleUriFactory
91-
stream_factory: Http\Message\StreamFactory\GuzzleStreamFactory
92-
```
93-
94-
#### Configure your client
95-
96-
You can configure your clients with some good default options. The clients are later registered as services.
97-
98-
```yaml
99-
httplug:
100-
clients:
101-
my_guzzle5:
102-
factory: 'httplug.factory.guzzle5'
103-
config:
104-
# These options are given to Guzzle without validation.
105-
defaults:
106-
base_uri: 'http://google.se/'
107-
verify_ssl: false
108-
timeout: 4
109-
headers:
110-
Content-Type: 'application/json'
111-
acme:
112-
factory: 'httplug.factory.guzzle6'
113-
config:
114-
base_uri: 'http://google.se/'
115-
116-
```
117-
118-
```php
119-
120-
$httpClient = $this->container->get('httplug.client.my_guzzle5');
121-
$httpClient = $this->container->get('httplug.client.acme');
122-
```
123-
124-
125-
#### Plugins
126-
127-
You can configure the clients with plugins.
128-
129-
```yaml
130-
// services.yml
131-
acme_plugin:
132-
class: Acme\Plugin\MyCustonPlugin
133-
arguments: ["%api_key%"]
134-
```
135-
```yaml
136-
// config.yml
137-
httpug:
138-
plugins:
139-
cache:
140-
cache_pool: 'my_cache_pool'
141-
clients:
142-
acme:
143-
factory: 'httplug.factory.guzzle6'
144-
plugins: ['acme_plugin', 'httplug.plugin.cache', ''httplug.plugin.retry']
145-
config:
146-
base_uri: 'http://google.se/'
147-
```
148-
149-
#### Authentication
150-
151-
```yaml
152-
// config.yml
153-
httpug:
154-
plugins:
155-
authentication:
156-
my_basic:
157-
type: 'basic'
158-
username: 'my_username'
159-
password: 'p4ssw0rd'
160-
my_wsse:
161-
type: 'wsse'
162-
username: 'my_username'
163-
password: 'p4ssw0rd'
164-
my_brearer:
165-
type: 'bearer'
166-
token: 'authentication_token_hash'
167-
my_service:
168-
type: 'service'
169-
service: 'my_authentication_service'
170-
171-
clients:
172-
acme:
173-
factory: 'httplug.factory.guzzle6'
174-
plugins: ['httplug.plugin.authentication.my_wsse']
175-
```
176-
177-
178-
### Use for Reusable Bundles
179-
180-
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.
181-
182-
The only steps they need is `require` one of the adapter implementations in their projects `composer.json` and instantiating the HttplugBundle in their kernel.
38+
Please see the [official documentation](http://docs.php-http/en/latest/integrations/index.html).
18339

18440

18541
## Testing

0 commit comments

Comments
 (0)