-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.php
More file actions
206 lines (179 loc) · 6.09 KB
/
Copy pathdebug.php
File metadata and controls
206 lines (179 loc) · 6.09 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
<?php
/*
Copyright (C) 2004-2005 Samuel J. Greear. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
$Id: debug.php 288 2006-01-03 00:50:47Z ryan $
*/
/*
<debug>
<array type="php">
<name></name>
<variable>
<name></name>
<value></value>
</variable>
<array>
<name></name>
<variable>
<name></name>
<value></value>
</variable>
</array>
</array>
<array type="app">
<name></name>
...
</array>
<string type="app">blabla</string>
<string type="info">blabla</string>
<string type="php">blabla</string>
</debug>
*/
$_DEBUG = Array();
for ($i = 0; $i < 10; $i++)
$_DEBUG[$i] = Array();
global $_DEBUG;
function ex_debug($str, $level=1) {
global $_DEBUG;
$_DEBUG[$level][] = $str;
}
$_INFO = Array();
global $_INFO;
function ex_info($str) {
global $_INFO;
$_INFO[] = $str;
}
class Debug extends XMLement {
function __construct() {
parent::__construct('debug', NULL, 'debug');
global $_CONF, $_APPREQ, $_FORM, $_DEBUG, $_INFO;
$level = $_CONF['debug_level'];
$this->BuildStrings($_INFO, 'info');
if ($level >= 1) {
$this->BuildArray($_GET, 'GET', 'php');
$this->BuildArray($_POST, 'POST', 'php');
$this->BuildArray($_FILES, 'FILES', 'php');
$this->BuildArray($_SESSION, 'SESSION', 'php');
$this->BuildStrings($_DEBUG[1], 'app');
}
if ($level >= 2) {
// Application-specific
$this->BuildArray($_APPREQ, 'APPREQ', 'app');
$this->BuildArray($_CONF, 'CONF', 'app');
$this->BuildArray($_FORM, 'FORM', 'app');
$this->BuildStrings($_DEBUG[2], 'app');
}
if ($level >= 3)
$this->BuildStrings($_DEBUG[3], 'app');
if ($level >= 4)
$this->BuildArray($_SERVER, 'SERVER', 'php');
}
function BuildStrings($strarr, $type, $level=NULL) {
if ($level == NULL)
foreach ($strarr as $key => $value) {
$element = $this->ForkChild('string', $value);
$element->SetAttribute('type', $type);
$this->AddChild($element);
}
}
function BuildVariable($name, $value) {
$element = $this->ForkChild('variable');
$element->AddElement('name', (string)$name);
$element->AddElement('value', (string)$value);
return $element;
}
function BuildArray($array, $name=NULL, $type=NULL, $parent=NULL) {
if (!is_array($array)) {
return false; }
if (count($array) == 0)
return false;
$element = $this->ForkChild('array');
if ($name != NULL)
$element->AddElement('name', $name);
if ($type != NULL)
$element->SetAttribute('type', $type);
foreach ($array as $name => $value) {
if ($this->BuildArray($value, $name, NULL, $element) == false) {
if (is_array($value))
$value = 'Empty Array';
$variable = $this->BuildVariable($name, $value);
$element->AddChild($variable);
}
}
if ($parent == NULL)
$this->AddChild($element);
else
$parent->AddChild($element);
return true;
}
}
// XXX: Temporary
function backtrace($backtrace)
{
$output = "<div class=\"backtrace\">\n";
$output .= "<b class=\"header\">Backtrace:</b><br />\n";
// $backtrace = debug_backtrace();
foreach ($backtrace as $bt) {
$args = '';
if (is_array($bt['args']))
foreach ($bt['args'] as $a) {
if (!empty($args)) {
$args .= ', ';
}
switch (gettype($a)) {
case 'integer':
case 'double':
$args .= $a;
break;
case 'string':
$a = htmlspecialchars(substr($a, 0, 64)).((strlen($a) > 64) ? '...' : '');
$args .= "\"$a\"";
break;
case 'array':
$args .= 'Array('.count($a).')';
break;
case 'object':
$args .= 'Object('.get_class($a).')';
break;
case 'resource':
$args .= 'Resource('.strstr($a, '#').')';
break;
case 'boolean':
$args .= $a ? 'True' : 'False';
break;
case 'NULL':
$args .= 'Null';
break;
default:
$args .= 'Unknown';
}
}
if (!array_key_exists('class', $bt)) $bt['class'] = '';
if (!array_key_exists('type', $bt)) $bt['type'] = '';
if (!array_key_exists('function', $bt)) $bt['function'] = '';
$output .= "<br />\n";
$output .= "<b>file:</b> {$bt['line']} - {$bt['file']}<br />\n";
$output .= "<b>call:</b> {$bt['class']}{$bt['type']}{$bt['function']}($args)<br />\n";
}
$output .= "</div>\n";
return $output;
}
?>