/
RTError.php
109 lines (93 loc) · 3.21 KB
/
RTError.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php // RTError
/**
* An open source PHP library collection
*
* @category RoboTamer
* @author Dennis T Kaplan
* @copyright Copyright (c) 2008 - 2011, Dennis T Kaplan
* @license http://www.RoboTamer.com/license.html
* @link http://www.RoboTamer.com
**/
/**
* @category RoboTamer
* @package RTError
* @author Dennis T Kaplan
* @copyright Copyright (c) 2008 - 2011, Dennis T Kaplan
* @license http://www.RoboTamer.com/license.html
* @link http://www.RoboTamer.com
**/
class RTError extends ErrorException {
protected $vars;
protected $codes = array
(
E_ERROR => 'Error',
E_USER_ERROR => 'User Error',
E_PARSE => 'Parse Error',
E_WARNING => 'Warning',
E_USER_WARNING => 'User Warning',
E_STRICT => 'Strict',
E_NOTICE => 'Notice',
E_RECOVERABLE_ERROR => 'Recoverable Error',
);
function __construct($message, $code = null, $severity = E_ERROR, $filename = null, $line= null, array $vars = array())
{
parent::__construct($message, $code, $severity, $filename, $line);
$this->message = $message;
$this->code = isset($this->codes[$code]) ? $this->codes[$code] : $code;
$this->severity = $severity;
$this->file = $filename;
$this->line = $line;
$this->vars = $vars;
$this->logErrors() ;
}
protected function logErrors()
{
$msg = $this->message .' | '. $this->file . ' #'. $this->line ;
RTLog::set($msg,$this->code);
}
/**
* Return array that points to the active symbol table at the point the error
* occurred. In other words, it will contain an array of every variable that
* existed in the scope the error was triggered in.
*
* @return array
*/
public function getVars()
{
return $this->vars;
}
/**
* Set Zend_Exception::errorHandler() as error handling function.
*
* @param integer $error_types (optional) used to mask the triggering of the Zend_Exception::errorHandler() function.
* @return boolean
*/
public static function setErrorHandler($error_types = E_ALL)
{
set_error_handler('Error::errorHandler', (int) $error_types);
set_exception_handler('Error::exceptionHandler');
return true;
}
/**
* Error handling function. Used by Error::setErrorHandler()
*
* @param integer $errno Level of the error raised
* @param string $errstr Error message
* @param string $errfile Filename that the error was raised in
* @param integer $errline Line number the error was raised at
* @param array $context Array that points to the active symbol table at the
* point the error occurred
* @throws Zend_Exception
* @return void
*/
public static function errorHandler($errno = E_ERROR, $errstr, $errfile, $errline, $context)
{
throw new Error($errstr, 0, $errno, $errfile, $errline, $context);
}
public static function exceptionHandler($exception) {
$msg = $exception->getMessage() .' | '. $exception->getFile() . ' #'. $exception->getLine() ;
RTLog::set($msg,get_class($exception));
}
} // End Error
RTError::setErrorHandler();
?>