Skip to content
This repository has been archived by the owner on Jun 16, 2020. It is now read-only.

Commit

Permalink
Improve README [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
gremo committed May 29, 2016
1 parent 9761afd commit 992783c
Showing 1 changed file with 57 additions and 38 deletions.
95 changes: 57 additions & 38 deletions README.md
@@ -1,16 +1,37 @@
# GremoBuzzBundle
[![Build status](https://img.shields.io/travis/gremo/GremoBuzzBundle.svg?style=flat-square)](https://travis-ci.org/gremo/GremoBuzzBundle) [![GitHub issues](https://img.shields.io/github/issues/gremo/GremoBuzzBundle.svg?style=flat-square)](https://github.com/gremo/GremoBuzzBundle/issues) [![Latest stable](https://img.shields.io/packagist/v/gremo/buzz-bundle.svg?style=flat-square)](https://packagist.org/packages/gremo/buzz-bundle) [![Downloads total](https://img.shields.io/packagist/dt/gremo/buzz-bundle.svg?style=flat-square)](https://packagist.org/packages/gremo/buzz-bundle)
[![Latest stable](https://img.shields.io/packagist/v/gremo/buzz-bundle.svg?style=flat-square)](https://packagist.org/packages/gremo/buzz-bundle) [![Downloads total](https://img.shields.io/packagist/dt/gremo/buzz-bundle.svg?style=flat-square)](https://packagist.org/packages/gremo/buzz-bundle) [![GitHub issues](https://img.shields.io/github/issues/gremo/GremoBuzzBundle.svg?style=flat-square)](https://github.com/gremo/GremoBuzzBundle/issues)

Symfony 2 Bundle for using the lightweight Buzz HTTP client.

- [Installation](#installation)
- [Configuration](#configuration)
- [Usage](#usage)
- [Adding listeners](#adding-listeners)
Symfony Bundle for using the lightweight Buzz HTTP client.

## Installation
Add the bundle in your `composer.json` file:

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

Then run `composer update` and register the bundle with your kernel in `app/appKernel.php`:

```php
<?php
// app/AppKernel.php

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

Add the following to your `deps` file (for Symfony 2.0.*):
### Legacy Symfony (2.0.*)
Add the following to your `deps` file:

```
[buzz]
Expand All @@ -21,9 +42,12 @@ Add the following to your `deps` file (for Symfony 2.0.*):
target=bundles/Gremo/BuzzBundle
```

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

```php
<?php
// app/autoload.php

$loader->registerNamespaces(array(
// ...
'Buzz' => __DIR__.'/../vendor/buzz/lib',
Expand All @@ -32,48 +56,39 @@ $loader->registerNamespaces(array(
));
```

If you are using [Composer](http://getcomposer.org/) and Symfony >= 2.1.*, add the following to your `composer.json` file:

```javascript
{
"require": {
"gremo/buzz-bundle": "*"
}
}
```

Finally register the bundle with your kernel in `app/appKernel.php`:

```php
<?php
// app/AppKernel.php

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

// ...
}
```

## Configuration
Configuration is not needed. Reference, along with default values:
Configuration is not needed. Available options and types (for the default values see [`Buzz\Client\AbstractClient`](https://github.com/kriswallsmith/Buzz/blob/master/lib/Buzz/Client/AbstractClient.php)):
```yml
# GremoBuzzBundle Configuration
gremo_buzz:
client: "native" # allowed "curl", "multi_curl" or "native"
options:
ignore_errors: true
max_redirects: 5
proxy: ~
timeout: 5
verify_host: 2
verify_peer: true
ignore_errors: ~ # boolean
max_redirects: ~ # integer
proxy: ~ # string
timeout: ~ # integer
verify_host: ~ # integer
verify_peer: ~ # boolean
```

## Usage
Get `gremo_buzz` service from the service container and start using the browser:
Get the `gremo_buzz` service from the service container:

```php
/** @var $browser \Buzz\Browser */
Expand All @@ -82,14 +97,14 @@ $browser = $this->get('gremo_buzz');

Refer to [Kris Wallsmith Buzz library](https://github.com/kriswallsmith/Buzz) for sending HTTP requests.

## Adding listeners
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. Same priority would lead to unexpected behaviours, as well as not numerical ones.
## 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.

An example listener that logs outgoing requests:
Example listener that logs outgoing requests:

```php
<?php

use Buzz\Listener\ListenerInterface;
use Buzz\Message\MessageInterface;
use Buzz\Message\RequestInterface;
Expand Down Expand Up @@ -120,21 +135,25 @@ class BuzzLoggerListener implements ListenerInterface
$this->logger = $logger;
}

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

/**
* {@inheritdoc}
*/
public function postSend(RequestInterface $request, MessageInterface $response)
{
$seconds = microtime(true) - $this->startTime;

$logger->info(sprintf(
$this->logger->info(sprintf(
'Sent "%s %s%s" in %dms',
$request->getMethod(),
$request->getHost(),
$request->getResource(),
round($seconds * 1000)
round((microtime(true) - $this->startTime) * 1000)
));
}
}
Expand Down

0 comments on commit 992783c

Please sign in to comment.