hannesvdvreken / guzzle-debugbar
Guzzle 中间件,将请求记录到 DebugBar 时间线中
3.0.1
2020-09-17 17:35 UTC
Requires
- php: >=7.2
- hannesvdvreken/guzzle-profiler: ^2
- maximebf/debugbar: ^1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.2.20
- illuminate/support: >=6
- phpunit/phpunit: ^8.2.3
README
⚠️ 此项目可被领养。如果您有兴趣积极参与维护3个紧密相关的包,请与我们联系。
将请求记录到 DebugBar 时间线中的 Guzzle 中间件。
安装
composer require hannesvdvreken/guzzle-debugbar --dev
使用
只需六行代码即可将您的请求记录到 DebugBar 时间线。
$debugBar = new StandardDebugBar(); // or when using Laravel: $debugBar = app('debugbar'); // Get data collector. $timeline = $debugBar->getCollector('time'); // Wrap the timeline. $profiler = new \GuzzleHttp\Profiling\Debugbar\Profiler($timeline); // Add the middleware to the stack $stack = \GuzzleHttp\HandlerStack::create(); $stack->unshift(new \GuzzleHttp\Profiling\Middleware($profiler)); // New up the client with this handler stack. $client = new \GuzzleHttp\Client(['handler' => $stack]);
现在 $client
已经准备好发送请求。现在每个请求都会记录到时间线。
推荐:使用 Guzzle 的 Log 中间件
$debugBar = new StandardDebugBar(); // or when using Laravel: $debugBar = app('debugbar'); // PSR-3 logger: $logger = $debugBar->getCollector('messages'); // Create a new Log middleware. $stack->push(\GuzzleHttp\Middleware::log($logger, new \GuzzleHttp\MessageFormatter())); // New up the client with this handler stack. $client = new \GuzzleHttp\Client(['handler' => $stack]);
支持
Laravel
建议安装并配置我朋友 Barry 的 laravel-debugbar。请确保将他的和我们的服务提供者包含在您的应用的 providers
数组中
'providers' => [ ... Barryvdh\Debugbar\ServiceProvider::class, GuzzleHttp\Profiling\Debugbar\Support\Laravel\ServiceProvider::class, ],
如果您想使用不同的 DebugBar\DebugBar
实例,创建一个 ServiceProvider 将实例绑定到键 debugbar
。例如使用此注册方法
public function register() { $this->app->singleton('debugbar', function () { return new \DebugBar\StandardDebugBar(); }); }
请确保通过 IoC 容器创建每个客户端(使用 GuzzleHttp\ClientInterface
或 GuzzleHttp\Client
类型提示)。
常见问题解答
我遇到了以下错误之一
'time' 不是一个已注册的收集器
'exceptions' 不是一个已注册的收集器
这意味着您已在您的 packages/barryvdh/laravel-debugbar/config.php
中禁用了 time
收集器和/或 exceptions
收集器。这些默认情况下是启用的。此包依赖于它,因此请启用它们。
贡献
请随意提交 pull request。请尽量使您的代码尽可能符合 PSR-2 规范。运行 vendor/bin/php-cs-fixer fix
快速修复代码风格。提供有关要添加/更改/删除/修复内容的良好描述。
测试
在推送代码之前,运行单元测试套件。
vendor/bin/phpunit