think_exception.tpl 17 KB

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