dev-master
9999999-dev http://github.com/guilhermednt/http-service-bundleSymfony HttpServiceBundle
MIT
The Requires
- php >=5.3.0
- guzzle/guzzle >=3.7.0
by Guilherme Donato
service http proxy
Symfony HttpServiceBundle
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)
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
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)
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);
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)
Symfony HttpServiceBundle
MIT
service http proxy