patError.php
9.65 KB
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
<?php
/**
* patError error object used by the patFormsError manager as error messages
* container for precise error management.
*
* $Id: patError.php,v 1.5 2004/04/17 20:29:56 schst Exp $
*
* @access public
* @package patError
*/
/**
* patError error object used by the patFormsError manager as error messages
* container for precise error management.
*
* $Id: patError.php,v 1.5 2004/04/17 20:29:56 schst Exp $
*
* @access public
* @package patError
* @version 0.3
* @author gERD Schaufelberger <gerd@php-tools.net>
* @author Sebastian Mordziol <argh@php-tools.net>
* @author Stephan Schmidt <schst@php-tools.net>
* @license LGPL
* @link http://www.php-tools.net
*/
class patError
{
/**
* stores the error level for this error
*
* @access private
* @var string
*/
var $level = null;
/**
* stores the code of the error
*
* @access private
* @var string
*/
var $code = null;
/**
* stores the error message - this is the message that can also be shown the
* user if need be.
*
* @access private
* @var string
*/
var $message = null;
/**
* additional info that is relevant for the developer of the script (e.g. if
* a database connect fails, the dsn used) and that the end-user should not
* see.
*
* @access private
* @var string
*/
var $info = '';
/**
* stores the filename of the file the error occurred in.
*
* @access private
* @var string
*/
var $file = '';
/**
* stores the line number the error occurred in.
*
* @access private
* @var integer
*/
var $line = 0;
/**
* stores the name of the method the error occurred in
*
* @access private
* @var string
*/
var $function = '';
/**
* stores the name of the class (if any) the error occurred in.
*
* @access private
* @var string
*/
var $class = '';
/**
* stores the type of error, as it is listed in the error backtrace
*
* @access private
* @var string
*/
var $type = '';
/**
* stores the arguments the method that the error occurred in had received.
*
* @access private
* @var array
*/
var $args = array();
/**
* stores the complete debug backtrace (if your PHP version has the
* debug_backtrace function)
*
* @access private
* @var mixed
*/
var $backtrace = false;
/**
* constructor, wrapper for the upcoming PHP5 constructors for upward
* compatibility.
*
* @access public
* @param int $level The error level (use the PHP constants E_ALL, E_NOTICE etc.).
* @param string $code The error code from the application
* @param string $msg The error message
* @param string $info Optional: The additional error information.
* @see __construct()
*/
function patError( $level, $code, $msg, $info = null )
{
$this->__construct( $level, $code, $msg, $info );
}
/**
* constructor - used to set up the error with all needed error details.
*
* @access public
* @param int $level The error level (use the PHP constants E_ALL, E_NOTICE etc.).
* @param string $code The error code from the application
* @param string $msg The error message
* @param string $info Optional: The additional error information.
* @todo all calls to patErrorManager::raise* should not be included in backtrace
*/
function __construct( $level, $code, $msg, $info = null )
{
static $raise = array( 'raise',
'raiseerror',
'raisewarning',
'raisenotice'
);
$this->level = $level;
$this->code = $code;
$this->message = $msg;
if( $info != null )
{
$this->info = $info;
}
if( function_exists( 'debug_backtrace' ) )
{
$this->backtrace = debug_backtrace();
for( $i = count( $this->backtrace ) - 1; $i >= 0; --$i )
{
if( in_array( $this->backtrace[$i]['function'], $raise ) )
{
++$i;
if( isset( $this->backtrace[$i]['file'] ) )
$this->file = $this->backtrace[$i]['file'];
if( isset( $this->backtrace[$i]['line'] ) )
$this->line = $this->backtrace[$i]['line'];
if( isset( $this->backtrace[$i]['class'] ) )
$this->class = $this->backtrace[$i]['class'];
if( isset( $this->backtrace[$i]['function'] ) )
$this->function = $this->backtrace[$i]['function'];
if( isset( $this->backtrace[$i]['type'] ) )
$this->type = $this->backtrace[$i]['type'];
$this->args = false;
if( isset( $this->backtrace[$i]['args'] ) )
{
$this->args = $this->backtrace[$i]['args'];
}
break;
}
}
}
}
/**
* returns the error level of the error - corresponds to the PHP
* error levels (E_ALL, E_NOTICE...)
*
* @access public
* @return int $level The error level
* @see $level
*/
function getLevel()
{
return $this->level;
}
/**
* retrieves the error message
*
* @access public
* @return string $msg The stored error message
* @see $message
*/
function getMessage()
{
return $this->message;
}
/**
* retrieves the additional error information (information usually
* only relevant for developers)
*
* @access public
* @return mixed $info The additional information
* @see $info
*/
function getInfo()
{
return $this->info;
}
/**
* recieve error code
*
* @access public
* @return string|integer error code (may be a string or an integer)
* @see $code
*/
function getCode()
{
return $this->code;
}
/**
* get the backtrace
*
* This is only possible, if debug_backtrace() is available.
*
* @access public
* @return array backtrace
* @see $backtrace
*/
function getBacktrace()
{
return $this->backtrace;
}
/**
* get the filename in which the error occured
*
* This is only possible, if debug_backtrace() is available.
*
* @access public
* @return string filename
* @see $file
*/
function getFile()
{
return $this->file;
}
/**
* get the line number in which the error occured
*
* This is only possible, if debug_backtrace() is available.
*
* @access public
* @return integer line number
* @see $line
*/
function getLine()
{
return $this->line;
}
}
?>