-
Notifications
You must be signed in to change notification settings - Fork 1
/
FatalErrorCatch.php
50 lines (48 loc) · 1.24 KB
/
FatalErrorCatch.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
/**
* Extension for catching FATAL errors
* In configuration file main.php add this lines of code:
*
* 'preload'=>array('fatalerrorcatch',...),
* ...
* 'components'=>array(
* ...
* 'fatalerrorcatch'=>array(
* 'class'=>'ext.error.FatalErrorCatch',
* ),
*
* @author Rustam Gumerov <[email protected]>
* @link https://github.com/psrustik/yii-fatal-error-catch
*/
class FatalErrorCatch extends CApplicationComponent
{
/**
* Yii-action for error displaying.
* Better to use handlers from Yii because self-written handlers can have errors too :)
* @var mixed
*/
public $errorAction = null;
/**
* Errors types that we want to catch
* @var array
*/
public $errorTypes = array(E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING);
public function init()
{
register_shutdown_function(array($this, 'shutdownHandler'));
return parent::init();
}
/**
* Error handler
*/
public function shutdownHandler()
{
$e = error_get_last();
if ($e !== null && in_array($e['type'], $this->errorTypes))
{
$msg = 'Fatal error: ' . $e['message'];
Yii::app()->errorHandler->errorAction = $this->errorAction;
Yii::app()->handleError($e['type'], $msg, $e['file'], $e['line']);
}
}
}