struzik-vladislav/php-error-handler
最新稳定版本:v1.0.2
Composer 安装命令:
composer require struzik-vladislav/php-error-handler
包简介
Handling PHP errors (Notice, Warning, etc.)
README 文档
README
Handling PHP errors in various processors.
Types of errors that can be handled according to set_error_handler:
- E_STRICT
- E_RECOVERABLE_ERROR
- E_NOTICE
- E_WARNING
- E_DEPRECATED
- E_USER_ERROR
- E_USER_NOTICE
- E_USER_WARNING
- E_USER_DEPRECATED
Processors
ReturnFalseProcessor
The processor for enabling native PHP handler after custom.
LoggerProcessor
The processor for writing to the PSR-3 compatible logger like Monolog.
IntoExceptionProcessor
The processor for converting errors to exceptions. The basic type of throwing exception is Struzik\ErrorHandler\Exception\ErrorException.
Usage
<?php use Struzik\ErrorHandler\ErrorHandler; use Struzik\ErrorHandler\Processor\LoggerProcessor; use Struzik\ErrorHandler\Processor\IntoExceptionProcessor; use Struzik\ErrorHandler\Exception\ErrorException; use Monolog\Logger; use Monolog\Handler\StreamHandler; $logger = new Logger('ErrorHandler DEMO'); $logger->pushHandler(new StreamHandler('php://output', Logger::DEBUG)); $errorHandler = new ErrorHandler(); $errorHandler->pushProcessor(new IntoExceptionProcessor()) ->pushProcessor(new LoggerProcessor($logger)); try { $errorHandler->set(); trigger_error('Dummy error', E_USER_NOTICE); $errorHandler->restore(); } catch (ErrorException $e) { echo $e; } /* [2017-05-13 21:42:46] ErrorHandler DEMO.NOTICE: Dummy error in /srv/php-error-handler/example.php:21 {"backtrace":"#0 /srv/php-error-handler/src/ErrorHandler.php(39): Struzik\\ErrorHandler\\Processor\\LoggerProcessor->handle(1024, 'Dummy error', '/srv/php-error-...', 21)\n#1 [internal function]: Struzik\\ErrorHandler\\ErrorHandler->handle(1024, 'Dummy error', '/srv/php-error-...', 21, Array)\n#2 /srv/php-error-handler/example.php(21): trigger_error('Dummy error', 1024)\n#3 {main}"} [] Struzik\ErrorHandler\Exception\UserNoticeException: Dummy error in /srv/php-error-handler/example.php:21 Stack trace: #0 /srv/php-error-handler/src/ErrorHandler.php(39): Struzik\ErrorHandler\Processor\IntoExceptionProcessor->handle(1024, 'Dummy error', '/srv/php-error-...', 21) #1 [internal function]: Struzik\ErrorHandler\ErrorHandler->handle(1024, 'Dummy error', '/srv/php-error-...', 21, Array) #2 /srv/php-error-handler/example.php(21): trigger_error('Dummy error', 1024) */
统计信息
- 总下载量: 13.01k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-05-13