playbloom/guzzle-bundle
Composer 安装命令:
composer require playbloom/guzzle-bundle
包简介
Provide Symfony2 web profiler for Guzzle
README 文档
README
Provide a basic logger and an advanced profiler for Guzzle with support for multiple Guzzle versions.
- The basic logger uses 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
- Multi-version support: Automatically detects and works with Guzzle 4.x, 5.x, 6.x, and 7.x
Supported Guzzle Versions
This bundle supports the following Guzzle versions:
- Guzzle 4.x (
guzzlehttp/guzzle:~4.0) - Guzzle 5.x (
guzzlehttp/guzzle:~5.0) - Guzzle 6.x (
guzzlehttp/guzzle:~6.0) - Guzzle 7.x (
guzzlehttp/guzzle:~7.0)
The bundle automatically detects which version you have installed and adapts accordingly.
Installation
composer require --dev playbloom/guzzle-bundle
Add the bundle to your Symfony app kernel
<?php // in %your_project%/app/AppKernel.php $bundles[] = new Playbloom\Bundle\GuzzleBundle\PlaybloomGuzzleBundle(); ?>
To enable the advanced profiler & the toolbar/web profiler panel, add this line to your app/config/config_dev.yml
playbloom_guzzle: web_profiler: true
Guzzle client as a Symfony service
Concrete Guzzle client creation can be easily managed by the Symfony service container thanks to a simple factory configuration, in this case, you just need to tag your guzzle service(s) with playbloom_guzzle.client.
Automatic plugin attachment via service tags works for all Guzzle versions (4, 5, 6, and 7). It will add the basic logger to your client(s). If the web_profiler is enabled in the current environment, it will also add the advanced profiler and display report on the Symfony toolbar/web profiler.
# config/services.yaml services: acme.client: class: '%acme.client.class%' factory: ['%acme.client.class%', 'factory'] tags: ['playbloom_guzzle.client']
Add the logger/profiler manually to a Guzzle client
If you need to handle the registration of the logger or profiler manually, you can retrieve these services from the Symfony container. The bundle automatically registers the correct service based on your Guzzle version.
For Guzzle 4 and 5
use GuzzleHttp\Client; $client = new Client(['base_url' => 'https://api.example.com']); $logger = $container->get('playbloom_guzzle.client.plugin.subscriber.logger'); $client->getEmitter()->attach($logger); $profiler = $container->get('playbloom_guzzle.client.plugin.subscriber.profiler'); $client->getEmitter()->attach($profiler);
For Guzzle 6+
use GuzzleHttp\Client; use GuzzleHttp\HandlerStack; $stack = HandlerStack::create(); $logger = $container->get('playbloom_guzzle.client.plugin.middleware.logger'); $stack->push($logger); $profiler = $container->get('playbloom_guzzle.client.plugin.middleware.profiler'); $stack->push($profiler); $client = new Client([ 'base_uri' => 'https://api.example.com', 'handler' => $stack ]);
Customize your own profiler panel
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 developement and you want to have the API requests profiled in this panel.
It's quite easy:
First, define your own GithubDataCollector extending the Playbloom\Bundle\GuzzleBundle\DataCollector\GuzzleDataCollector
Then extends the guzzle web profiler template
{% extends 'PlaybloomGuzzleBundle: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 'PlaybloomGuzzleBundle:Profiler:requests.html.twig' with {'requests': collector.requests } %}
{% endblock %}
And finally declare your data collector
# config/services.yaml services: data_collector.github: class: Acme\GithubBundle\DataCollector\GithubDataCollector arguments: - '@playbloom_guzzle.client.plugin.profiler' tags: - { name: data_collector, template: '@AcmeGithub/Collector/github.html.twig', id: github }
That's it, now your profiler panel displays your custom information and the Guzzle API requests.
TODO
- Add extra information about the client configuration itself (thanks to the guzzle service builder?)
- Add clients|host|endpoint|time filters for http requests
Licence
This bundle is under the MIT license. See the complete license in the bundle
Credits
- Swagger for the UI
playbloom/guzzle-bundle 适用场景与选型建议
playbloom/guzzle-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 311.32k 次下载、GitHub Stars 达 82, 最近一次更新时间为 2013 年 02 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「Symfony2」 「Guzzle」 「profiler」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 playbloom/guzzle-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 playbloom/guzzle-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 playbloom/guzzle-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
g4 application profiler package
Symfony2 Barcode Generator Bundle with Twig function extension
Symfony bundle to connect AWS sns and sqs to create offline queue processing
Cloudflare Middleware For Guzzle
Integrate the doctrine-translatable extension in Symfony2
Video Editor Bundle
统计信息
- 总下载量: 311.32k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 85
- 点击次数: 27
- 依赖项目数: 1
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2013-02-23