cronfy/yii2-web-errorhandler

可定制的Yii2错误处理器

v0.0.1 2016-10-06 08:14 UTC

This package is auto-updated.

Last update: 2024-08-29 03:22:06 UTC


README

可以根据需要将哪些错误类型转换为异常或仅记录。

安装

php composer.phar require cronfy/yii2-web-errorhandler

使用方法

在应用程序配置中替换 errorHandler 组件,并配置您想要转换为异常或记录的错误类型。默认为 E_ALL | E_STRICT

示例

...
    'components' => [
        'errorHandler' => [
            'class' => 'cronfy\yii\web\ErrorHandler',
            'typesToExceptions' => YII_DEBUG ? (E_ALL | E_STRICT) : false,
            'typesToLog' => E_ALL | E_STRICT,
        ],
    ],
...

此配置将在调试模式下将所有PHP通知和警告转换为异常,在生产环境中不转换为异常。错误将在调试和生产模式下都进行记录。您可以自定义发送到日志或转换为异常的错误类型。

错误通过内部Yii2 log 组件进行记录。

您可以通过设置 typesToHandle 选项来启用/禁用特定错误类型的ErrorHandler。所有未在此处指定的错误类型都将转发到内部PHP错误处理器。

...
    'components' => [
        'errorHandler' => [
            'class' => 'cronfy\yii\web\ErrorHandler',
            'typesToHandle' => E_ALL & ~E_NOTICE,

	        // NOTE: although E_ALL is set here, PHP Notices will not be converted to exceptions, 
	        // because they were disabled via 'typesToHandle' option above.
	        // PHP Warnings and other errors will be converted to exceptions.
            'typesToExceptions' => E_ALL,
        ],
    ],
...