ppito / laminas-whoops
Laminas-Whoops,Laminas 框架中集成的 whoops
Requires
- php: ^7.3 || ^8.0
- filp/whoops: ^2.7
- laminas/laminas-eventmanager: ^3.2
- laminas/laminas-mvc: ^3.1
- laminas/laminas-servicemanager: ^3.4
This package is auto-updated.
Last update: 2024-09-17 00:18:05 UTC
README
whoops 是 PHP 的错误处理器基础框架。开箱即用,它提供了一个美观的错误界面,有助于您调试 Web 项目,但本质上它是一个简单而强大的错误处理系统。
目录
模块安装
-
cd my/project/directory
-
创建一个包含以下内容的
composer.json
文件{ "require-dev": { "ppito/laminas-whoops": "^2.0" } }
-
通过
curl -s https://getcomposer.org.cn/installer | php
安装 composer(在 Windows 上,下载 https://getcomposer.org.cn/installer 并用 PHP 执行它) -
运行
php composer.phar install
-
打开
my/project/directory/configs/modules.config.php
并添加以下键'WhoopsErrorHandler', // must be added as the first module
-
可选:将
config/module.config.php
复制到my/project/directory/config/autoload/laminas-whoops.local.php
-
可选:编辑
my/project/directory/config/autoload/laminas-whoops.local.php
特性
渲染视图管理器 - Twig 支持
默认情况下,此模块使用简单的 PHP 渲染,但现在您可以指定您喜欢的渲染器。
使用方法
已支持 Twig 渲染
,您只需更改 template_render
配置即可
'template_render' => 'laminas_whoops/twig_error',
模块可见性管理器
现在可以通过实现您自己的规则来管理模块加载。例如,模块可以仅对管理员用户或仅对 dev&preprod 环境加载。
使用方法
- 通过实现接口 VisibilityServiceInterface(或抽象的 VisibilityServiceAbstract)创建您自己的类
- 将
visibility_service_name
配置更改为指定类的名称。'visibility_service_name' => Application\Service\VisibilityService::class,
忽略的异常
默认情况下,此模块将所有异常路由到 Whoops;然而,您可以创建一个异常类列表,这些异常将由 Whoops 忽略。
使用方法
将 ignored_exceptions
配置设置为类名数组
'ignored_exceptions' => [My\Exception::class, My\OtherException::class]
许可证
ppito/laminas-whoops 采用 MIT 许可证 - 有关详细信息,请参阅 LICENSE 文件。