php-middleware/php-debug-bar 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

php-middleware/php-debug-bar

Composer 安装命令:

composer require php-middleware/php-debug-bar

包简介

PHP Debug Bar PSR-15 middleware with PSR-7

README 文档

README

PHP Debug Bar as framework-agnostic PSR-15 middleware with PSR-7 messages created by PSR-17 message factories. Also provides PSR-11 container invokable factories.

Framework-agnostic way to attach PHP Debug Bar to your response (html or non-html!).

Installation

composer require --dev php-middleware/php-debug-bar

To build middleware you need to inject DebugBar\JavascriptRenderer (you can get it from DebugBar\StandardDebugBar) inside PhpDebugBarMiddleware and add it into your middleware runner:

$debugbar = new DebugBar\StandardDebugBar();
$debugbarRenderer = $debugbar->getJavascriptRenderer('/phpdebugbar');
$middleware = new PhpMiddleware\PhpDebugBar\PhpDebugBarMiddleware($debugbarRenderer, $psr17ResponseFactory, $psr17StreamFactory);

// or use provided factory
$factory = new PhpMiddleware\PhpDebugBar\PhpDebugBarMiddlewareFactory();
$middleware = $factory($psr11Container);

$app = new MiddlewareRunner();
$app->add($middleware);
$app->run($request, $response);

You don't need to copy any static assets from phpdebugbar vendor!

How to force disable or enable PHP Debug Bar?

Sometimes you want to have control when enable or disable PHP Debug Bar:

  • custom content negotiation,
  • allow debug redirects responses.

We allow you to disable attaching phpdebugbar using X-Enable-Debug-Bar: false header, cookie or request attribute. To force enable just send request with X-Enable-Debug-Bar header, cookie or request attribute with true value.

PSR-17

This package isn't require any PSR-7 implementation - you need to provide it by own. Middleware require ResponseFactory and StreamFactory interfaces. List of existing interfaces.

... and PSR-11

If you use provided PSR-11 factories, then your container must have services registered as PSR-17 interface's name. Example for laminas-diactoros implementation and Pimple:

$container[Psr\Http\Message\ResponseInterface::class] = new Laminas\Diactoros\ResponseFactory();
$container[Psr\Http\Message\StreamFactoryInterface::class] = new Laminas\Diactoros\StreamFactory();

How to install on Mezzio?

You need to register PhpMiddleware\PhpDebugBar\ConfigProvider and pipe provided middleware:

$app->pipe(\PhpMiddleware\PhpDebugBar\PhpDebugBarMiddleware::class);

For more - follow Mezzio documentation.

How to install on Slim 3?

Register factories in container:

foreach (ConfigProvider::getConfig()['dependencies']['factories'] as $key => $factory) {
    $container[$key] = new $factory();
}

and add middleware from container to app:

$app->add(
    $app->getContainer()->get(\PhpMiddleware\PhpDebugBar\PhpDebugBarMiddleware::class)
);

How to configure using existing factories?

Put array with a configuration into PhpMiddleware\PhpDebugBar\ConfigProvider service in your container:

return [
    'phpmiddleware' => [
        'phpdebugbar' => [
            'javascript_renderer' => [
                'base_url' => '/phpdebugbar',
            ],
            'collectors' => [
                DebugBar\DataCollector\ConfigCollector::class, // Service names of collectors
            ],
            'storage' => null, // Service name of storage
        ],
    ],
];

You can override existing configuration by merge default configuration with your own (example):

return array_merge(PhpMiddleware\PhpDebugBar\ConfigProvider::getConfig(), $myOverritenConfig);

It's just works with any modern php framework!

Middleware tested on:

And any other modern framework supported PSR-17 middlewares and PSR-7.

php-middleware/php-debug-bar 适用场景与选型建议

php-middleware/php-debug-bar 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 487.73k 次下载、GitHub Stars 达 77, 最近一次更新时间为 2015 年 08 月 31 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「debug」 「middleware」 「psr」 「psr-7」 「PSR-11」 「psr-15」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 php-middleware/php-debug-bar 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 php-middleware/php-debug-bar 我们能提供哪些服务?
定制开发 / 二次开发

基于 php-middleware/php-debug-bar 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 487.73k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 77
  • 点击次数: 26
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 77
  • Watchers: 5
  • Forks: 19
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-08-31