2017 © Pedro Peláez
 

symfony-bundle buzz-bundle

Symfony Bundle for using the lightweight Buzz HTTP client.

image

gremo/buzz-bundle

Symfony Bundle for using the lightweight Buzz HTTP client.

  • Sunday, May 29, 2016
  • by gremo
  • Repository
  • 1 Watchers
  • 7 Stars
  • 28,212 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 4 Forks
  • 0 Open issues
  • 7 Versions
  • 3 % Grown

The README.md

GremoBuzzBundle

Latest stable Downloads total GitHub issues, (*1)

Symfony Bundle for using the lightweight Buzz HTTP client., (*2)

Installation

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

{
    "require": {
        "gremo/buzz-bundle": "~1.0"
    }
}

Then run composer update and register the bundle with your kernel in app/appKernel.php:, (*4)

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Gremo\BuzzBundle\GremoBuzzBundle(),
        // ...
    );
}

Legacy Symfony (2.0.*)

Add the following to your deps file:, (*5)

[buzz]
    git=https://github.com/kriswallsmith/Buzz.git

[GremoBuzzBundle]
    git=https://github.com/gremo/GremoBuzzBundle.git
    target=bundles/Gremo/BuzzBundle

Then run php bin/vendors update and register the namespaces with the autoloader (app/autoload.php):, (*6)

<?php
// app/autoload.php

$loader->registerNamespaces(array(
    // ...
    'Buzz'  => __DIR__.'/../vendor/buzz/lib',
    'Gremo' => __DIR__.'/../vendor/bundles',
    // ...
));

Finally register the bundle with your kernel in app/appKernel.php:, (*7)

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Gremo\BuzzBundle\GremoBuzzBundle(),
        // ...
    );
}

Configuration

Configuration is not needed. Available options and types (for the default values see Buzz\Client\AbstractClient):, (*8)

# GremoBuzzBundle Configuration
gremo_buzz:
    client: "native" # allowed "curl", "multi_curl" or "native"
    options:
        ignore_errors: ~ # boolean
        max_redirects: ~ # integer
        proxy:         ~ # string
        timeout:       ~ # integer
        verify_host:   ~ # integer
        verify_peer:   ~ # boolean

Usage

Get the gremo_buzz service from the service container:, (*9)

/** @var $browser \Buzz\Browser */
$browser = $this->get('gremo_buzz');

Refer to Kris Wallsmith Buzz library for sending HTTP requests., (*10)

Dependency Injection Tags

You can register a listener creating a service that implements Buzz\Listener\ListenerInterface and tagging it as gremo_buzz.listener (optionally defining a priority attribute). Higher priority means that the corresponding listener is executed first., (*11)

Example listener that logs outgoing requests:, (*12)

<?php

use Buzz\Listener\ListenerInterface;
use Buzz\Message\MessageInterface;
use Buzz\Message\RequestInterface;
use JMS\DiExtraBundle\Annotation as DI;
use Psr\Log\LoggerInterface;

/**
 * @DI\Service("buzz.listener.logger")
 * @DI\Tag("gremo_buzz.listener", attributes={"priority"=10})
 */
class BuzzLoggerListener implements ListenerInterface
{
    /**
     * @var \Psr\Log\LoggerInterface
     */
    private $logger;

    /**
     * @var float
     */
    private $startTime;

    /**
     * @DI\InjectParams({"logger" = @DI\Inject("logger")})
     */
    public function __construct(LoggerInterface $logger)
    {
        $this->logger = $logger;
    }

    /**
     * {@inheritdoc}
     */
    public function preSend(RequestInterface $request)
    {
        $this->startTime = microtime(true);
    }

    /**
     * {@inheritdoc}
     */
    public function postSend(RequestInterface $request, MessageInterface $response)
    {
        $this->logger->info(sprintf(
            'Sent "%s %s%s" in %dms',
            $request->getMethod(),
            $request->getHost(),
            $request->getResource(),
            round((microtime(true) - $this->startTime) * 1000)
        ));
    }
}

Note that this example uses the new Psr\Log\LoggerInterface and may not work for old versions of Symfony., (*13)

The Versions

29/05 2016

dev-master

9999999-dev

Symfony Bundle for using the lightweight Buzz HTTP client.

  Sources   Download

MIT

The Requires

 

http client buzz

29/05 2016

v1.1.0

1.1.0.0

Symfony Bundle for using the lightweight Buzz HTTP client.

  Sources   Download

MIT

The Requires

 

http client buzz

01/09 2015

v1.0.4

1.0.4.0

Symfony 2 Bundle for using the lightweight Buzz HTTP client.

  Sources   Download

MIT

The Requires

 

http client buzz

28/10 2014

v1.0.3

1.0.3.0

Symfony 2 Bundle for using the lightweight Buzz HTTP client.

  Sources   Download

MIT

The Requires

 

http client buzz

09/06 2013

v1.0.2

1.0.2.0

Symfony 2 Bundle for using the lightweight Buzz HTTP client.

  Sources   Download

MIT

The Requires

 

http client buzz

17/04 2013

v1.0.1

1.0.1.0

Symfony 2 Bundle for using the lightweight Buzz HTTP client.

  Sources   Download

MIT

The Requires

 

http client buzz

05/04 2013

v1.0.0

1.0.0.0

Symfony 2 Bundle for using the lightweight Buzz HTTP client.

  Sources   Download

MIT

The Requires

 

http client buzz