Provides a basic logger and an advanced profiler for Guzzle
- The basic logger use the default Symfony app logger, it's safe to use in your production environment.
- The advanced profiler is for debug purposes and will display a dedicated report available in the toolbar and Symfony Web Profiler
Add the composer requirements
{
"require-dev": {
"ratza/guzzle-profiler-bundle": "dev-master"
},
"repositories": {
{
"type": "vcs",
"url": "https://github.com/ratza/guzzle-profiler-bundle.git"
}
},
}
Add the bundle to your Symfony app kernel
<?php
// in %your_project%/app/AppKernel.php
$bundles[] = new Ratza\GuzzleProfilerBundle\RatzaGuzzleProfilerBundle();
?>
To enable the advanced profiler & the toolbar/web profiler panel, add this line to your app/config/config_dev.yml
ratza_guzzle:
web_profiler: true
If you need to handle the registration of the logger or profiler plugin manually, you can retrieve theses services from the Symfony container.
<?php
$client = new \GuzzleHttp\Client('https://my.api.com');
// basic logger service plugged & configured with the default Symfony app logger
$loggerPlugin = $container->get('ratza_guzzle.client.logger');
$client->getEmitter()->attach($loggerPlugin);
// advanced profiler for development and debug, requires web_profiler to be enabled
$profilerPlugin = $container->get('ratza_guzzle.client.profiler');
$client->getEmitter()->attach($profilerPlugin);
?>
If you need a custom profiler panel you can extend/reuse easily the data collector and profiler template from this bundle.
For example, you have a GitHubBundle which interact with the GitHub API. You also have a GitHub profiler panel to debug your development and you want to have the API requests profiled in this panel.
It's quite easy:
First, define your own GitHubDataCollector
extending the Ratza\GuzzleProfilerBundle\DataCollector\GuzzleDataCollector
Then extends the guzzle web profiler template
{% extends 'RatzaGuzzleProfilerBundle:Collector:guzzle.html.twig' %}
{% block panel %}
<div class="github">
<h2>GitHub</h2>
<ul>
<li><strong>GitHub API key:</strong> {{ collector.getApiKey }}</li>
<!-- Some custom information -->
</ul>
</div>
{% include 'RatzaGuzzleBundle:Profiler:requests.html.twig' with {'requests': collector.requests } %}
{% endblock %}
And finally declare your data collector
<service id="data_collector.github" class="Acme\GitHubBundle\DataCollector\GitHubDataCollector">
<argument type="service" id="ratza_guzzle.client.profiler"/>
<tag name="data_collector"
template="AcmeGithubBundle:Collector:github"
id="github"/>
</service>
That's it, now your profiler panel displays your custom information and the Guzzle API requests.
This bundle is under the MIT license. See the complete license in the bundle
- Swagger for the UI
- Ludovic Fleury for the original inspiration. This is a profiler only bundle that uses the same UI, but supports Guzzle Client 4.x and 5.x.