cronfy/yii2-web-errorhandler

Yii2 customizable error handler

Installs: 29 867

Dependents: 0

Suggesters: 0

Security: 0

Stars: 4

Watchers: 1

Forks: 1

Open Issues: 0

Type:extension

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

This package is auto-updated.

Last update: 2024-04-29 02:40:28 UTC


README

Can be customized in terms of which error types should be converted to exceptions or only logged.

Installation

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

Usage

Replace errorHandler component in application configuration and configure error types you want to convert to exceptions or log. Default is E_ALL | E_STRICT.

Example:

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

This configuration will convert all php notices and warnings to exceptions only in debug mode, and none in production environment. Errors will be logged both in debug and production modes. You can customize error types that go to log or convereted to exceptions.

Errors are logged via internal Yii2 log component.

You can enable/disable ErrorHandler for particular error types by setting typesToHandle option. All error types not specified there will be forwarded to internal php error handler:

...
    '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,
        ],
    ],
...