think_exception.tpl 17 KB

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