hannesvdvreken/guzzle-clockwork

A Guzzle plugin that listens to events and logs them with Clockwork

Installs: 4 653

Dependents: 0

Stars: 22

Watchers: 1

Forks: 1

Language: PHP

0.3.0 2015-02-10 21:41 UTC

README

Build Status Latest Stable Version Total Downloads Coverage Status License

Guzzle Subscriber for logging to clockwork so you can view the requests timeline and logs in your browser's developer tools.

Developer tools timeline

Developer tools logs

Usage

// First you need a Guzzle HTTP Client
$client = new GuzzleHttp\Client;

// Then you need a Clockwork object
$clockwork = new Clockwork\Clockwork;

// Create the Guzzle subscriber
$subscriber = new GuzzleHttp\Subscriber\Log\ClockworkSubscriber($clockwork);

// Add it as a subscriber
$client->getEmitter()->attach($subscriber);

And you are done!

Laravel 4

If you are using Laravel 4, use the included service providers to add the subscriber to every Guzzle Client.

'providers' => [
    ...
    'Clockwork\Support\Laravel\ClockworkServiceProvider',
    'GuzzleHttp\Subscriber\Log\Support\Laravel\ServiceProvider',  
]

Be sure to create every client via the auto-resolving application container:

$client = App::make('GuzzleHttp\Client');

Guzzle v3

If you want to continue to work with the old Guzzle v3 (Guzzle\Http\Client instead of GuzzleHttp\Client) ClockworkPlugin then you might want to install the 0.1.* releases. Pull request with Guzzle v3 compatibility should be made against the guzzle3 branch. Install the latest guzzle v3 compatible version with 0.1.* or dev-guzzle3.

Versions 0.2.0 and up are all compatible with Guzzle v4 and v5.

Contributing

Feel free to make a pull request. Please try to be as PSR-2 compliant as possible.

Testing

To test your code before pushing, run the unit test suite.

phpunit

License

MIT