1 |
<?php |
2 |
|
3 |
/** |
4 |
* This file contains some core functions extending php, |
5 |
* especially regarding basic error handling. |
6 |
* |
7 |
* @author Andreas Motl <andreas.motl@ilo.de> |
8 |
* @package org.netfrag.glib |
9 |
* @name errors |
10 |
* |
11 |
*/ |
12 |
|
13 |
/** |
14 |
* $Id: php_errors.php,v 1.1 2003/04/04 17:34:17 joko Exp $ |
15 |
* |
16 |
* $Log: php_errors.php,v $ |
17 |
* Revision 1.1 2003/04/04 17:34:17 joko |
18 |
* initial commit |
19 |
* |
20 |
* |
21 |
*/ |
22 |
|
23 |
|
24 |
/** |
25 |
* --- functions supporting handling errors/exceptions |
26 |
* |
27 |
*/ |
28 |
|
29 |
|
30 |
/** |
31 |
* --- php error extension functions living in the global namespace |
32 |
* |
33 |
* |
34 |
* @author Andreas Motl <andreas.motl@ilo.de> |
35 |
* @copyright (c) 2003 - All Rights reserved. |
36 |
* @license GNU LGPL (GNU Lesser General Public License) |
37 |
* |
38 |
* @link http://www.netfrag.org/~joko/ |
39 |
* @link http://www.gnu.org/licenses/lgpl.txt |
40 |
* |
41 |
* @package org.netfrag.glib |
42 |
* @name errors |
43 |
* |
44 |
* |
45 |
*/ |
46 |
|
47 |
//function error_handler($errno, $errstr, $errfile, $errline) { |
48 |
function php_error_handler() { |
49 |
|
50 |
// build error hash |
51 |
$error_raw = func_get_args(); |
52 |
$error = array( |
53 |
'level' => $error_raw[0], |
54 |
'message' => $error_raw[1], |
55 |
'file' => $error_raw[2], |
56 |
'line' => $error_raw[3], |
57 |
'context' => &$error_raw[4], |
58 |
'object_context' => &$error_raw[4][this], |
59 |
); |
60 |
$error[component] = $error[object_context]->_component_name; |
61 |
|
62 |
|
63 |
// component errors / stack-backtrace |
64 |
|
65 |
/* |
66 |
$level = $error[0]; |
67 |
$context = &$error[4]; |
68 |
$cc = &$context['this']; |
69 |
*/ |
70 |
|
71 |
// tracing |
72 |
//print Dumper($context); |
73 |
//print Dumper($cc); |
74 |
//print Dumper($cc->_component_name); |
75 |
|
76 |
// by level |
77 |
//$do_trace = ($level <= 5); |
78 |
|
79 |
//$c_name = $context['this']['_component_name']; |
80 |
|
81 |
//print "c_error: $c_name<br/>"; |
82 |
|
83 |
// if component |
84 |
//$do_trace = isset($context[this][_component_name]); |
85 |
//$do_trace = isset($context->this[_component_name]); |
86 |
//$do_trace = isset($cc->_component_name); |
87 |
|
88 |
//print Dumper($context); |
89 |
|
90 |
|
91 |
|
92 |
// V0 - testing (always on) |
93 |
//$do_trace = 1; |
94 |
|
95 |
// V1 - just for components |
96 |
//$do_trace = isset($error[component]); |
97 |
|
98 |
// V2 - actions via constant definition(s) |
99 |
$do_render = !constants::get('PHP_ERRORS_DISABLED') && constants::get('PHP_ERRORS_ENABLED'); |
100 |
$do_verbose = constants::get('PHP_ERRORS_MODE_VERBOSE'); |
101 |
$do_trace = constants::get('PHP_ERRORS_MODE_TRACE'); |
102 |
// ignore debugging-messages here if not explicitely requested |
103 |
if (!constants::get('PHP_ERRORS_TRACE_LEVEL_DEBUG')) { |
104 |
$do_verbose = $do_verbose && ($error[level] != 8); |
105 |
$do_trace = $do_trace && ($error[level] != 8); |
106 |
} |
107 |
|
108 |
|
109 |
// Rendering |
110 |
|
111 |
if ($do_render) { |
112 |
|
113 |
// which box to draw? |
114 |
|
115 |
// V1 - fixed set of error attributes |
116 |
//$output_order = array( 'message', 'component', 'file', 'line', 'level' ); |
117 |
//$output_order = array( 'message', 'level', 'file', 'line' ); |
118 |
|
119 |
// V2 - build variable set dependent on defined constant(s) |
120 |
$output_order = array(); |
121 |
$box_type = constants::get('PHP_ERRORS_BOX_TYPE'); |
122 |
//print "boxtype: $box_type<br/>"; |
123 |
switch ($box_type) { |
124 |
case 'full': |
125 |
$output_order = array( 'message', 'component', 'file', 'line', 'level' ); |
126 |
break; |
127 |
case 'medium': |
128 |
$output_order = array( 'message', 'level', 'file', 'line' ); |
129 |
break; |
130 |
default: |
131 |
$output_order = array( 'message', 'level' ); |
132 |
break; |
133 |
} |
134 |
|
135 |
//print php::Dumper($error); |
136 |
//exit; |
137 |
|
138 |
// dispatch color by level |
139 |
if ($error[level] <= 8) { |
140 |
$color = '#eeeeee'; |
141 |
} elseif ($error[level] == 512) { |
142 |
$color = 'orange'; |
143 |
} elseif ($error[level] == 1024) { |
144 |
$color = 'yellow'; |
145 |
} |
146 |
|
147 |
ob_start(); |
148 |
//print "<hr/><b><font color=\"red\">ERROR:</font></b><br/>"; |
149 |
print "<div style=\"background:$color; margin:4px; border:1px black groove; padding:2px;\"><b><font color=\"red\">Event:</font></b> [ErrorCode: $error[level]]<br/> "; |
150 |
foreach ($output_order as $key) { |
151 |
print "<b>$key:</b> $error[$key]<br/>"; |
152 |
} |
153 |
print "</div>\n"; |
154 |
$out = ob_get_contents(); |
155 |
ob_end_clean(); |
156 |
|
157 |
if ($do_trace) { |
158 |
if (loadModule('Tracer')) { |
159 |
trace($out); |
160 |
} |
161 |
} |
162 |
|
163 |
if ($do_verbose) { |
164 |
print $out; |
165 |
} |
166 |
|
167 |
} |
168 |
|
169 |
} |
170 |
|
171 |
|
172 |
?> |