-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.php
320 lines (265 loc) · 8.65 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
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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
<?php
/**
* error.php
*
* Genetic error page. Used when page haven't registered its own
* error page.
*
* @author Belikhun
* @since 1.0.0
* @license https://tldrlegal.com/license/mit-license MIT
*
* Copyright (C) 2018-2023 Belikhun. All right reserved
* See LICENSE in the project root for license information.
*/
use Blink\BacktraceFrame;
use Blink\ErrorPage\Instance;
use Blink\ErrorPage\Renderer;
use Blink\HtmlWriter;
use Blink\URL;
/** @var \Blink\ErrorPage\Instance */
$instance = $_SESSION["LAST_ERROR"];
list($statusText, $description, $details) = $instance -> info();
list($tipTitle, $tipContent) = $instance -> tips();
$status = $instance -> status;
$sticker = new URL(getRelativePath(CORE_ROOT . "/public/stickers/" . $instance -> sticker()));
$exception = $instance -> exception();
$basePublic = new URL(getRelativePath(CORE_ROOT . "/public"));
$tipDeco = new URL(getRelativePath(CORE_ROOT . "/public/imgs/tip-deco.svg"));
$statusColor = match ($instance -> type()) {
Instance::ERROR_CLIENT => "yellow",
Instance::ERROR_SERVER => "red",
default => "green"
};
$class = (!empty($exception) && !empty($exception["class"]))
? $exception["class"]
: null;
/** @var BacktraceFrame[] */
$stacktrace = $instance -> stacktrace();
$contexts = $instance -> contexts;
http_response_code($status);
header("Access-Control-Allow-Private-Network: true");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="<?php echo $basePublic; ?>/default.css">
<link rel="stylesheet" href="<?php echo $basePublic; ?>/error.css">
<title><?php echo (!empty($class) ? $class : $statusText) . ": {$description}"; ?></title>
</head>
<body>
<div id="app">
<header>
<div class="top">
<div class="inner">
<span class="left">
<a class="link" href="#stacktrace" target="_self" nav-link>
<?php echo Renderer::icon("stack"); ?>
Stack
</a>
<a class="link" href="#context" target="_self" nav-link>
<?php echo Renderer::icon("context"); ?>
Context
</a>
</span>
<span class="right">
<a class="link" data-report-link="<?php echo $instance -> url(); ?>">
<?php echo Renderer::icon("link"); ?>
<span>Copy report link</span>
</a>
</span>
</div>
</div>
<div class="bottom">
<div class="inner">
<span class="truncate">
<?php echo strip_tags($description, [ "code", "b", "i", "u" ]); ?>
</span>
</div>
</div>
</header>
<div class="content">
<div id="details" class="panel">
<div class="flex flex-row flex-g1 info">
<?php if (CONFIG::$W_MODE) { ?>
<video id="sticker" src="<?php echo $sticker -> out(false); ?>" autoplay loop></video>
<?php } ?>
<span class="flex-g1 block exception">
<div class="flex flex-row align-center justify-between flex-wrap top">
<span class="badges flex flex-row align-center flex-wrap">
<span class="badge status" data-color="<?php echo $statusColor; ?>">
<?php echo $status; ?>
</span>
<?php if (!empty($class)) { ?>
<span class="badge class">
<?php echo str_replace("\\", "<span>\</span>", $class); ?>
</span>
<?php } ?>
</span>
<span class="versions flex flex-row align-center">
<span>
<span class="wider">PHP</span>
<?php echo $instance -> php; ?>
</span>
<?php if (!empty($instance -> server)) { ?>
<span>
<?php echo Renderer::icon("server"); ?>
<?php echo $instance -> server; ?>
</span>
<?php } ?>
<span>
<?php echo Renderer::icon("blink"); ?>
<?php echo $instance -> blink; ?>
</span>
</span>
</div>
<div class="description"><?php echo strip_tags($description, [ "code", "b", "i", "u" ]); ?></div>
<?php if (!empty($details)) { ?>
<div class="details"><?php echo $details; ?></div>
<?php } ?>
</span>
</div>
<?php if (!empty($tipTitle)) { ?>
<div class="flex flex-row flex-g0 tips active" toggle-target="tip1">
<div class="block tip" style="background-image: url('<?php echo $tipDeco -> out(true); ?>')">
<div class="title"><?php echo $tipTitle; ?></div>
<div class="content"><?php echo $tipContent; ?></div>
</div>
<div class="close active" toggle-id="tip1">
<?php echo Renderer::icon("close"); ?>
</div>
</div>
<?php } ?>
</div>
</div>
<?php if (!empty($stacktrace)) { ?>
<div id="stacktrace" class="content">
<div class="flex flex-row panel">
<span class="flex flex-col flex-g0 left">
<div class="header">
<b>Frames</b>
</div>
<div class="frames">
<?php
$foundfault = false;
foreach ($stacktrace as $i => $trace) {
$attrs = array(
"class" => ["frame", "flex", "flex-col", "align-start", "text-sm"]
);
if (!empty($trace -> file)) {
$attrs["toggle-id"] = $trace -> getID();
$attrs["toggle-name"] = "stacktrace";
if (!$foundfault && $trace -> fault) {
$attrs["toggle-default"] = true;
$attrs["class"][] = "active";
$foundfault = true;
}
echo HtmlWriter::startDIV($attrs);
$badges = array();
if ($trace -> isVendor()) {
$badges[] = HtmlWriter::span(
array( "class" => "badge vendor" ),
"vendor"
);
}
if ($trace -> isBlink()) {
$badges[] = HtmlWriter::span(
array( "class" => "badge blink" ),
"blink"
);
}
if ($trace -> fault) {
$badges[] = HtmlWriter::span(
array( "class" => "badge fault" ),
"fault"
);
}
if (!empty($badges)) {
echo HtmlWriter::div(
array( "class" => "badges" ),
implode("", $badges)
);
}
echo HtmlWriter::div(
array( "class" => "path" ),
$trace -> file . "<code>:{$trace -> line}</code>");
} else {
echo HtmlWriter::startDIV($attrs);
}
echo HtmlWriter::div(array(
"class" => "font-semibold"
), $trace -> getCallString());
foreach ($trace -> args as $i => $arg) {
$prefix = "args[{$i}] = ";
if (is_array($arg)) {
echo HtmlWriter::code(
array( "class" => "arg" ),
"$prefix <b>{$arg[0]}</b> " . htmlspecialchars($arg[1])
);
continue;
}
echo HtmlWriter::code(
array( "class" => "arg" ),
htmlspecialchars($prefix . $arg));
}
echo HtmlWriter::endDIV();
}
?>
<div class="space"></div>
</div>
</span>
<span class="flex flex-col flex-g1 viewer">
<?php
$foundfault = false;
foreach ($stacktrace as $trace) {
if (empty($trace -> file))
continue;
$attrs = array(
"class" => ["flex", "flex-col", "view"],
"toggle-target" => $trace -> getID()
);
if (!$foundfault && $trace -> fault) {
$attrs["class"][] = "active";
$foundfault = true;
}
echo HtmlWriter::startDIV($attrs);
echo HtmlWriter::startDIV(array(
"class" => "header text-sm font-semibold"
));
echo HtmlWriter::a(
"vscode://file/" . urlencode($trace -> getFullPath() . ":{$trace -> line}"),
$trace -> file . "<code>:{$trace -> line}</code>",
array( "class" => "open-file" )
);
echo HtmlWriter::endDIV();
echo renderSourceCode($trace -> getFullPath(), $trace -> line, 27);
echo HtmlWriter::endDIV();
}
?></span>
</div>
</div>
<?php } ?>
<div id="context" class="content">
<div class="nav">
<?php foreach ($contexts as $group)
$group -> renderNavigation(); ?>
</div>
<div class="panel">
<?php foreach ($contexts as $group)
$group -> render(); ?>
</div>
</div>
<div id="footer" class="content">
Report ID: <?php echo $instance -> id; ?>
<span class="separator">//</span>
<span>
✨ <a href="<?php echo CONFIG::$BLINK_URL; ?>" target="_blank">blink</a> by Belikhun
</span>
</div>
</div>
<script src="<?php echo $basePublic; ?>/error.js"></script>
</body>
</html>