think_exception.tpl 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. <?php
  2. if(!\think\App::$debug) {
  3. die(json_encode([
  4. "code" => 500,
  5. "msg" => "Please try again,the program error",
  6. "data" => null
  7. ]));
  8. }
  9. //如果关闭debug模式,那么自动将数据关闭
  10. if(!function_exists('parse_padding')){
  11. function parse_padding($source)
  12. {
  13. $length = strlen(strval(count($source['source']) + $source['first']));
  14. return 40 + ($length - 1) * 8;
  15. }
  16. }
  17. if(!function_exists('parse_class')){
  18. function parse_class($name)
  19. {
  20. $names = explode('\\', $name);
  21. return '<abbr title="'.$name.'">'.end($names).'</abbr>';
  22. }
  23. }
  24. if(!function_exists('parse_file')){
  25. function parse_file($file, $line)
  26. {
  27. return '<a class="toggle" title="'."{$file} line {$line}".'">'.basename($file)." line {$line}".'</a>';
  28. }
  29. }
  30. if(!function_exists('parse_args')){
  31. function parse_args($args)
  32. {
  33. $result = [];
  34. foreach ($args as $key => $item) {
  35. switch (true) {
  36. case is_object($item):
  37. $value = sprintf('<em>object</em>(%s)', parse_class(get_class($item)));
  38. break;
  39. case is_array($item):
  40. if(count($item) > 3){
  41. $value = sprintf('[%s, ...]', parse_args(array_slice($item, 0, 3)));
  42. } else {
  43. $value = sprintf('[%s]', parse_args($item));
  44. }
  45. break;
  46. case is_string($item):
  47. if(strlen($item) > 20){
  48. $value = sprintf(
  49. '\'<a class="toggle" title="%s">%s...</a>\'',
  50. htmlentities($item),
  51. htmlentities(substr($item, 0, 20))
  52. );
  53. } else {
  54. $value = sprintf("'%s'", htmlentities($item));
  55. }
  56. break;
  57. case is_int($item):
  58. case is_float($item):
  59. $value = $item;
  60. break;
  61. case is_null($item):
  62. $value = '<em>null</em>';
  63. break;
  64. case is_bool($item):
  65. $value = '<em>' . ($item ? 'true' : 'false') . '</em>';
  66. break;
  67. case is_resource($item):
  68. $value = '<em>resource</em>';
  69. break;
  70. default:
  71. $value = htmlentities(str_replace("\n", '', var_export(strval($item), true)));
  72. break;
  73. }
  74. $result[] = is_int($key) ? $value : "'{$key}' => {$value}";
  75. }
  76. return implode(', ', $result);
  77. }
  78. }
  79. ?>
  80. <!DOCTYPE html>
  81. <html>
  82. <head>
  83. <meta charset="UTF-8">
  84. <title><?php echo \think\Lang::get('System Error'); ?></title>
  85. <meta name="robots" content="noindex,nofollow" />
  86. <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
  87. <style>
  88. /* Base */
  89. body {
  90. color: #333;
  91. font: 14px Verdana, "Helvetica Neue", helvetica, Arial, 'Microsoft YaHei', sans-serif;
  92. margin: 0;
  93. padding: 0 20px 20px;
  94. word-break: break-word;
  95. }
  96. h1{
  97. margin: 10px 0 0;
  98. font-size: 28px;
  99. font-weight: 500;
  100. line-height: 32px;
  101. }
  102. h2{
  103. color: #4288ce;
  104. font-weight: 400;
  105. padding: 6px 0;
  106. margin: 6px 0 0;
  107. font-size: 18px;
  108. border-bottom: 1px solid #eee;
  109. }
  110. h3.subheading {
  111. color: #4288ce;
  112. margin: 6px 0 0;
  113. font-weight: 400;
  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. /* Layout */
  153. .col-md-3 {
  154. width: 25%;
  155. }
  156. .col-md-9 {
  157. width: 75%;
  158. }
  159. [class^="col-md-"] {
  160. float: left;
  161. }
  162. .clearfix {
  163. clear:both;
  164. }
  165. @media only screen
  166. and (min-device-width : 375px)
  167. and (max-device-width : 667px) {
  168. .col-md-3,
  169. .col-md-9 {
  170. width: 100%;
  171. }
  172. }
  173. /* Exception Info */
  174. .exception {
  175. margin-top: 20px;
  176. }
  177. .exception .message{
  178. padding: 12px;
  179. border: 1px solid #ddd;
  180. border-bottom: 0 none;
  181. line-height: 18px;
  182. font-size:16px;
  183. border-top-left-radius: 4px;
  184. border-top-right-radius: 4px;
  185. font-family: Consolas,"Liberation Mono",Courier,Verdana,"微软雅黑";
  186. }
  187. .exception .code{
  188. float: left;
  189. text-align: center;
  190. color: #fff;
  191. margin-right: 12px;
  192. padding: 16px;
  193. border-radius: 4px;
  194. background: #999;
  195. }
  196. .exception .source-code{
  197. padding: 6px;
  198. border: 1px solid #ddd;
  199. background: #f9f9f9;
  200. overflow-x: auto;
  201. }
  202. .exception .source-code pre{
  203. margin: 0;
  204. }
  205. .exception .source-code pre ol{
  206. margin: 0;
  207. color: #4288ce;
  208. display: inline-block;
  209. min-width: 100%;
  210. box-sizing: border-box;
  211. font-size:14px;
  212. font-family: "Century Gothic",Consolas,"Liberation Mono",Courier,Verdana;
  213. padding-left: <?php echo (isset($source) && !empty($source)) ? parse_padding($source) : 40; ?>px;
  214. }
  215. .exception .source-code pre li{
  216. border-left: 1px solid #ddd;
  217. height: 18px;
  218. line-height: 18px;
  219. }
  220. .exception .source-code pre code{
  221. color: #333;
  222. height: 100%;
  223. display: inline-block;
  224. border-left: 1px solid #fff;
  225. font-size:14px;
  226. font-family: Consolas,"Liberation Mono",Courier,Verdana,"微软雅黑";
  227. }
  228. .exception .trace{
  229. padding: 6px;
  230. border: 1px solid #ddd;
  231. border-top: 0 none;
  232. line-height: 16px;
  233. font-size:14px;
  234. font-family: Consolas,"Liberation Mono",Courier,Verdana,"微软雅黑";
  235. }
  236. .exception .trace ol{
  237. margin: 12px;
  238. }
  239. .exception .trace ol li{
  240. padding: 2px 4px;
  241. }
  242. .exception div:last-child{
  243. border-bottom-left-radius: 4px;
  244. border-bottom-right-radius: 4px;
  245. }
  246. /* Exception Variables */
  247. .exception-var table{
  248. width: 100%;
  249. margin: 12px 0;
  250. box-sizing: border-box;
  251. table-layout:fixed;
  252. word-wrap:break-word;
  253. }
  254. .exception-var table caption{
  255. text-align: left;
  256. font-size: 16px;
  257. font-weight: bold;
  258. padding: 6px 0;
  259. }
  260. .exception-var table caption small{
  261. font-weight: 300;
  262. display: inline-block;
  263. margin-left: 10px;
  264. color: #ccc;
  265. }
  266. .exception-var table tbody{
  267. font-size: 13px;
  268. font-family: Consolas,"Liberation Mono",Courier,"微软雅黑";
  269. }
  270. .exception-var table td{
  271. padding: 0 6px;
  272. vertical-align: top;
  273. word-break: break-all;
  274. }
  275. .exception-var table td:first-child{
  276. width: 28%;
  277. font-weight: bold;
  278. white-space: nowrap;
  279. }
  280. .exception-var table td pre{
  281. margin: 0;
  282. }
  283. /* Copyright Info */
  284. .copyright{
  285. margin-top: 24px;
  286. padding: 12px 0;
  287. border-top: 1px solid #eee;
  288. }
  289. /* SPAN elements with the classes below are added by prettyprint. */
  290. pre.prettyprint .pln { color: #000 } /* plain text */
  291. pre.prettyprint .str { color: #080 } /* string content */
  292. pre.prettyprint .kwd { color: #008 } /* a keyword */
  293. pre.prettyprint .com { color: #800 } /* a comment */
  294. pre.prettyprint .typ { color: #606 } /* a type name */
  295. pre.prettyprint .lit { color: #066 } /* a literal value */
  296. /* punctuation, lisp open bracket, lisp close bracket */
  297. pre.prettyprint .pun, pre.prettyprint .opn, pre.prettyprint .clo { color: #660 }
  298. pre.prettyprint .tag { color: #008 } /* a markup tag name */
  299. pre.prettyprint .atn { color: #606 } /* a markup attribute name */
  300. pre.prettyprint .atv { color: #080 } /* a markup attribute value */
  301. pre.prettyprint .dec, pre.prettyprint .var { color: #606 } /* a declaration; a variable name */
  302. pre.prettyprint .fun { color: red } /* a function name */
  303. </style>
  304. </head>
  305. <body>
  306. <div class="echo">
  307. <?php echo $echo;?>
  308. </div>
  309. <?php if(\think\App::$debug) { ?>
  310. <div class="exception">
  311. <div class="message">
  312. <div class="info">
  313. <div>
  314. <h2>[<?php echo $code; ?>] <?php echo sprintf('%s in %s', parse_class($name), parse_file($file, $line)); ?></h2>
  315. </div>
  316. <div><h1><?php echo nl2br(htmlentities($message)); ?></h1></div>
  317. </div>
  318. </div>
  319. <?php if(!empty($source)){?>
  320. <div class="source-code">
  321. <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>
  322. </div>
  323. <?php }?>
  324. <div class="trace">
  325. <h2>Call Stack</h2>
  326. <ol>
  327. <li><?php echo sprintf('in %s', parse_file($file, $line)); ?></li>
  328. <?php foreach ((array) $trace as $value) { ?>
  329. <li>
  330. <?php
  331. // Show Function
  332. if($value['function']){
  333. echo sprintf(
  334. 'at %s%s%s(%s)',
  335. isset($value['class']) ? parse_class($value['class']) : '',
  336. isset($value['type']) ? $value['type'] : '',
  337. $value['function'],
  338. isset($value['args'])?parse_args($value['args']):''
  339. );
  340. }
  341. // Show line
  342. if (isset($value['file']) && isset($value['line'])) {
  343. echo sprintf(' in %s', parse_file($value['file'], $value['line']));
  344. }
  345. ?>
  346. </li>
  347. <?php } ?>
  348. </ol>
  349. </div>
  350. </div>
  351. <?php } else { ?>
  352. <div class="exception">
  353. <div class="info"><h1><?php echo htmlentities($message); ?></h1></div>
  354. </div>
  355. <?php } ?>
  356. <?php if(!empty($datas)){ ?>
  357. <div class="exception-var">
  358. <h2>Exception Datas</h2>
  359. <?php foreach ((array) $datas as $label => $value) { ?>
  360. <table>
  361. <?php if(empty($value)){ ?>
  362. <caption><?php echo $label; ?><small>empty</small></caption>
  363. <?php } else { ?>
  364. <caption><?php echo $label; ?></caption>
  365. <tbody>
  366. <?php foreach ((array) $value as $key => $val) { ?>
  367. <tr>
  368. <td><?php echo htmlentities($key); ?></td>
  369. <td>
  370. <?php
  371. if(is_array($val) || is_object($val)){
  372. echo htmlentities(json_encode($val, JSON_PRETTY_PRINT));
  373. } else if(is_bool($val)) {
  374. echo $val ? 'true' : 'false';
  375. } else if(is_scalar($val)) {
  376. echo htmlentities($val);
  377. } else {
  378. echo 'Resource';
  379. }
  380. ?>
  381. </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. <div>
  395. <?php if(empty($value)){ ?>
  396. <div class="clearfix">
  397. <div class="col-md-3"><strong><?php echo $label; ?></strong></div>
  398. <div class="col-md-9"><small>empty</small></div>
  399. </div>
  400. <?php } else { ?>
  401. <h3 class="subheading"><?php echo $label; ?></h3>
  402. <div>
  403. <?php foreach ((array) $value as $key => $val) { ?>
  404. <div class="clearfix">
  405. <div class="col-md-3"><strong><?php echo htmlentities($key); ?></strong></div>
  406. <div class="col-md-9"><small>
  407. <?php
  408. if(is_array($val) || is_object($val)){
  409. echo htmlentities(json_encode($val, JSON_PRETTY_PRINT));
  410. } else if(is_bool($val)) {
  411. echo $val ? 'true' : 'false';
  412. } else if(is_scalar($val)) {
  413. echo htmlentities($val);
  414. } else {
  415. echo 'Resource';
  416. }
  417. ?>
  418. </small></div>
  419. </div>
  420. <?php } ?>
  421. </div>
  422. <?php } ?>
  423. </div>
  424. <?php } ?>
  425. </div>
  426. <?php } ?>
  427. <div class="copyright">
  428. <a title="官方网站" href="http://www.52zhainan.com">安徽库云网络技术有限公司</a>
  429. <span>V<?php echo THINK_VERSION; ?></span>
  430. <span>{ 安徽库云网络技术有限公司 }</span>
  431. </div>
  432. <?php if(\think\App::$debug) { ?>
  433. <script>
  434. var LINE = <?php echo $line; ?>;
  435. function $(selector, node){
  436. var elements;
  437. node = node || document;
  438. if(document.querySelectorAll){
  439. elements = node.querySelectorAll(selector);
  440. } else {
  441. switch(selector.substr(0, 1)){
  442. case '#':
  443. elements = [node.getElementById(selector.substr(1))];
  444. break;
  445. case '.':
  446. if(document.getElementsByClassName){
  447. elements = node.getElementsByClassName(selector.substr(1));
  448. } else {
  449. elements = get_elements_by_class(selector.substr(1), node);
  450. }
  451. break;
  452. default:
  453. elements = node.getElementsByTagName();
  454. }
  455. }
  456. return elements;
  457. function get_elements_by_class(search_class, node, tag) {
  458. var elements = [], eles,
  459. pattern = new RegExp('(^|\\s)' + search_class + '(\\s|$)');
  460. node = node || document;
  461. tag = tag || '*';
  462. eles = node.getElementsByTagName(tag);
  463. for(var i = 0; i < eles.length; i++) {
  464. if(pattern.test(eles[i].className)) {
  465. elements.push(eles[i])
  466. }
  467. }
  468. return elements;
  469. }
  470. }
  471. $.getScript = function(src, func){
  472. var script = document.createElement('script');
  473. script.async = 'async';
  474. script.src = src;
  475. script.onload = func || function(){};
  476. $('head')[0].appendChild(script);
  477. }
  478. ;(function(){
  479. var files = $('.toggle');
  480. var ol = $('ol', $('.prettyprint')[0]);
  481. var li = $('li', ol[0]);
  482. // 短路径和长路径变换
  483. for(var i = 0; i < files.length; i++){
  484. files[i].ondblclick = function(){
  485. var title = this.title;
  486. this.title = this.innerHTML;
  487. this.innerHTML = title;
  488. }
  489. }
  490. // 设置出错行
  491. var err_line = $('.line-' + LINE, ol[0])[0];
  492. err_line.className = err_line.className + ' line-error';
  493. $.getScript('//cdn.bootcss.com/prettify/r298/prettify.min.js', function(){
  494. prettyPrint();
  495. // 解决Firefox浏览器一个很诡异的问题
  496. // 当代码高亮后,ol的行号莫名其妙的错位
  497. // 但是只要刷新li里面的html重新渲染就没有问题了
  498. if(window.navigator.userAgent.indexOf('Firefox') >= 0){
  499. ol[0].innerHTML = ol[0].innerHTML;
  500. }
  501. });
  502. })();
  503. </script>
  504. <?php } ?>
  505. </body>
  506. </html>