|
1
|
|
|
<?php |
|
2
|
|
|
$defflip = (!cfip()) ? exit(header('HTTP/1.1 401 Unauthorized')) : 1; |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* This file defines the debug class used in this site to enable |
|
6
|
|
|
* verbose deugging outout. |
|
7
|
|
|
* @package debug |
|
8
|
|
|
* @author Sebastian 'Seraph' Grewe |
|
9
|
|
|
* @copyright Sebastian Grewe |
|
10
|
|
|
* @version 1.0 |
|
11
|
|
|
* */ |
|
12
|
|
|
class Debug { |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @var integer $DEBUG enable (1) or disable (0) debugging |
|
16
|
|
|
*/ |
|
17
|
|
|
private $DEBUG; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var array $debugInfo Data array with debugging information |
|
21
|
|
|
*/ |
|
22
|
|
|
private $arrDebugInfo; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var float $startTime Start time of our debugger |
|
26
|
|
|
*/ |
|
27
|
|
|
private $floatStartTime; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Construct our class |
|
31
|
|
|
* @param integer $DEBUG [optional] Enable (>=1) or disable (0) debugging |
|
32
|
|
|
* @return none |
|
|
|
|
|
|
33
|
|
|
*/ |
|
34
|
|
|
function __construct($log, $DEBUG=0) { |
|
|
|
|
|
|
35
|
|
|
$this->log = $log; |
|
|
|
|
|
|
36
|
|
|
$this->DEBUG = $DEBUG; |
|
37
|
|
|
if ($DEBUG >= 1) { |
|
38
|
|
|
$this->floatStartTime = microtime(true); |
|
39
|
|
|
$this->append("Debugging enabled", 1); |
|
40
|
|
|
} |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* If we want to set our debugging level in a child class this allows us to do so |
|
45
|
|
|
* @param integer $DEBUG our debugging level |
|
46
|
|
|
*/ |
|
47
|
|
|
function setDebug($DEBUG) { |
|
|
|
|
|
|
48
|
|
|
$this->DEBUG = $DEBUG; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Return a backtrace strin |
|
53
|
|
|
* @return string Full backtrace <file>:<line> but no refereces to debug class |
|
54
|
|
|
*/ |
|
55
|
|
|
public function getBacktrace() { |
|
56
|
|
|
$bth = debug_backtrace(); |
|
57
|
|
|
while (strpos($bth[0]['file'], "classes/debug") != false) array_shift($bth); |
|
|
|
|
|
|
58
|
|
|
foreach ($bth as $x) { |
|
59
|
|
|
$backtrace[] = array( |
|
|
|
|
|
|
60
|
|
|
'file' => substr($x['file'], strrpos($x['file'], '/') + 1), |
|
61
|
|
|
'line' => $x['line'], |
|
62
|
|
|
'function' => $x['function'], |
|
63
|
|
|
); |
|
64
|
|
|
} |
|
65
|
|
|
return $backtrace; |
|
|
|
|
|
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* We fill our data array here |
|
70
|
|
|
* @param string $msg Debug Message |
|
71
|
|
|
* @param string $file [optional] File name |
|
|
|
|
|
|
72
|
|
|
* @param integer $line [optional] Line inside the $file |
|
|
|
|
|
|
73
|
|
|
* @param integer $debug [optional] Debugging level, default 1 |
|
74
|
|
|
* @param string $class [optional] Class this is called from |
|
|
|
|
|
|
75
|
|
|
* @param string $method [optional] Method this is called from |
|
|
|
|
|
|
76
|
|
|
* @return none |
|
77
|
|
|
*/ |
|
78
|
|
|
function append($msg, $debug=1) { |
|
|
|
|
|
|
79
|
|
|
if ($this->DEBUG >= $debug) { |
|
80
|
|
|
$this->arrDebugInfo[] = array( |
|
81
|
|
|
'level' => $debug, |
|
82
|
|
|
'time' => round((microtime(true) - $this->floatStartTime) * 1000, 2), |
|
83
|
|
|
'backtrace' => $this->getBacktrace(), |
|
84
|
|
|
'message' => $msg, |
|
85
|
|
|
); |
|
86
|
|
|
$this->log->log("debug", $msg); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Return the created strDebugInfo array |
|
92
|
|
|
* @return none |
|
93
|
|
|
*/ |
|
94
|
|
|
public function getDebugInfo() { |
|
95
|
|
|
return $this->arrDebugInfo; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Directly print the debugging information, table formatted |
|
100
|
|
|
* @return none |
|
101
|
|
|
*/ |
|
102
|
|
|
function printDebugInfo() { |
|
|
|
|
|
|
103
|
|
|
echo "<table><tr><td>Timestamp</td><td>File</td><td>Line</td><td>Class</td><td>Method</td><td>Message</td></tr>"; |
|
104
|
|
|
foreach ($this->getDebugInfo() as $content) { |
|
105
|
|
|
echo "<tr><td>" . $content['time'] . "</td><td>" . $content['backtrace'] . "</td><td>" . $content['message'] . "</td></tr>"; |
|
106
|
|
|
} |
|
107
|
|
|
echo "</table>"; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
// Instantiate this class |
|
113
|
|
|
$debug = new Debug($log, $config['DEBUG']); |
|
114
|
|
|
|
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.