yii2-extensions / debug
Yii框架的调试扩展
dev-main / 1.0.x-dev
2024-02-13 09:49 UTC
Requires
- php: >=8.1
- ext-intl: *
- ext-mbstring: *
- symfony/mime: ^6.3
- yiisoft/yii2: ^2.0.49 || ^2.2
- yiisoft/yii2-symfonymailer: ^4.0
Requires (Dev)
- maglnet/composer-require-checker: ^4.6
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^10.2
- rector/rector: ^0.19
- yii2-extensions/phpstan: dev-main
This package is auto-updated.
Last update: 2024-09-13 11:09:05 UTC
README
调试
安装
安装此扩展的首选方法是使用 composer。
运行以下命令之一
php composer.phar require --dev --prefer-dist yii2-extensions/debug
或者在您的 composer.json
文件的 require-dev 部分中添加
"yii2-extensions/debug": "dev-main"
。
用法
扩展安装完成后,只需按照以下方式修改您的应用程序配置
return [ 'bootstrap' => ['debug'], 'modules' => [ 'debug' => [ 'class' => 'yii\debug\Module', // uncomment and adjust the following to add your IP if you are not connecting from localhost. //'allowedIPs' => ['127.0.0.1', '::1'], ], // ... ], ... ];
您将在应用程序每个页面的底部看到调试工具栏。您可以点击工具栏以查看更详细的调试信息。
在IDE中打开文件
您可以使用此配置创建一个链接,在您喜欢的IDE中打开文件
return [ 'bootstrap' => ['debug'], 'modules' => [ 'debug' => [ 'class' => 'yii\debug\Module', 'traceLine' => '<a href="phpstorm://open?url={file}&line={line}">{file}:{line}</a>', // uncomment and adjust the following to add your IP if you are not connecting from localhost. //'allowedIPs' => ['127.0.0.1', '::1'], ], // ... ], ... ];
您需要修改您的操作系统。请参阅以下示例
- PHPStorm: https://github.com/aik099/PhpStormProtocol
- Windows 或 Linux 上的 Sublime Text 3: https://packagecontrol.io/packages/subl%20protocol
- Mac 上的 Sublime Text 3: https://github.com/inopinatus/sublime_url
虚拟化或docker化
如果您的应用程序在虚拟化或docker化环境中运行,通常情况下,应用程序的基本路径在虚拟机或容器内部与宿主机器不同。为了使链接在这些情况下工作,您可以配置 tracePathMappings
如此(更改为您应用程序的路径)
'tracePathMappings' => [ '/app' => '/path/to/your/app', ],
或者,您可以创建一个回调来控制 traceLine
'traceLine' => function($options, $panel) { $filePath = $options['file']; if (StringHelper::startsWith($filePath, Yii::$app->basePath)) { $filePath = '/path/to/your/app' . substr($filePath, strlen(Yii::$app->basePath)); } return strtr('<a href="ide://open?url=file://{file}&line={line}">{text}</a>', ['{file}' => $filePath]); },
使用 yiisoft/config 进行配置
将以下代码添加到您的应用程序中的
config/config-plugin
文件。
'config-plugin' => [ 'web' => [ '$yii2-debug', // add this line 'web/*.php' ], ],
要激活调试工具栏,请将以下代码添加到您的应用程序的
config/params.php
文件中。
return [ 'yii2.debug' => true, ];
要更改允许的IP,请将以下代码添加到您的应用程序的
config/params.php
文件中。
return [ 'yii2.debug.allowedIPs' => ['192.168.1.1'], ];
要添加类映射模块,请将以下代码添加到您的应用程序的
config/params.php
文件中。
use App\YourClass; return [ 'yii2.debug.classMap' => [ 'class' => YourClass::class, ], ];
测试
请参阅文档测试了解有关测试的信息。
支持的 Yii2 版本
代码质量
我们的社交媒体
许可
MIT 许可证。请参阅 许可证文件 了解更多信息。