This bundle integrates Guzzle 6.x into Symfony. Guzzle is a PHP framework for building RESTful web service clients.
- PHP 5.6 or above
- Guzzle PHP Framework (included by composer)
- Symfony 2.7 or above (including Symfony 3.x)
To install this bundle, run the command below and you will get the latest version by Packagist.
composer require e-moe/guzzle6-bundle
To use the newest (maybe unstable) version please add following into your composer.json:
{
"require": {
"e-moe/guzzle6-bundle": "dev-master"
}
}
Load bundle in AppKernel.php:
new Emoe\GuzzleBundle\EmoeGuzzleBundle(),
Configuration in config.yml:
emoe_guzzle:
log:
enabled: true # Logging requests to Monolog
format: 'Guzzle: [{ts}] "{method} {uri} HTTP/{version}" {code}' # Optional log format customization
Using services in controller:
$client = $this->get('guzzle.client');
$response = $client->get('http://example.com');
Adding aliases: If you want to use different names for provided services you can use aliases. This is a good idea if you don't want have any dependency to guzzle in your service name.
services:
http.client:
alias: guzzle.client
Creating multiple clients: If you want to have different Guzzle clients in your application all you need is to define them in services file and add "guzzle.client" tag to turn on Symfony integration (Debug toolbar, logs, so on..).
services:
guzzle.client_one:
class: GuzzleHttp\Client
tags:
- { name: guzzle.client }
guzzle.client_two:
class: GuzzleHttp\Client
tags:
- { name: guzzle.client }
- Nikolay Labinskiy aka e-moe
Inspired by Chris Wilkinson's and Florian Preusner's GuzzleBundles (1, 2).
See also the list of contributors who participated in this project.
This bundle is released under the MIT license