dev-master
9999999-dev https://github.com/orkestra/OrkestraGuzzleBundleGuzzle bundle for Symfony2
Apache2
The Requires
- php >=5.3.2
- guzzle/guzzle 3.*
by Zach D. Badgett
guzzle web service guzzlebundle
Guzzle bundle for Symfony2
Symfony2 bundle for Guzzle, (*1)
To install OrkestraGuzzleBundle with Composer just add the following to your
composer.json
file:, (*2)
// composer.json { // ... require: { // ... "orkestra/guzzle-bundle": "dev-master" } }
Then, you can install the new dependencies by running Composer's update
command from the directory where your composer.json
file is located:, (*3)
$ php composer.phar update
Composer will automatically download all required files, and install them
for you. All that is left to do is to update your AppKernel.php
file, and
register the new bundle:, (*4)
<?php // in AppKernel::registerBundles() $bundles = array( // ... new Orkestra\Bundle\GuzzleBundle\GuzzleBundle(), // ... );
To create a service you must create a service file:, (*5)
<?php // ..src/Acme/AcmeBundle/Services/AcmeService.php namespace Acme\AcmeBundle\Services; use Orkestra\Bundle\GuzzleBundle\Services\Service as AbstractService; use Orkestra\Bundle\GuzzleBundle\Services\Annotation\Command; use Orkestra\Bundle\GuzzleBundle\Services\Annotation\Doc; use Orkestra\Bundle\GuzzleBundle\Services\Annotation\Param; use Orkestra\Bundle\GuzzleBundle\Services\Annotation\Headers; use Orkestra\Bundle\GuzzleBundle\Services\Annotation\Type; class AcmeService extends AbstractService { /** * @Command(name="acme_users", method="GET", uri="/users") * @Doc("Get list of Acme users") */ public function acmeUsersCommand() { return $this->getResponse(); } /** * @Command(name="acme_user_id", method="GET", uri="/users/{user_id}") * @Doc("Find user by id") * @Param(name="user_id", type="integer", required="true") */ public function acmeUserByIdCommand() { //Here you can manipulate the response, you can bind it to an object for example return $this->getResponse(); } }
After the service is created you must define it in your config.yml
file, (*6)
guzzle: services: AcmeService: class: Acme\AcmeBundle\Services\AcmeService params: base_url: https://api.acme.com
The params are passed to the constructor as an array and is processed into Guzzle's configuration. Now you can use your service with Guzzle!!, (*7)
<?php //... class AcmeController extends Controller { public function acmeAction() { $guzzle = $this->get('guzzle'); //Get list of users $users = $guzzle->getService('AcmeService')->execute('acme_users'); //Get a user by id $oneUser = $guzzle->getService('AcmeService')->execute('acme_user_id', array('user_id' => 1)); } }
This bundle is work in progress and may have changes that break compatibility., (*8)
Guzzle bundle for Symfony2
Apache2
guzzle web service guzzlebundle