-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexception.php
57 lines (52 loc) · 2.01 KB
/
exception.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
<?php
/* This plugin displays a user friendly page on uncaught PHP exceptions. */
set_exception_handler(function ($exception) use ($context) {
while (ob_get_level()) {
ini_get("display_errors") == 1 ? ob_end_flush() : ob_end_clean();
}
error_log(sprintf("%s in %s:%d\n%s",
$exception->getMessage(),
$exception->getFile(), $exception->getLine(),
$exception->getTraceAsString()));
http_response_code(500);
$context->hooks->echo_empty([
"bodyAttributes" => ["class" => "middle body_full"],
"body" => $context->hooks->template("exception", [
"exception" => $exception,
"showMessage" =>
($exception instanceof Kanbani\PublicException) ||
($exception instanceof Kanbani\SyncFileException) ||
($exception instanceof Kanbani\QrCodeException) ||
!empty($exception->kwvIsPublic),
]),
]);
});
$context->hooks->register("echo_exception", function (array $vars) {
// $exception
// $showMessage
extract($vars);
?>
<article class="ex middle__out">
<div class="ex__wr middle__in">
<?php if ($showMessage) {?>
<p><?=htmlspecialchars($this($exception->getMessage()))?></p>
<?php } else {?>
<h1><?=$this("No way!")?></h1>
<p>
<?=$this(
"You hit an unexpected %s – contact us for assistance.",
htmlspecialchars(preg_replace('/([a-z])([A-Z])/', '\1 \2', basename(get_class($exception))))
)?>
</p>
<?php }?>
<?php if (ini_get("display_errors") == 1) {?>
<textarea readonly class="ex__trace light-shade block-area">
<?=htmlspecialchars($exception->getMessage())?>
in <?=htmlspecialchars($exception->getFile().":".$exception->getLine())?>
<?=htmlspecialchars($exception->getTraceAsString())?>
</textarea>
<?php }?>
</div>
</article>
<?php
});