定制 hkvstore/php-debug-bar 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

hkvstore/php-debug-bar

最新稳定版本:4.2.1

Composer 安装命令:

composer require hkvstore/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.

统计信息

  • 总下载量: 6.09k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 19
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-03-03