<commit_before># HttplugBundle

[![Latest Version](https://img.shields.io/github/release/php-http/HttplugBundle.svg?style=flat-square)](https://github.com/php-http/HttplugBundle/releases)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)
[![Build Status](https://img.shields.io/travis/php-http/HttplugBundle.svg?style=flat-square)](https://travis-ci.org/php-http/HttplugBundle)
[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/php-http/httplug-bundle.svg?style=flat-square)](https://scrutinizer-ci.com/g/php-http/HttplugBundle)
[![Quality Score](https://img.shields.io/scrutinizer/g/php-http/httplug-bundle.svg?style=flat-square)](https://scrutinizer-ci.com/g/php-http/HttplugBundle)
[![Total Downloads](https://img.shields.io/packagist/dt/php-http/httplug-bundle.svg?style=flat-square)](https://packagist.org/packages/php-http/HttplugBundle)

**Symfony integration for the [php-http Httplug](http://docs.httplug.io/) HTTP client**


## Install

Via Composer

``` bash
$ composer require php-http/httplug-bundle
```

Enable the bundle in your kernel:

``` php
<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Http\HttplugBundle\HttplugBundle(),
    );
}
```

## Usage

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.

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


### Use in Applications

#### Custom services

| Service id | Description |
| ---------- | ----------- |
| httplug.message_factory | Service* that provides the `Http\Message\MessageFactory`
| httplug.uri_factory | Service* that provides the `Http\Message\UriFactory`
| httplug.stream_factory | Service* that provides the `Http\Message\StreamFactory`
| httplug.client.[name] | This is your Httpclient that you have configured. With the configuration below the name would be `acme_client`.
| httplug.client | This is the first client configured or a client named `default`.
| httplug.plugin.content_length <br> httplug.plugin.decoder<br> httplug.plugin.error<br> httplug.plugin.logger<br> httplug.plugin.redirect<br> httplug.plugin.retry | These are built in plugins that live in the `php-http/plugins` package. These servcies are not public and may only be used when configure HttpClients or services. 

\* *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.*


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.

```yaml
httplug:
  clients:
      acme_client: # This is the name of the client
        factory: 'httplug.factory.guzzle6'

  main_alias:
    client: httplug.client.default
    message_factory: httplug.message_factory.default
    uri_factory: httplug.uri_factory.default
    stream_factory: httplug.stream_factory.default
  classes:
    # uses discovery if not specified
    client: ~
    message_factory: ~
    uri_factory: ~
    stream_factory: ~
```


#### Configure your client

You can configure your clients with some good default options. The clients are later registered as services.

```yaml
httplug:
  clients:
    my_guzzle5:
      factory: 'httplug.factory.guzzle5'
      config:
        # These options are given to Guzzle without validation.
        defaults:
          base_uri: 'http://google.se/'
          verify_ssl: false
          timeout: 4
          headers:
            Content-Type: 'application/json'
    acme:
      factory: 'httplug.factory.guzzle6'
      config:
        base_uri: 'http://google.se/'

```

```php

$httpClient = $this->container->get('httplug.client.my_guzzle5');
$httpClient = $this->container->get('httplug.client.acme');
```


#### Plugins

You can configure the clients with plugins.

```yaml
// services.yml
acme_plugin:
  class: Acme\Plugin\MyCustonPlugin
  arguments: ["%api_key%"]
```
```yaml
// config.yml
httpug:
  clients:
    acme:
      factory: 'httplug.factory.guzzle6'
      plugins: ['acme_plugin' , 'httplug.plugin.logger']
      config:
        base_uri: 'http://google.se/'
```


### Use for Reusable Bundles

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.

The only steps they need is `require` one of the adapter implementations in their projects `composer.json` and instantiating the HttplugBundle in their kernel.


## Testing

``` bash
$ composer test
```


## Contributing

Please see our [contributing guide](http://docs.php-http.org/en/latest/development/contributing.html).


## Security

If you discover any security related issues, please contact us at [<EMAIL>](mailto:<EMAIL>).


## License

The MIT License (MIT). Please see [License File](LICENSE) for more information.
<commit_msg>Fix YAML indentation, closes #27<commit_after># HttplugBundle

[![Latest Version](https://img.shields.io/github/release/php-http/HttplugBundle.svg?style=flat-square)](https://github.com/php-http/HttplugBundle/releases)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)
[![Build Status](https://img.shields.io/travis/php-http/HttplugBundle.svg?style=flat-square)](https://travis-ci.org/php-http/HttplugBundle)
[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/php-http/httplug-bundle.svg?style=flat-square)](https://scrutinizer-ci.com/g/php-http/HttplugBundle)
[![Quality Score](https://img.shields.io/scrutinizer/g/php-http/httplug-bundle.svg?style=flat-square)](https://scrutinizer-ci.com/g/php-http/HttplugBundle)
[![Total Downloads](https://img.shields.io/packagist/dt/php-http/httplug-bundle.svg?style=flat-square)](https://packagist.org/packages/php-http/HttplugBundle)

**Symfony integration for the [php-http Httplug](http://docs.httplug.io/) HTTP client**


## Install

Via Composer

``` bash
$ composer require php-http/httplug-bundle
```

Enable the bundle in your kernel:

``` php
<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Http\HttplugBundle\HttplugBundle(),
    );
}
```

## Usage

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.

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


### Use in Applications

#### Custom services

| Service id | Description |
| ---------- | ----------- |
| httplug.message_factory | Service* that provides the `Http\Message\MessageFactory`
| httplug.uri_factory | Service* that provides the `Http\Message\UriFactory`
| httplug.stream_factory | Service* that provides the `Http\Message\StreamFactory`
| httplug.client.[name] | This is your Httpclient that you have configured. With the configuration below the name would be `acme_client`.
| httplug.client | This is the first client configured or a client named `default`.
| httplug.plugin.content_length <br> httplug.plugin.decoder<br> httplug.plugin.error<br> httplug.plugin.logger<br> httplug.plugin.redirect<br> httplug.plugin.retry | These are built in plugins that live in the `php-http/plugins` package. These servcies are not public and may only be used when configure HttpClients or services.

\* *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.*


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.

```yaml
httplug:
    clients:
        acme_client: # This is the name of the client
        factory: 'httplug.factory.guzzle6'

    main_alias:
        client: httplug.client.default
        message_factory: httplug.message_factory.default
        uri_factory: httplug.uri_factory.default
        stream_factory: httplug.stream_factory.default
    classes:
        # uses discovery if not specified
        client: ~
        message_factory: ~
        uri_factory: ~
        stream_factory: ~
```


#### Configure your client

You can configure your clients with some good default options. The clients are later registered as services.

```yaml
httplug:
    clients:
        my_guzzle5:
            factory: 'httplug.factory.guzzle5'
            config:
                # These options are given to Guzzle without validation.
                defaults:
                    base_uri: 'http://google.se/'
                    verify_ssl: false
                    timeout: 4
                    headers:
                        Content-Type: 'application/json'
        acme:
            factory: 'httplug.factory.guzzle6'
            config:
                base_uri: 'http://google.se/'

```

```php

$httpClient = $this->container->get('httplug.client.my_guzzle5');
$httpClient = $this->container->get('httplug.client.acme');
```


#### Plugins

You can configure the clients with plugins.

```yaml
// services.yml
acme_plugin:
      class: Acme\Plugin\MyCustonPlugin
      arguments: ["%api_key%"]
```
```yaml
// config.yml
httpug:
    clients:
        acme:
            factory: 'httplug.factory.guzzle6'
            plugins: ['acme_plugin' , 'httplug.plugin.logger']
            config:
                base_uri: 'http://google.se/'
```


### Use for Reusable Bundles

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.

The only steps they need is `require` one of the adapter implementations in their projects `composer.json` and instantiating the HttplugBundle in their kernel.


## Testing

``` bash
$ composer test
```


## Contributing

Please see our [contributing guide](http://docs.php-http.org/en/latest/development/contributing.html).


## Security

If you discover any security related issues, please contact us at [<EMAIL>](mailto:<EMAIL>).


## License

The MIT License (MIT). Please see [License File](LICENSE) for more information.

{'fraction_non_alphanumeric': 0.10830207144022182, 'fraction_numerical': 0.0013048442342195401, 'mean_word_length': 3.7864949258391882, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 25, 'https://': 22, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1385285', 'n_tokens_mistral': 3576, 'n_tokens_neox': 3420, 'n_words': 1140}