think_exception.tpl 18 KB

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