Update error.tpl

This commit is contained in:
邹景立 2021-06-17 13:35:25 +08:00
parent 2ff8d3aaf7
commit 519ad1cfb8

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>
@ -374,8 +374,8 @@ echo 'Resource';
</head> </head>
<body> <body>
<?php if (\think\facade\App::isDebug()) { ?> <?php if (\think\facade\App::isDebug()) { ?>
<?php 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>
@ -398,13 +398,7 @@ echo 'Resource';
<?php <?php
// Show Function // Show Function
if ($value['function']) { if ($value['function']) {
echo sprintf( echo sprintf('at %s%s%s(%s)', isset($value['class']) ? parse_class($value['class']) : '', $value['type'] ?? '', $value['function'], isset($value['args']) ? parse_args($value['args']) : '');
'at %s%s%s(%s)',
isset($value['class']) ? parse_class($value['class']) : '',
isset($value['type']) ? $value['type'] : '',
$value['function'],
isset($value['args']) ? parse_args($value['args']) : ''
);
} }
// Show line // Show line
@ -416,16 +410,16 @@ echo 'Resource';
<?php } ?> <?php } ?>
</ol> </ol>
</div> </div>
</div> </div>
<?php } ?> <?php } ?>
<?php } else { ?> <?php } else { ?>
<div class="exception"> <div class="exception">
<div class="info"><h1><?php echo htmlentities($message); ?></h1></div> <div class="info"><h1><?php echo htmlentities($message); ?></h1></div>
</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>
@ -444,11 +438,11 @@ echo 'Resource';
<?php } ?> <?php } ?>
</table> </table>
<?php } ?> <?php } ?>
</div> </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>
@ -467,11 +461,11 @@ echo 'Resource';
<?php } ?> <?php } ?>
</table> </table>
<?php } ?> <?php } ?>
</div> </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;
@ -568,7 +562,7 @@ echo 'Resource';
prettyPrint(); prettyPrint();
}); });
})(); })();
</script> </script>
<?php } ?> <?php } ?>
</body> </body>
</html> </html>