fastd / debug
错误处理组件。
v2.0.3
2017-03-24 09:21 UTC
Requires
- php: >=7.0
- maximebf/debugbar: ^1.12
- monolog/monolog: *
Requires (Dev)
- fastd/config: ~2.0.0@beta
- fastd/database: ~2.0.0@beta
- phpunit/phpunit: 5.0
This package is auto-updated.
Last update: 2024-09-13 13:41:03 UTC
README
支持自定义错误页面,自定义响应格式,响应头,支持致命错误捕捉,日志记录等功能。
要求
- 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
测试
phpunit