-
Notifications
You must be signed in to change notification settings - Fork 2
/
cError.php
131 lines (114 loc) · 2.32 KB
/
cError.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
/* $Id: cError.php,v 0.1 2010/10/14 20:23:12 aedavies Exp $ */
require_once("cIP.php");
require_once("cLogger.php");
/**
* Error interface.
*/
interface iError {
/* protected methods inherited from Exception class */
public function getMessage();
public function getCode();
public function getFile();
public function getLine();
public function getTrace();
public function getTraceAsString();
// overrideable methods
public function __construct($code, $message = '');
public function __toString();
// new methods
public function log();
public static function showerror($msg);
}
class cError extends Exception implements iError {
/**
* Current environment, taken from the config file.
*
* @var string
*/
public static $environment;
/**
* Error code.
*
* @var int
*/
protected $code = 0;
/**
* Error message.
*
* @var string
*/
protected $message = '';
/**
* Filename where error occurred.
*
* @var string
*/
protected $file;
/**
* Line where error occurred.
*
* @var int
*/
protected $line;
/**
* Error constructor.
*
* @param int $code Error code
* @param string $message Error message
*/
public function __construct($code, $message='')
{
if (empty(self::$environment)) {
self::$environment = cConf::get('ENVIRONMENT');
}
parent::__construct($message, $code);
}
/**
* String casting.
*
* @return string Error message
*/
public function __toString()
{
return get_class($this).'('.$this->message.')';
}
/**
* Error log.
*/
public function log()
{
cLogger::log("error", array(
"code" => $this->code,
"message" => $this->message,
"file" => $this->file,
"line" => $this->line));
}
public static function showerror( $msg )
{
cLogger::showerror( $msg );
}
}
/**
* Exteption handler.
*
* @param Exception $exception Exception class.
*/
function exception_handler($exception)
{
$exception->log();
}
set_exception_handler("exception_handler");
/* Amen-ra error handler */
function error_handler($severity, $msg, $filename, $linenum)
{
cLogger::log("error", array(
"code" => $severity,
"message" => $msg,
"file" => $filename,
"line" => $linenum));
/* Don't execute PHP internal error handler */
return (true);
}
set_error_handler("error_handler");
?>