fastd/debug
最新稳定版本:v2.0.3
Composer 安装命令:
composer require fastd/debug
包简介
error handle component.
关键字:
README 文档
README
支持自定义错误页面,自定义响应格式,响应头,支持 fatal error 捕捉,日志纪录等功能。
要求
- PHP 7+
Composer
{
"fastd/debug": "2.0.x-dev"
}
使用
use FastD\Debug\Debug; Debug::enable(); trigger_error('demo');
日志使用 Monolog\Logger, 完全自定义 Monolog\Logger 日志,直接注入到 FastD/Debug 对象中即可
$logger = new \Monolog\Logger('test'); $stream = new \Monolog\Handler\StreamHandler(__DIR__ . '/test.log'); $stream->setFormatter(new Monolog\Formatter\LineFormatter("[%datetime%] >> %level_name%: >> %message% >> %context% >> %extra%\n")); $logger->pushHandler($stream); $debug = \FastD\Debug\Debug::enable(false, $logger); throw new \Exception('test');
自定义错误页面内容
\FastD\Debug\Debug::enable(); class PageException extends \FastD\Debug\Exceptions\HttpException { /** * Returns response content. * * @return string */ public function getContent() { return file_get_contents(__DIR__ . '/demo.html'); } } throw new PageException('custom');
自定义错误页面使用自定义异常类一样的做法,可以更加灵活处理。
自定义异常
自定义异常只需要继承 FastD\Debug\Exceptions\Http\HttpException 对象,对类中的 getStatusCode, getHeaders, getContent 三个方法重写即可
可参考例子:
自定义响应格式: json.php 自定义页面: page.php
Testing
phpunit
License MIT
统计信息
- 总下载量: 2.22k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-06-24