/
Error.php
119 lines (83 loc) · 3.17 KB
/
Error.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
<?PHP
class Plank_Error {
function __call($function, $message){
Plank_Error::defaultError('503', $message, $response);
}
static function Error503($message, $response){
Plank_Error::defaultError('503', $message, $response);
}
function defaultError($status, $message, $response){
$trace = debug_backtrace();
if(is_object($message) && is_subclass_of($message, 'Exception')){
$trace = $message->getTrace();
$message = $message->getMessage();
}
if(defined('DESTRUCT')){
die($message);
}
$view = new Plank_View('Errors', 'Error503');
$view->error = '
<p>Something\'s drastically wrong. Sorry about this, this is a last-ditch fail message, caused by terror upon terror to have been inflicted upon my poor innocent paradiems. Nothing\'s worked. The thing you asked for? Failed. The recovery from error system? Broken. The error display system itself? Fucked. I have no idea what to try next, so I\'m going to throw data at you until you go away.</p>
<h2>'.$message.'</h2>
';
$view->error .= Plank_Error::getBacktrace($trace);
$response->setContent($view->render());
$response->respond();
if(defined("TEXTMODE")){
echo "Uh-Oh\n";
echo striptags($view->error);
die();
} else {
echo Plank_Logger_Display::display();
}
}
function getBacktrace($trace = null){
if (is_null($trace)){
echo "<p>(Trace generated from inside Exception handler)</p>";
$trace = debug_backtrace();
}
#$trace = array_slice($trace, 1);
$output = '
<p><span style="color: #CCC">ħ</span> stands for <q>'.realpath(CODE_PATH."../").'</q> in the below:</p>
<table width="100%">
<tr><th>Function/Method</th><th>File</th><th>Line</th><th>Args</th></tr>';
$sprintf = '<tr><td>%s</td><td>%s</td><td>%s</td><td><a href="#" onClick="document.getElementById(\'%s\').style.display = \'block\'; this.style.display = \'none\'">Args</a><pre id="%s" style="display: none;">%s</pre></td></tr>';
foreach($trace as $t){
$function = isset($t['class']) ? $t['class']. $t['type']. $t['function'] : $t['function'];
$id = uniqid();
if (!defined("CODE_PATH")){
define("CODE_PATH", getcwd());
}
//$file = str_replace(getcwd(), 'CWD', $t['file']);
$file = $t['file'];
$file = str_replace(realpath(CODE_PATH), '[<acronym title="'.realpath(CODE_PATH).'">APP</acronym>]', $file);
$file = str_replace(realpath(PLANK_PATH), '[<acronym title="'.realpath(PLANK_PATH).'">PLK</acronym>]', $file);
$file = str_replace(getcwd(), 'CWD', $file);
if(isset($t['file'])){
$file = str_replace(realpath(CODE_PATH."../"), '<span style="color: #CCC">ħ</span>', $t['file']);
} else {
$file = "-";
}
if(isset($t['line'])){
$line = $t['line'];
} else {
$line = "-";
}
if(isset($t['args'])){
$args = Plank_Error::var_dump_string($t['args'],1);
} else {
$args = "[no arguments]";
}
$output .= sprintf($sprintf, $function, $file, $t['line'], $id, $id, $args);
}
$output .= '</table>';
return $output;
}
function var_dump_string($thing){
ob_start();
var_dump($thing);
$content = ob_get_contents();
ob_end_clean();
return $content;
}
}