2017 © Pedro Peláez
 

symfony-bundle guzzle-bundle

Guzzle bundle for Symfony2

image

orkestra/guzzle-bundle

Guzzle bundle for Symfony2

  • Thursday, January 24, 2013
  • by zachbadgett
  • Repository
  • 1 Watchers
  • 10 Stars
  • 233 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 10 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

OrkestraGuzzleBundle

Symfony2 bundle for Guzzle, (*1)

Installation and Usage

1. Using Composer

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(),
    // ...
);

2. Usage

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)

The Versions

24/01 2013

dev-master

9999999-dev https://github.com/orkestra/OrkestraGuzzleBundle

Guzzle bundle for Symfony2

  Sources   Download

Apache2

The Requires

 

by Zach D. Badgett

guzzle web service guzzlebundle