error.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. <?php
  2. if (!function_exists('parse_padding')) {
  3. function parse_padding($source)
  4. {
  5. $length = strlen(strval(count($source['source']) + $source['first']));
  6. return 40 + ($length - 1) * 8;
  7. }
  8. }
  9. if (!function_exists('parse_class')) {
  10. function parse_class($name): string
  11. {
  12. $names = explode('\\', $name);
  13. return '<abbr title="' . $name . '">' . end($names) . '</abbr>';
  14. }
  15. }
  16. if (!function_exists('parse_file')) {
  17. function parse_file($file, $line): string
  18. {
  19. return '<a class="toggle" title="' . "{$file} line {$line}" . '">' . basename($file) . " line {$line}" . '</a>';
  20. }
  21. }
  22. if (!function_exists('parse_args')) {
  23. function parse_args($args): string
  24. {
  25. $result = [];
  26. foreach ($args as $key => $item) {
  27. switch (true) {
  28. case is_object($item):
  29. $value = sprintf('<em>object</em>(%s)', parse_class(get_class($item)));
  30. break;
  31. case is_array($item):
  32. if (count($item) > 3) {
  33. $value = sprintf('[%s, ...]', parse_args(array_slice($item, 0, 3)));
  34. } else {
  35. $value = sprintf('[%s]', parse_args($item));
  36. }
  37. break;
  38. case is_string($item):
  39. if (strlen($item) > 20) {
  40. $value = sprintf(
  41. '\'<a class="toggle" title="%s">%s...</a>\'',
  42. htmlentities($item),
  43. htmlentities(substr($item, 0, 20))
  44. );
  45. } else {
  46. $value = sprintf("'%s'", htmlentities($item));
  47. }
  48. break;
  49. case is_int($item):
  50. case is_float($item):
  51. $value = $item;
  52. break;
  53. case is_null($item):
  54. $value = '<em>null</em>';
  55. break;
  56. case is_bool($item):
  57. $value = '<em>' . ($item ? 'true' : 'false') . '</em>';
  58. break;
  59. case is_resource($item):
  60. $value = '<em>resource</em>';
  61. break;
  62. default:
  63. $value = htmlentities(str_replace("\n", '', var_export(strval($item), true)));
  64. break;
  65. }
  66. $result[] = is_int($key) ? $value : "'{$key}' => {$value}";
  67. }
  68. return implode(', ', $result);
  69. }
  70. }
  71. if (!function_exists('echo_value')) {
  72. function echo_value($val)
  73. {
  74. if (is_array($val) || is_object($val)) {
  75. echo htmlentities(json_encode($val, JSON_PRETTY_PRINT));
  76. } elseif (is_bool($val)) {
  77. echo $val ? 'true' : 'false';
  78. } elseif (is_scalar($val)) {
  79. echo htmlentities($val);
  80. } else {
  81. echo 'Resource';
  82. }
  83. }
  84. }
  85. ?>
  86. <!DOCTYPE html>
  87. <html lang="zh">
  88. <head>
  89. <meta charset="UTF-8">
  90. <title>系统发生错误</title>
  91. <meta name="robots" content="noindex,nofollow"/>
  92. <style>
  93. /* Base */
  94. body {
  95. color: #333;
  96. font: 16px Verdana, "Helvetica Neue", helvetica, Arial, 'Microsoft YaHei', sans-serif;
  97. margin: 0;
  98. padding: 0 20px 20px;
  99. }
  100. h1 {
  101. margin: 10px 0 0;
  102. font-size: 28px;
  103. font-weight: 500;
  104. line-height: 32px;
  105. }
  106. h2 {
  107. color: #4288ce;
  108. font-weight: 400;
  109. padding: 6px 0;
  110. margin: 6px 0 0;
  111. font-size: 18px;
  112. border-bottom: 1px solid #eee;
  113. }
  114. h3 {
  115. margin: 12px;
  116. font-size: 16px;
  117. font-weight: bold;
  118. }
  119. abbr {
  120. cursor: help;
  121. text-decoration: underline;
  122. text-decoration-style: dotted;
  123. }
  124. a {
  125. color: #868686;
  126. cursor: pointer;
  127. }
  128. a:hover {
  129. text-decoration: underline;
  130. }
  131. .line-error {
  132. background: #f8cbcb;
  133. }
  134. .echo table {
  135. width: 100%;
  136. }
  137. .echo pre {
  138. padding: 16px;
  139. overflow: auto;
  140. font-size: 85%;
  141. line-height: 1.45;
  142. background-color: #f7f7f7;
  143. border: 0;
  144. border-radius: 3px;
  145. font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace;
  146. }
  147. .echo pre > pre {
  148. padding: 0;
  149. margin: 0;
  150. }
  151. /* Exception Info */
  152. .exception {
  153. margin-top: 20px;
  154. }
  155. .exception .message {
  156. padding: 12px;
  157. border: 1px solid #ddd;
  158. border-bottom: 0 none;
  159. line-height: 18px;
  160. font-size: 16px;
  161. border-top-left-radius: 4px;
  162. border-top-right-radius: 4px;
  163. font-family: Consolas, "Liberation Mono", Courier, Verdana, "微软雅黑", serif;
  164. }
  165. .exception .code {
  166. float: left;
  167. text-align: center;
  168. color: #fff;
  169. margin-right: 12px;
  170. padding: 16px;
  171. border-radius: 4px;
  172. background: #999;
  173. }
  174. .exception .source-code {
  175. padding: 6px;
  176. border: 1px solid #ddd;
  177. background: #f9f9f9;
  178. overflow-x: auto;
  179. }
  180. .exception .source-code pre {
  181. margin: 0;
  182. }
  183. .exception .source-code pre ol {
  184. margin: 0;
  185. color: #4288ce;
  186. display: inline-block;
  187. min-width: 100%;
  188. box-sizing: border-box;
  189. font-size: 14px;
  190. font-family: "Century Gothic", Consolas, "Liberation Mono", Courier, Verdana, serif;
  191. padding-left: <?php echo (isset($source) && ! empty($source)) ? parse_padding($source): 40;?> px;
  192. }
  193. .exception .source-code pre li {
  194. border-left: 1px solid #ddd;
  195. height: 18px;
  196. line-height: 18px;
  197. }
  198. .exception .source-code pre code {
  199. color: #333;
  200. height: 100%;
  201. display: inline-block;
  202. border-left: 1px solid #fff;
  203. font-size: 14px;
  204. font-family: Consolas, "Liberation Mono", Courier, Verdana, "微软雅黑", serif;
  205. }
  206. .exception .trace {
  207. padding: 6px;
  208. border: 1px solid #ddd;
  209. border-top: 0 none;
  210. line-height: 16px;
  211. font-size: 14px;
  212. font-family: Consolas, "Liberation Mono", Courier, Verdana, "微软雅黑", serif;
  213. }
  214. .exception .trace h2:hover {
  215. text-decoration: underline;
  216. cursor: pointer;
  217. }
  218. .exception .trace ol {
  219. margin: 12px;
  220. }
  221. .exception .trace ol li {
  222. padding: 2px 4px;
  223. }
  224. .exception div:last-child {
  225. border-bottom-left-radius: 4px;
  226. border-bottom-right-radius: 4px;
  227. }
  228. /* Exception Variables */
  229. .exception-var table {
  230. width: 100%;
  231. margin: 12px 0;
  232. box-sizing: border-box;
  233. table-layout: fixed;
  234. word-wrap: break-word;
  235. }
  236. .exception-var table caption {
  237. text-align: left;
  238. font-size: 16px;
  239. font-weight: bold;
  240. padding: 6px 0;
  241. }
  242. .exception-var table caption small {
  243. font-weight: 300;
  244. display: inline-block;
  245. margin-left: 10px;
  246. color: #ccc;
  247. }
  248. .exception-var table tbody {
  249. font-size: 13px;
  250. font-family: Consolas, "Liberation Mono", Courier, "微软雅黑", serif;
  251. }
  252. .exception-var table td {
  253. padding: 0 6px;
  254. vertical-align: top;
  255. word-break: break-all;
  256. }
  257. .exception-var table td:first-child {
  258. width: 28%;
  259. font-weight: bold;
  260. white-space: nowrap;
  261. }
  262. .exception-var table td pre {
  263. margin: 0;
  264. }
  265. /* Copyright Info */
  266. .copyright {
  267. margin-top: 24px;
  268. padding: 12px 0;
  269. border-top: 1px solid #eee;
  270. }
  271. /* SPAN elements with the classes below are added by prettyprint. */
  272. pre.prettyprint .pln {
  273. color: #000
  274. }
  275. /* plain text */
  276. pre.prettyprint .str {
  277. color: #080
  278. }
  279. /* string content */
  280. pre.prettyprint .kwd {
  281. color: #008
  282. }
  283. /* a keyword */
  284. pre.prettyprint .com {
  285. color: #800
  286. }
  287. /* a comment */
  288. pre.prettyprint .typ {
  289. color: #606
  290. }
  291. /* a type name */
  292. pre.prettyprint .lit {
  293. color: #066
  294. }
  295. /* a literal value */
  296. /* punctuation, lisp open bracket, lisp close bracket */
  297. pre.prettyprint .pun, pre.prettyprint .opn, pre.prettyprint .clo {
  298. color: #660
  299. }
  300. pre.prettyprint .tag {
  301. color: #008
  302. }
  303. /* a markup tag name */
  304. pre.prettyprint .atn {
  305. color: #606
  306. }
  307. /* a markup attribute name */
  308. pre.prettyprint .atv {
  309. color: #080
  310. }
  311. /* a markup attribute value */
  312. pre.prettyprint .dec, pre.prettyprint .var {
  313. color: #606
  314. }
  315. /* a declaration; a variable name */
  316. pre.prettyprint .fun {
  317. color: red
  318. }
  319. /* a function name */
  320. </style>
  321. </head>
  322. <body>
  323. <h2><?php echo $message; ?></h2>
  324. <?php if (\think\facade\App::isDebug()) { ?>
  325. <?php foreach ($traces as $index => $trace) { ?>
  326. <div class="exception">
  327. <div class="message">
  328. <div class="info">
  329. <div>
  330. <h2><?php echo "#{$index} [{$trace['code']}]" . sprintf('%s in %s', parse_class($trace['name']), parse_file($trace['file'], $trace['line'])); ?></h2>
  331. </div>
  332. <div><h1><?php echo nl2br(htmlentities($trace['message'])); ?></h1></div>
  333. </div>
  334. </div>
  335. <?php if (!empty($trace['source'])) { ?>
  336. <div class="source-code">
  337. <pre class="prettyprint lang-php">
  338. <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>
  339. </pre>
  340. </div>
  341. <?php } ?>
  342. <div class="trace">
  343. <h2 data-expand="<?php echo 0 === $index ? '1' : '0'; ?>">Call Stack</h2>
  344. <ol>
  345. <li><?php echo sprintf('in %s', parse_file($trace['file'], $trace['line'])); ?></li>
  346. <?php foreach ((array)$trace['trace'] as $value) { ?>
  347. <li>
  348. <?php
  349. // Show Function
  350. if ($value['function']) {
  351. 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']) : '');
  352. }
  353. // Show line
  354. if (isset($value['file']) && isset($value['line'])) {
  355. echo sprintf(' in %s', parse_file($value['file'], $value['line']));
  356. }
  357. ?>
  358. </li>
  359. <?php } ?>
  360. </ol>
  361. </div>
  362. </div>
  363. <?php } ?>
  364. <?php } else { ?>
  365. <div class="exception">
  366. <div class="info"><h1><?php echo htmlentities(isset($message) ? $message : ''); ?></h1></div>
  367. </div>
  368. <?php } ?>
  369. <?php if (!empty($datas)) { ?>
  370. <div class="exception-var">
  371. <h2>Exception Datas</h2>
  372. <?php foreach ((array)$datas as $label => $value) { ?>
  373. <table>
  374. <?php if (empty($value)) { ?>
  375. <caption><?php echo $label; ?><small>empty</small></caption>
  376. <?php } else { ?>
  377. <caption><?php echo $label; ?></caption>
  378. <tbody>
  379. <?php foreach ((array)$value as $key => $val) { ?>
  380. <tr>
  381. <td><?php echo htmlentities($key); ?></td>
  382. <td><?php echo_value($val); ?></td>
  383. </tr>
  384. <?php } ?>
  385. </tbody>
  386. <?php } ?>
  387. </table>
  388. <?php } ?>
  389. </div>
  390. <?php } ?>
  391. <?php if (!empty($tables)) { ?>
  392. <div class="exception-var">
  393. <h2>Environment Variables</h2>
  394. <?php foreach ((array)$tables as $label => $value) { ?>
  395. <table>
  396. <?php if (empty($value)) { ?>
  397. <caption><?php echo $label; ?><small>empty</small></caption>
  398. <?php } else { ?>
  399. <caption><?php echo $label; ?></caption>
  400. <tbody>
  401. <?php foreach ((array)$value as $key => $val) { ?>
  402. <tr>
  403. <td><?php echo htmlentities($key); ?></td>
  404. <td><?php echo_value($val); ?></td>
  405. </tr>
  406. <?php } ?>
  407. </tbody>
  408. <?php } ?>
  409. </table>
  410. <?php } ?>
  411. </div>
  412. <?php } ?>
  413. <?php if (\think\facade\App::isDebug()) { ?>
  414. <script>
  415. function $(selector, node) {
  416. var elements;
  417. node = node || document;
  418. if (document.querySelectorAll) {
  419. elements = node.querySelectorAll(selector);
  420. } else {
  421. switch (selector.substr(0, 1)) {
  422. case '#':
  423. elements = [node.getElementById(selector.substr(1))];
  424. break;
  425. case '.':
  426. if (document.getElementsByClassName) {
  427. elements = node.getElementsByClassName(selector.substr(1));
  428. } else {
  429. elements = get_elements_by_class(selector.substr(1), node);
  430. }
  431. break;
  432. default:
  433. elements = node.getElementsByTagName();
  434. }
  435. }
  436. return elements;
  437. function get_elements_by_class(search_class, node, tag) {
  438. var elements = [], eles,
  439. pattern = new RegExp('(^|\\s)' + search_class + '(\\s|$)');
  440. node = node || document;
  441. tag = tag || '*';
  442. eles = node.getElementsByTagName(tag);
  443. for (var i = 0; i < eles.length; i++) {
  444. if (pattern.test(eles[i].className)) {
  445. elements.push(eles[i])
  446. }
  447. }
  448. return elements;
  449. }
  450. }
  451. $.getScript = function (src, func) {
  452. var script = document.createElement('script');
  453. script.async = 'async';
  454. script.src = src;
  455. script.onload = func || function () {
  456. };
  457. $('head')[0].appendChild(script);
  458. }
  459. ;(function () {
  460. var files = $('.toggle');
  461. var ol = $('ol', $('.prettyprint')[0]);
  462. var li = $('li', ol[0]);
  463. // 短路径和长路径变换
  464. for (var i = 0; i < files.length; i++) {
  465. files[i].ondblclick = function () {
  466. var title = this.title;
  467. this.title = this.innerHTML;
  468. this.innerHTML = title;
  469. }
  470. }
  471. (function () {
  472. var expand = function (dom, expand) {
  473. var ol = $('ol', dom.parentNode)[0];
  474. expand = undefined === expand ? dom.attributes['data-expand'].value === '0' : undefined;
  475. if (expand) {
  476. dom.attributes['data-expand'].value = '1';
  477. ol.style.display = 'none';
  478. dom.innerText = 'Call Stack (展开)';
  479. } else {
  480. dom.attributes['data-expand'].value = '0';
  481. ol.style.display = 'block';
  482. dom.innerText = 'Call Stack (折叠)';
  483. }
  484. };
  485. var traces = $('.trace');
  486. for (var i = 0; i < traces.length; i++) {
  487. var h2 = $('h2', traces[i])[0];
  488. expand(h2);
  489. h2.onclick = function () {
  490. expand(this);
  491. };
  492. }
  493. })();
  494. $.getScript('//cdn.bootcss.com/prettify/r298/prettify.min.js', function () {
  495. prettyPrint();
  496. });
  497. })();
  498. </script>
  499. <?php } ?>
  500. </body>
  501. </html>