Update error.tpl

This commit is contained in:
邹景立 2021-03-24 17:47:48 +08:00
parent 7030c900d9
commit 6def8f617d

View File

@ -13,80 +13,80 @@ if (!function_exists('parse_class')) {
{ {
$names = explode('\\', $name); $names = explode('\\', $name);
return '<abbr title="' . $name . '">' . end($names) . '</abbr>'; return '<abbr title="' . $name . '">' . end($names) . '</abbr>';
} }
} }
if (!function_exists('parse_file')) { if (!function_exists('parse_file')) {
function parse_file($file, $line) function parse_file($file, $line)
{ {
return '<a class="toggle" title="' . "{$file} line {$line}" . '">' . basename($file) . " line {$line}" . '</a>'; return '<a class="toggle" title="' . "{$file} line {$line}" . '">' . basename($file) . " line {$line}" . '</a>';
} }
} }
if (!function_exists('parse_args')) { if (!function_exists('parse_args')) {
function parse_args($args) function parse_args($args)
{ {
$result = []; $result = [];
foreach ($args as $key => $item) { foreach ($args as $key => $item) {
switch (true) { switch (true) {
case is_object($item): case is_object($item):
$value = sprintf('<em>object</em>(%s)', parse_class(get_class($item))); $value = sprintf('<em>object</em>(%s)', parse_class(get_class($item)));
break; break;
case is_array($item): case is_array($item):
if (count($item) > 3) { if (count($item) > 3) {
$value = sprintf('[%s, ...]', parse_args(array_slice($item, 0, 3))); $value = sprintf('[%s, ...]', parse_args(array_slice($item, 0, 3)));
} else { } else {
$value = sprintf('[%s]', parse_args($item)); $value = sprintf('[%s]', parse_args($item));
} }
break; break;
case is_string($item): case is_string($item):
if (strlen($item) > 20) { if (strlen($item) > 20) {
$value = sprintf( $value = sprintf(
'\'<a class="toggle" title="%s">%s...</a>\'', '\'<a class="toggle" title="%s">%s...</a>\'',
htmlentities($item), htmlentities($item),
htmlentities(substr($item, 0, 20)) htmlentities(substr($item, 0, 20))
); );
} else { } else {
$value = sprintf("'%s'", htmlentities($item)); $value = sprintf("'%s'", htmlentities($item));
} }
break; break;
case is_int($item): case is_int($item):
case is_float($item): case is_float($item):
$value = $item; $value = $item;
break; break;
case is_null($item): case is_null($item):
$value = '<em>null</em>'; $value = '<em>null</em>';
break; break;
case is_bool($item): case is_bool($item):
$value = '<em>' . ($item ? 'true' : 'false') . '</em>'; $value = '<em>' . ($item ? 'true' : 'false') . '</em>';
break; break;
case is_resource($item): case is_resource($item):
$value = '<em>resource</em>'; $value = '<em>resource</em>';
break; break;
default: default:
$value = htmlentities(str_replace("\n", '', var_export(strval($item), true))); $value = htmlentities(str_replace("\n", '', var_export(strval($item), true)));
break; break;
} }
$result[] = is_int($key) ? $value : "'{$key}' => {$value}"; $result[] = is_int($key) ? $value : "'{$key}' => {$value}";
} }
return implode(', ', $result); return implode(', ', $result);
} }
} }
if (!function_exists('echo_value')) { if (!function_exists('echo_value')) {
function echo_value($val) function echo_value($val)
{ {
if (is_array($val) || is_object($val)) { if (is_array($val) || is_object($val)) {
echo htmlentities(json_encode($val, JSON_PRETTY_PRINT)); echo htmlentities(json_encode($val, JSON_PRETTY_PRINT));
} elseif (is_bool($val)) { } elseif (is_bool($val)) {
echo $val ? 'true' : 'false'; echo $val ? 'true' : 'false';
} elseif (is_scalar($val)) { } elseif (is_scalar($val)) {
echo htmlentities($val); echo htmlentities($val);
} else { } else {
echo 'Resource'; echo 'Resource';
} }
} }
} }
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
@ -161,8 +161,8 @@ if (!function_exists('echo_value')) {
} }
.echo pre > pre { .echo pre > pre {
margin: 0;
padding: 0; padding: 0;
margin: 0;
} }
/* Exception Info */ /* Exception Info */
@ -171,11 +171,11 @@ if (!function_exists('echo_value')) {
} }
.exception .message { .exception .message {
border: 1px solid #ddd;
padding: 12px; padding: 12px;
font-size: 16px; border: 1px solid #ddd;
line-height: 18px;
border-bottom: 0 none; border-bottom: 0 none;
line-height: 18px;
font-size: 16px;
border-top-left-radius: 4px; border-top-left-radius: 4px;
border-top-right-radius: 4px; border-top-right-radius: 4px;
font-family: Consolas, "Liberation Mono", Courier, Verdana, "微软雅黑", serif; font-family: Consolas, "Liberation Mono", Courier, Verdana, "微软雅黑", serif;
@ -192,10 +192,12 @@ if (!function_exists('echo_value')) {
} }
.exception .source-code { .exception .source-code {
border: 1px solid #ddd;
padding: 6px; padding: 6px;
overflow-x: auto; border: 1px solid #ddd;
background: #f9f9f9; background: #f9f9f9;
overflow-x: auto;
} }
.exception .source-code pre { .exception .source-code pre {
@ -207,24 +209,25 @@ if (!function_exists('echo_value')) {
color: #4288ce; color: #4288ce;
display: inline-block; display: inline-block;
min-width: 100%; min-width: 100%;
font-size: 14px;
box-sizing: border-box; box-sizing: border-box;
font-size: 14px;
font-family: "Century Gothic", Consolas, "Liberation Mono", Courier, Verdana, serif; font-family: "Century Gothic", Consolas, "Liberation Mono", Courier, Verdana, serif;
padding-left: <?php echo (isset($source) && ! empty($source)) ? parse_padding($source): 40;?> px; padding-left: < ? php echo (isset($ source) & & ! empty($ source)) ? parse_padding($ source): 40;
? > px;
} }
.exception .source-code pre li { .exception .source-code pre li {
border-left: 1px solid #ddd;
height: 18px; height: 18px;
line-height: 18px; line-height: 18px;
border-left: 1px solid #ddd;
} }
.exception .source-code pre code { .exception .source-code pre code {
color: #333; color: #333;
height: 100%; height: 100%;
font-size: 14px;
display: inline-block; display: inline-block;
border-left: 1px solid #fff; border-left: 1px solid #fff;
font-size: 14px;
font-family: Consolas, "Liberation Mono", Courier, Verdana, "微软雅黑", serif; font-family: Consolas, "Liberation Mono", Courier, Verdana, "微软雅黑", serif;
} }
@ -371,37 +374,28 @@ if (!function_exists('echo_value')) {
</head> </head>
<body> <body>
<?php if (\think\facade\App::isDebug()) { ?> <?php if (\think\facade\App::isDebug()) { ?>
<?php if (isset($traces)) foreach ($traces as $index => $trace) { ?> <?php foreach ($traces as $index => $trace) { ?>
<div class="exception"> <div class="exception">
<div class="message"> <div class="message">
<div class="info"> <div class="info">
<div> <div>
<h2><?php echo "#{$index} [{$trace['code']}]" . sprintf('%s in %s', parse_class($trace['name']), parse_file($trace['file'], $trace['line'])); ?></h2> <h2><?php echo "#{$index} [{$trace['code']}]" . sprintf('%s in %s', parse_class($trace['name']), parse_file($trace['file'], $trace['line'])); ?></h2>
</div>
<div><h1><?php echo nl2br(htmlentities($trace['message'])); ?></h1></div>
</div>
</div> </div>
<?php if (!empty($trace['source'])) { ?> <div><h1><?php echo nl2br(htmlentities($trace['message'])); ?></h1></div>
<div class="source-code"> </div>
<pre class="prettyprint lang-php"> </div>
<?php <?php if (!empty($trace['source'])) { ?>
echo "<ol start='{$trace['source']['first']}'>"; <div class="source-code">
foreach ((array)$trace['source']['source'] as $key => $value) { <pre class="prettyprint lang-php"><ol start="<?php echo $trace['source']['first']; ?>"><?php foreach ((array)$trace['source']['source'] as $key => $value) { ?><li class="line-<?php echo " {$index}-" . ($key + $trace['source']['first']) . ($trace['line'] === $key + $trace['source']['first'] ? ' line-error' : ''); ?>"><code><?php echo htmlentities($value); ?></code></li><?php } ?></ol></pre>
$class = " {$index}-" . ($key + $trace['source']['first']) . ($trace['line'] === $key + $trace['source']['first'] ? ' line-error' : ''); </div>
echo "<li class='{$class}'><code>" . htmlentities($value) . "</code></li>"; <?php } ?>
} <div class="trace">
echo "</ol>"; <h2 data-expand="<?php echo 0 === $index ? '1' : '0'; ?>">Call Stack</h2>
?> <ol>
</pre> <li><?php echo sprintf('in %s', parse_file($trace['file'], $trace['line'])); ?></li>
</div> <?php foreach ((array)$trace['trace'] as $value) { ?>
<?php } ?> <li>
<div class="trace"> <?php
<h2 data-expand="<?php echo 0 === $index ? '1' : '0'; ?>">Call Stack</h2>
<ol>
<li><?php echo sprintf('in %s', parse_file($trace['file'], $trace['line'])); ?></li>
<?php foreach ((array)$trace['trace'] as $value) { ?>
<li>
<?php
// Show Function // Show Function
if ($value['function']) { if ($value['function']) {
echo sprintf( echo sprintf(
@ -412,154 +406,169 @@ if (!function_exists('echo_value')) {
isset($value['args']) ? parse_args($value['args']) : '' isset($value['args']) ? parse_args($value['args']) : ''
); );
} }
// Show line // Show line
if (isset($value['file']) && isset($value['line'])) { if (isset($value['file']) && isset($value['line'])) {
echo sprintf(' in %s', parse_file($value['file'], $value['line'])); echo sprintf(' in %s', parse_file($value['file'], $value['line']));
} }
?> ?>
</li> </li>
<?php } ?> <?php } ?>
</ol> </ol>
</div>
</div>
<?php } ?>
<?php } else { ?>
<div class="exception">
<div class="info"><h1><?php echo htmlentities($message); ?></h1></div>
</div> </div>
</div>
<?php } ?>
<?php } else { ?>
<div class="exception">
<div class="info"><h1><?php echo htmlentities($message); ?></h1></div>
</div>
<?php } ?> <?php } ?>
<?php if (!empty($datas)) { ?> <?php if (!empty($datas)) { ?>
<div class="exception-var"> <div class="exception-var">
<h2>Exception Datas</h2> <h2>Exception Datas</h2>
<?php foreach ((array)$datas as $label => $value) { ?> <?php foreach ((array)$datas as $label => $value) { ?>
<table> <table>
<?php if (empty($value)) { ?> <?php if (empty($value)) { ?>
<caption><?php echo $label; ?><small>empty</small></caption> <caption><?php echo $label; ?><small>empty</small></caption>
<?php } else { ?> <?php } else { ?>
<caption><?php echo $label; ?></caption> <caption><?php echo $label; ?></caption>
<tbody> <tbody>
<?php foreach ((array)$value as $key => $val) { ?> <?php foreach ((array)$value as $key => $val) { ?>
<tr> <tr>
<td><?php echo htmlentities($key); ?></td> <td><?php echo htmlentities($key); ?></td>
<td><?php echo_value($val); ?></td> <td><?php echo_value($val); ?></td>
</tr> </tr>
<?php } ?>
</tbody>
<?php } ?>
</table>
<?php } ?> <?php } ?>
</div> </tbody>
<?php } ?>
</table>
<?php } ?>
</div>
<?php } ?> <?php } ?>
<?php if (!empty($tables)) { ?> <?php if (!empty($tables)) { ?>
<div class="exception-var"> <div class="exception-var">
<h2>Environment Variables</h2> <h2>Environment Variables</h2>
<?php foreach ((array)$tables as $label => $value) { ?> <?php foreach ((array)$tables as $label => $value) { ?>
<table> <table>
<?php if (empty($value)) { ?> <?php if (empty($value)) { ?>
<caption><?php echo $label; ?><small>empty</small></caption> <caption><?php echo $label; ?><small>empty</small></caption>
<?php } else { ?> <?php } else { ?>
<caption><?php echo $label; ?></caption> <caption><?php echo $label; ?></caption>
<tbody> <tbody>
<?php foreach ((array)$value as $key => $val) { ?> <?php foreach ((array)$value as $key => $val) { ?>
<tr> <tr>
<td><?php echo htmlentities($key); ?></td> <td><?php echo htmlentities($key); ?></td>
<td><?php echo_value($val); ?></td> <td><?php echo_value($val); ?></td>
</tr> </tr>
<?php } ?>
</tbody>
<?php } ?>
</table>
<?php } ?> <?php } ?>
</div> </tbody>
<?php } ?>
</table>
<?php } ?>
</div>
<?php } ?> <?php } ?>
<?php if (\think\facade\App::isDebug()) { ?> <?php if (\think\facade\App::isDebug()) { ?>
<script> <script>
function $(selector, node) { function $(selector, node) {
var elements; var elements;
node = node || document;
if (document.querySelectorAll) {
elements = node.querySelectorAll(selector);
} else {
switch (selector.substr(0, 1)) {
case '#':
elements = [node.getElementById(selector.substr(1))];
break;
case '.':
if (document.getElementsByClassName) {
elements = node.getElementsByClassName(selector.substr(1));
} else {
elements = get_elements_by_class(selector.substr(1), node);
}
break;
default:
elements = node.getElementsByTagName();
}
}
return elements;
function get_elements_by_class(search_class, node, tag) { node = node || document;
var elements = [], eles, pattern = new RegExp('(^|\\s)' + search_class + '(\\s|$)'); if (document.querySelectorAll) {
node = node || document, tag = tag || '*', eles = node.getElementsByTagName(tag); elements = node.querySelectorAll(selector);
for (var i = 0; i < eles.length; i++) { } else {
if (pattern.test(eles[i].className)) { switch (selector.substr(0, 1)) {
elements.push(eles[i]) case '#':
} elements = [node.getElementById(selector.substr(1))];
} break;
return elements; case '.':
} if (document.getElementsByClassName) {
} elements = node.getElementsByClassName(selector.substr(1));
$.getScript = function (src, func) {
var script = document.createElement('script');
script.src = src;
script.async = 'async';
script.onload = func || function () {
};
$('head')[0].appendChild(script);
}
;(function () {
var files = $('.toggle');
// 短路径和长路径变换
for (var i = 0; i < files.length; i++) {
files[i].ondblclick = function () {
var title = this.title;
this.title = this.innerHTML;
this.innerHTML = title;
}
}
(function () {
var expand = function (dom, expand) {
var ol = $('ol', dom.parentNode)[0];
expand = undefined === expand ? dom.attributes['data-expand'].value === '0' : undefined;
if (expand) {
dom.attributes['data-expand'].value = '1';
ol.style.display = 'none';
dom.innerText = 'Call Stack (展开)';
} else { } else {
dom.attributes['data-expand'].value = '0'; elements = get_elements_by_class(selector.substr(1), node);
ol.style.display = 'block';
dom.innerText = 'Call Stack (折叠)';
} }
}; break;
var traces = $('.trace'); default:
for (var i = 0; i < traces.length; i++) { elements = node.getElementsByTagName();
var h2 = $('h2', traces[i])[0]; }
expand(h2); }
h2.onclick = function () { return elements;
expand(this);
};
}
})();
$.getScript('//cdn.bootcss.com/prettify/r298/prettify.min.js', function () { function get_elements_by_class(search_class, node, tag) {
prettyPrint(); var elements = [], eles,
}); pattern = new RegExp('(^|\\s)' + search_class + '(\\s|$)');
node = node || document;
tag = tag || '*';
eles = node.getElementsByTagName(tag);
for (var i = 0; i < eles.length; i++) {
if (pattern.test(eles[i].className)) {
elements.push(eles[i])
}
}
return elements;
}
}
$.getScript = function (src, func) {
var script = document.createElement('script');
script.async = 'async';
script.src = src;
script.onload = func || function () {
};
$('head')[0].appendChild(script);
}
;(function () {
var files = $('.toggle');
var ol = $('ol', $('.prettyprint')[0]);
var li = $('li', ol[0]);
// 短路径和长路径变换
for (var i = 0; i < files.length; i++) {
files[i].ondblclick = function () {
var title = this.title;
this.title = this.innerHTML;
this.innerHTML = title;
}
}
(function () {
var expand = function (dom, expand) {
var ol = $('ol', dom.parentNode)[0];
expand = undefined === expand ? dom.attributes['data-expand'].value === '0' : undefined;
if (expand) {
dom.attributes['data-expand'].value = '1';
ol.style.display = 'none';
dom.innerText = 'Call Stack (展开)';
} else {
dom.attributes['data-expand'].value = '0';
ol.style.display = 'block';
dom.innerText = 'Call Stack (折叠)';
}
};
var traces = $('.trace');
for (var i = 0; i < traces.length; i++) {
var h2 = $('h2', traces[i])[0];
expand(h2);
h2.onclick = function () {
expand(this);
};
}
})(); })();
</script>
$.getScript('//cdn.bootcss.com/prettify/r298/prettify.min.js', function () {
prettyPrint();
});
})();
</script>
<?php } ?> <?php } ?>
</body> </body>
</html> </html>