think_exception.tpl 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  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. <?php if(\think\facade\App::isDebug()) { ?>
  271. <div class="exception">
  272. <div class="message">
  273. <div class="info">
  274. <div>
  275. <h2>[<?php echo $code; ?>]&nbsp;<?php echo sprintf('%s in %s', parse_class($name), parse_file($file, $line)); ?></h2>
  276. </div>
  277. <div><h1><?php echo nl2br(htmlentities($message)); ?></h1></div>
  278. </div>
  279. </div>
  280. <?php if(!empty($source)){?>
  281. <div class="source-code">
  282. <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>
  283. </div>
  284. <?php }?>
  285. <div class="trace">
  286. <h2>Call Stack</h2>
  287. <ol>
  288. <li><?php echo sprintf('in %s', parse_file($file, $line)); ?></li>
  289. <?php foreach ((array) $trace as $value) { ?>
  290. <li>
  291. <?php
  292. // Show Function
  293. if($value['function']){
  294. echo sprintf(
  295. 'at %s%s%s(%s)',
  296. isset($value['class']) ? parse_class($value['class']) : '',
  297. isset($value['type']) ? $value['type'] : '',
  298. $value['function'],
  299. isset($value['args'])?parse_args($value['args']):''
  300. );
  301. }
  302. // Show line
  303. if (isset($value['file']) && isset($value['line'])) {
  304. echo sprintf(' in %s', parse_file($value['file'], $value['line']));
  305. }
  306. ?>
  307. </li>
  308. <?php } ?>
  309. </ol>
  310. </div>
  311. </div>
  312. <?php } else { ?>
  313. <div class="exception">
  314. <div class="info"><h1><?php echo htmlentities($message); ?></h1></div>
  315. </div>
  316. <?php } ?>
  317. <?php if(!empty($datas)){ ?>
  318. <div class="exception-var">
  319. <h2>Exception Datas</h2>
  320. <?php foreach ((array) $datas as $label => $value) { ?>
  321. <table>
  322. <?php if(empty($value)){ ?>
  323. <caption><?php echo $label; ?><small>empty</small></caption>
  324. <?php } else { ?>
  325. <caption><?php echo $label; ?></caption>
  326. <tbody>
  327. <?php foreach ((array) $value as $key => $val) { ?>
  328. <tr>
  329. <td><?php echo htmlentities($key); ?></td>
  330. <td>
  331. <?php
  332. if(is_array($val) || is_object($val)){
  333. echo htmlentities(json_encode($val, JSON_PRETTY_PRINT));
  334. } else if(is_bool($val)) {
  335. echo $val ? 'true' : 'false';
  336. } else if(is_scalar($val)) {
  337. echo htmlentities($val);
  338. } else {
  339. echo 'Resource';
  340. }
  341. ?>
  342. </td>
  343. </tr>
  344. <?php } ?>
  345. </tbody>
  346. <?php } ?>
  347. </table>
  348. <?php } ?>
  349. </div>
  350. <?php } ?>
  351. <?php if(!empty($tables)){ ?>
  352. <div class="exception-var">
  353. <h2>Environment Variables</h2>
  354. <?php foreach ((array) $tables as $label => $value) { ?>
  355. <table>
  356. <?php if(empty($value)){ ?>
  357. <caption><?php echo $label; ?><small>empty</small></caption>
  358. <?php } else { ?>
  359. <caption><?php echo $label; ?></caption>
  360. <tbody>
  361. <?php foreach ((array) $value as $key => $val) { ?>
  362. <tr>
  363. <td><?php echo htmlentities($key); ?></td>
  364. <td>
  365. <?php
  366. if(is_array($val) || is_object($val)){
  367. echo htmlentities(json_encode($val, JSON_PRETTY_PRINT));
  368. } else if(is_bool($val)) {
  369. echo $val ? 'true' : 'false';
  370. } else if(is_scalar($val)) {
  371. echo htmlentities($val);
  372. } else {
  373. echo 'Resource';
  374. }
  375. ?>
  376. </td>
  377. </tr>
  378. <?php } ?>
  379. </tbody>
  380. <?php } ?>
  381. </table>
  382. <?php } ?>
  383. </div>
  384. <?php } ?>
  385. <div class="copyright">
  386. <a title="官方网站" href="http://www.thinkphp.cn">ThinkPHP</a>
  387. <span>V<?php echo \think\facade\App::version(); ?></span>
  388. <span>{ 十年磨一剑-为API开发设计的高性能框架 }</span>
  389. <span>- <a title="官方手册" href="https://www.kancloud.cn/manual/thinkphp6_0/">官方手册</a></span>
  390. </div>
  391. <?php if(\think\facade\App::isDebug()) { ?>
  392. <script>
  393. var LINE = <?php echo $line; ?>;
  394. function $(selector, node){
  395. var elements;
  396. node = node || document;
  397. if(document.querySelectorAll){
  398. elements = node.querySelectorAll(selector);
  399. } else {
  400. switch(selector.substr(0, 1)){
  401. case '#':
  402. elements = [node.getElementById(selector.substr(1))];
  403. break;
  404. case '.':
  405. if(document.getElementsByClassName){
  406. elements = node.getElementsByClassName(selector.substr(1));
  407. } else {
  408. elements = get_elements_by_class(selector.substr(1), node);
  409. }
  410. break;
  411. default:
  412. elements = node.getElementsByTagName();
  413. }
  414. }
  415. return elements;
  416. function get_elements_by_class(search_class, node, tag) {
  417. var elements = [], eles,
  418. pattern = new RegExp('(^|\\s)' + search_class + '(\\s|$)');
  419. node = node || document;
  420. tag = tag || '*';
  421. eles = node.getElementsByTagName(tag);
  422. for(var i = 0; i < eles.length; i++) {
  423. if(pattern.test(eles[i].className)) {
  424. elements.push(eles[i])
  425. }
  426. }
  427. return elements;
  428. }
  429. }
  430. $.getScript = function(src, func){
  431. var script = document.createElement('script');
  432. script.async = 'async';
  433. script.src = src;
  434. script.onload = func || function(){};
  435. $('head')[0].appendChild(script);
  436. }
  437. ;(function(){
  438. var files = $('.toggle');
  439. var ol = $('ol', $('.prettyprint')[0]);
  440. var li = $('li', ol[0]);
  441. // 短路径和长路径变换
  442. for(var i = 0; i < files.length; i++){
  443. files[i].ondblclick = function(){
  444. var title = this.title;
  445. this.title = this.innerHTML;
  446. this.innerHTML = title;
  447. }
  448. }
  449. // 设置出错行
  450. var err_line = $('.line-' + LINE, ol[0])[0];
  451. err_line.className = err_line.className + ' line-error';
  452. $.getScript('//cdn.bootcss.com/prettify/r298/prettify.min.js', function(){
  453. prettyPrint();
  454. // 解决Firefox浏览器一个很诡异的问题
  455. // 当代码高亮后,ol的行号莫名其妙的错位
  456. // 但是只要刷新li里面的html重新渲染就没有问题了
  457. if(window.navigator.userAgent.indexOf('Firefox') >= 0){
  458. ol[0].innerHTML = ol[0].innerHTML;
  459. }
  460. });
  461. })();
  462. </script>
  463. <?php } ?>
  464. </body>
  465. </html>