2017 © Pedro Peláez
 

symfony-bundle http-service-bundle

Symfony HttpServiceBundle

image

guilhermednt/http-service-bundle

Symfony HttpServiceBundle

  • Thursday, January 16, 2014
  • by guilhermednt
  • Repository
  • 1 Watchers
  • 0 Stars
  • 5 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

http-service-bundle

Currently, this bundle turns Guzzle HTTP Client into a service to allow application wide configuration (like curl proxy settings)., (*1)

It uses a ClientFactory so that you can adapt it to other HTTP Clients., (*2)

Installation

Step 1: Add package as requirement in Composer

Add the bundle to your composer.json:, (*3)

``` js { "require": { "guilhermednt/http-service-bundle": "dev-master" } }, (*4)


Then run the update command: ``` bash $ composer update guilhermednt/http-service-bundle

Step 2: Tell Symfony2 about it.

Enable the bundle in your AppKernel.php:, (*5)

``` php <?php // app/AppKernel.php, (*6)

public function registerBundles() { $bundles = array( // ... new Donato\HttpServiceBundle\DonatoHttpServiceBundle(), ); }, (*7)


### Step 3: Add desired parameters This bundle does not require you to change `config.yml`, so that you can have different configuration scenarios for each environment you have. The minimum configuration needed is this: ``` yaml # app/config/parameters.yml parameters: http_client_factory_class: Donato\HttpServiceBundle\Factory\ClientFactory http_client_config: ~

Below you can see an example for HTTP Proxy with Authentication:, (*8)

``` yaml, (*9)

app/config/parameters.yml

imports: - { resource: constants.php }, (*10)

parameters: # ... your regular parameters ..., (*11)

http_client_factory_class: Donato\HttpServiceBundle\Factory\ClientFactory
http_client_config:
    curl:
        %curl.proxy.type%: HTTP
        %curl.proxy.host%: my.proxy.example.com
        %curl.proxy.port%: 1234
        %curl.proxy.auth%: username:password

**Note** that the CURL constants are introduced via **constants.php** as follows: ``` php <?php // app/config/constants.php $container->setParameter('curl.proxy.type', CURLOPT_PROXYTYPE); $container->setParameter('curl.proxy.host', CURLOPT_PROXY); $container->setParameter('curl.proxy.port', CURLOPT_PROXYPORT); $container->setParameter('curl.proxy.auth', CURLOPT_PROXYUSERPWD);

That's it!

Now you can start using the service named http_client_factory. To instantiate a Guzzle\Http\Client you may just do the following:, (*12)

``` php <?php // SomeController.php public function someAction() { // ..., (*13)

    $clientFactory = $this->get('http_client_factory');
    $client = $clientFactory->getGuzzleClient();

    // ...
}

```, (*14)

The Versions

16/01 2014

dev-master

9999999-dev http://github.com/guilhermednt/http-service-bundle

Symfony HttpServiceBundle

  Sources   Download

MIT

The Requires

 

by Guilherme Donato

service http proxy