error.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  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. <?php if (\think\facade\App::isDebug()) { ?>
  324. <?php foreach ($traces as $index => $trace) { ?>
  325. <div class="exception">
  326. <div class="message">
  327. <div class="info">
  328. <div>
  329. <h2><?php echo "#{$index} [{$trace['code']}]" . sprintf('%s in %s', parse_class($trace['name']), parse_file($trace['file'], $trace['line'])); ?></h2>
  330. </div>
  331. <div><h1><?php echo nl2br(htmlentities($trace['message'])); ?></h1></div>
  332. </div>
  333. </div>
  334. <?php if (!empty($trace['source'])) { ?>
  335. <div class="source-code">
  336. <pre class="prettyprint lang-php">
  337. <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>
  338. </pre>
  339. </div>
  340. <?php } ?>
  341. <div class="trace">
  342. <h2 data-expand="<?php echo 0 === $index ? '1' : '0'; ?>">Call Stack</h2>
  343. <ol>
  344. <li><?php echo sprintf('in %s', parse_file($trace['file'], $trace['line'])); ?></li>
  345. <?php foreach ((array)$trace['trace'] as $value) { ?>
  346. <li>
  347. <?php
  348. // Show Function
  349. if ($value['function']) {
  350. 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']) : '');
  351. }
  352. // Show line
  353. if (isset($value['file']) && isset($value['line'])) {
  354. echo sprintf(' in %s', parse_file($value['file'], $value['line']));
  355. }
  356. ?>
  357. </li>
  358. <?php } ?>
  359. </ol>
  360. </div>
  361. </div>
  362. <?php } ?>
  363. <?php } else { ?>
  364. <div class="exception">
  365. <div class="info"><h1><?php echo htmlentities(isset($message) ? $message : ''); ?></h1></div>
  366. </div>
  367. <?php } ?>
  368. <?php if (!empty($datas)) { ?>
  369. <div class="exception-var">
  370. <h2>Exception Datas</h2>
  371. <?php foreach ((array)$datas as $label => $value) { ?>
  372. <table>
  373. <?php if (empty($value)) { ?>
  374. <caption><?php echo $label; ?><small>empty</small></caption>
  375. <?php } else { ?>
  376. <caption><?php echo $label; ?></caption>
  377. <tbody>
  378. <?php foreach ((array)$value as $key => $val) { ?>
  379. <tr>
  380. <td><?php echo htmlentities($key); ?></td>
  381. <td><?php echo_value($val); ?></td>
  382. </tr>
  383. <?php } ?>
  384. </tbody>
  385. <?php } ?>
  386. </table>
  387. <?php } ?>
  388. </div>
  389. <?php } ?>
  390. <?php if (!empty($tables)) { ?>
  391. <div class="exception-var">
  392. <h2>Environment Variables</h2>
  393. <?php foreach ((array)$tables as $label => $value) { ?>
  394. <table>
  395. <?php if (empty($value)) { ?>
  396. <caption><?php echo $label; ?><small>empty</small></caption>
  397. <?php } else { ?>
  398. <caption><?php echo $label; ?></caption>
  399. <tbody>
  400. <?php foreach ((array)$value as $key => $val) { ?>
  401. <tr>
  402. <td><?php echo htmlentities($key); ?></td>
  403. <td><?php echo_value($val); ?></td>
  404. </tr>
  405. <?php } ?>
  406. </tbody>
  407. <?php } ?>
  408. </table>
  409. <?php } ?>
  410. </div>
  411. <?php } ?>
  412. <?php if (\think\facade\App::isDebug()) { ?>
  413. <script>
  414. function $(selector, node) {
  415. var elements;
  416. node = node || document;
  417. if (document.querySelectorAll) {
  418. elements = node.querySelectorAll(selector);
  419. } else {
  420. switch (selector.substr(0, 1)) {
  421. case '#':
  422. elements = [node.getElementById(selector.substr(1))];
  423. break;
  424. case '.':
  425. if (document.getElementsByClassName) {
  426. elements = node.getElementsByClassName(selector.substr(1));
  427. } else {
  428. elements = get_elements_by_class(selector.substr(1), node);
  429. }
  430. break;
  431. default:
  432. elements = node.getElementsByTagName();
  433. }
  434. }
  435. return elements;
  436. function get_elements_by_class(search_class, node, tag) {
  437. var elements = [], eles,
  438. pattern = new RegExp('(^|\\s)' + search_class + '(\\s|$)');
  439. node = node || document;
  440. tag = tag || '*';
  441. eles = node.getElementsByTagName(tag);
  442. for (var i = 0; i < eles.length; i++) {
  443. if (pattern.test(eles[i].className)) {
  444. elements.push(eles[i])
  445. }
  446. }
  447. return elements;
  448. }
  449. }
  450. $.getScript = function (src, func) {
  451. var script = document.createElement('script');
  452. script.async = 'async';
  453. script.src = src;
  454. script.onload = func || function () {
  455. };
  456. $('head')[0].appendChild(script);
  457. }
  458. ;(function () {
  459. var files = $('.toggle');
  460. var ol = $('ol', $('.prettyprint')[0]);
  461. var li = $('li', ol[0]);
  462. // 短路径和长路径变换
  463. for (var i = 0; i < files.length; i++) {
  464. files[i].ondblclick = function () {
  465. var title = this.title;
  466. this.title = this.innerHTML;
  467. this.innerHTML = title;
  468. }
  469. }
  470. (function () {
  471. var expand = function (dom, expand) {
  472. var ol = $('ol', dom.parentNode)[0];
  473. expand = undefined === expand ? dom.attributes['data-expand'].value === '0' : undefined;
  474. if (expand) {
  475. dom.attributes['data-expand'].value = '1';
  476. ol.style.display = 'none';
  477. dom.innerText = 'Call Stack (展开)';
  478. } else {
  479. dom.attributes['data-expand'].value = '0';
  480. ol.style.display = 'block';
  481. dom.innerText = 'Call Stack (折叠)';
  482. }
  483. };
  484. var traces = $('.trace');
  485. for (var i = 0; i < traces.length; i++) {
  486. var h2 = $('h2', traces[i])[0];
  487. expand(h2);
  488. h2.onclick = function () {
  489. expand(this);
  490. };
  491. }
  492. })();
  493. $.getScript('//cdn.bootcss.com/prettify/r298/prettify.min.js', function () {
  494. prettyPrint();
  495. });
  496. })();
  497. </script>
  498. <?php } ?>
  499. </body>
  500. </html>