mostafasy/mezzio-debugbar

中间件,用于自动将 PHP DebugBar 插入 HTML 响应中

1.2.2 2024-09-11 15:47 UTC

This package is auto-updated.

Last update: 2024-09-11 15:48:24 UTC


README

- forked from : https://github.com/middlewares/debugbar

- forked from : https://github.com/php-middleware/phpdebugbar

mezzio/debugbar

Software License Testing Total Downloads

Mezzio 框架自动在 HTML 响应中插入 PHP DebugBar 的中间件。

要求

  • PHP >= 7.4

安装

composer require --dev mostafasy/mezzio-debugbar 

示例

此包提供了一个配置提供者,可以在使用 laminas-config-aggregator 或 mezzio-config-manager 时将其添加到您的 config/config.php 中。然而,因为它仅在开发时启用,所以我们建议在需要启用时创建一个 "local" 配置文件(例如,config/autoload/php-debugbar.local.php),以下内容

use DebugBar\Bridge\DoctrineCollector;
use DebugBar\Storage\FileStorage;
use Laminas\ConfigAggregator\ConfigAggregator;
use Laminas\Stdlib\ArrayUtils;

$aggregator = new ConfigAggregator(
    [
        Mezzio\DebugBar\ConfigProvider::class,
    ]
);
return ArrayUtils::merge(
    $aggregator->getMergedConfig(),
    [
// here you can overload the default Values .as example add doctrine collector or fileStorage
        'debugbar'     => [
            'disable'    => false,
            'captureAjax' => true,
            'collectors' => [
                DoctrineCollector::class,
            ],
            'storage'    => FileStorage::class,
            'storage_dir' =>'path/to-your-storage-dir'
        ],
    ]
);

禁用配置

有时您想在启用或禁用 PHP Debug Bar 时进行控制

  • 我们允许您使用 X-Disable-Debug-Bar: true 头部、cookie 或请求属性禁用 phpdebugbar。
  • 或者在配置中进行配置
'disable'=>true

捕获Ajax配置

使用此选项来捕获 Ajax 请求并在头部发送数据。 关于 AJAX 和堆叠数据的更多信息。默认情况下它是禁用的。

内联

将 true 设置为将 js/css 代码内联在 html 中。这可以解决(或减轻)与加载调试栏资源相关的一些问题。

renderOptions

使用此选项将渲染选项作为数组传递给调试栏。有关可用选项的列表,请参阅 https://github.com/maximebf/php-debugbar/blob/master/src/DebugBar/JavascriptRenderer.php#L132

示例用法是传递一个新的 base_url 位置,以便您可以重写渲染调试栏所需文件的位置。这可以使用符号链接、.htaccess 或路由到文件使用,以确保调试栏文件可访问。

文件存储

它将收集数据作为 json 文件存储在指定的目录下(该目录必须可写)。您可以配置如下

'storage'    => FileStorage::class,
'storage_dir' =>'path/to-your-storage-dir'

pdo存储

它将收集数据并保存到数据库中,您可以配置如下

'storage'    => PdoStorage::class,
'pdo' =>[
  'dsn'=>'mysql:dbname=testdb;host=127.0.0.1';',
  'username'=>'dbuser',
  'password'=>'dbpass',
],

请注意您必须执行以下 SQL 模式 pdo-sql-Schema

Doctrine 存储

它将收集数据并通过使用 Doctine 保存到数据库中,您可以配置如下

'storage'    => DoctrineStorage::class,
  'doctrine_storage'=>[
    // it will save queries into extra table for analysis purpose.by default it is false.
    'save_sql_queries_to_extra_table' => true,
    ],

您必须执行以下 SQL 模式: doctrine-sql-Schema

路由收集器

它将收集路由信息。我们可以添加收集器到配置中,如下所示

  'collectors' => [
                RouteCollector::class,
            ],

路由配置示例

 'routes' => [
        [
            'path' => '/path/to/match',
            'middleware' => 'Middleware service or pipeline',
            'allowed_methods' => ['GET', 'POST', 'PATCH'],
            'name' => 'route.name',
            'options' => [
                'stuff' => 'to',
                'pass'  => 'to',
                'the'   => 'underlying router',
            ],
        ],
        'another.route.name' => [
            'path' => '/another/path/to/match',
            'middleware' => 'Middleware service or pipeline',
            'allowed_methods' => ['GET', 'POST'],
            'options' => [
                'more'    => 'router',
                'options' => 'here',
            ],
        ],
    ],

请参阅 CHANGELOG 了解有关最近更改的更多信息,以及 CONTRIBUTING 了解贡献详情。

麻省理工学院许可证(MIT)。更多信息请参阅许可协议