dev_error_stacktrace.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. /**
  3. * Prints a stack trace for an exception
  4. *
  5. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  6. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  7. *
  8. * Licensed under The MIT License
  9. * For full copyright and license information, please see the LICENSE.txt
  10. * Redistributions of files must retain the above copyright notice.
  11. *
  12. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  13. * @link https://cakephp.org CakePHP(tm) Project
  14. * @since 4.5.0
  15. * @license https://opensource.org/licenses/mit-license.php MIT License
  16. * @var array $trace
  17. */
  18. use Cake\Error\Debugger;
  19. foreach ($exceptions as $level => $exc):
  20. $stackTrace = Debugger::formatTrace($exc->getTrace(), [
  21. 'format' => 'array',
  22. 'args' => true,
  23. ]);
  24. if ($level != 0): ?>
  25. <div class="stack-exception-header">
  26. <span class="stack-exception-caused">Caused by</span>
  27. <span class="stack-exception-message"><?= Debugger::formatHtmlMessage($exc->getMessage()) ?></span>
  28. <span class="stack-exception-type"><?= h(get_class($exc)); ?></span>
  29. </div>
  30. <?php endif; ?>
  31. <ul class="stack-frames">
  32. <?php
  33. foreach ($stackTrace as $i => $stack):
  34. $excerpt = $params = [];
  35. $line = null;
  36. if (isset($stack['file'], $stack['line']) && is_numeric($stack['line'])):
  37. $line = $stack['line'];
  38. $excerpt = Debugger::excerpt($stack['file'], $line, 4);
  39. endif;
  40. if (isset($stack['file'])):
  41. $file = $stack['file'];
  42. else:
  43. $file = '[internal function]';
  44. endif;
  45. if (isset($stack['function'])):
  46. if (!empty($stack['args'])):
  47. foreach ((array)$stack['args'] as $arg):
  48. $params[] = Debugger::exportVar($arg, 4);
  49. endforeach;
  50. else:
  51. $params[] = 'No arguments';
  52. endif;
  53. endif;
  54. $frameId = "{$level}-{$i}";
  55. $activeFrame = $i == 0;
  56. $vendorFrame = isset($stack['file']) && strpos($stack['file'], APP) === false ? 'vendor-frame' : '';
  57. ?>
  58. <li id="stack-frame-<?= $frameId ?>" class="stack-frame <?= $vendorFrame ?>">
  59. <div class="stack-frame-header">
  60. <button
  61. data-frame-id="<?= h($frameId) ?>"
  62. class="stack-frame-toggle <?= $activeFrame ? 'active' : '' ?>"
  63. >
  64. &#x25BC;
  65. </button>
  66. <div class="stack-frame-header-content">
  67. <span class="stack-frame-file">
  68. <?= h(Debugger::trimPath($file)); ?>
  69. </span>
  70. <span class="stack-function">
  71. <?php if (isset($stack['class']) || isset($stack['function'])): ?>
  72. <span class="stack-frame-label">in</span>
  73. <?php endif ?>
  74. <?php if (isset($stack['class'])): ?>
  75. <?= h($stack['class'] . $stack['type'] . $stack['function']) ?>
  76. <?php elseif (isset($stack['function'])): ?>
  77. <?= h($stack['function']) ?>
  78. <?php endif; ?>
  79. </span>
  80. <?php if ($line !== null): ?>
  81. <span class="stack-frame-line">
  82. <span class="stack-frame-label">at line</span><?= h($line) ?>
  83. </span>
  84. <?php endif ?>
  85. <?php if ($line !== null): ?>
  86. <?= $this->Html->link('(edit)', Debugger::editorUrl($file, $line), ['class' => 'stack-frame-edit']); ?>
  87. <?php endif; ?>
  88. </div>
  89. </div>
  90. <div
  91. class="stack-frame-contents"
  92. id="stack-frame-details-<?= $frameId ?>"
  93. style="display: <?= $activeFrame ? 'block' : 'none' ?>"
  94. >
  95. <table class="code-excerpt" cellspacing="0" cellpadding="0">
  96. <?php $lineno = isset($stack['line']) && is_numeric($stack['line']) ? $stack['line'] - 4 : 0 ?>
  97. <?php foreach ($excerpt as $l => $line): ?>
  98. <tr>
  99. <td class="excerpt-number" data-number="<?= $lineno + $l ?>"></td>
  100. <td class="excerpt-line"><?= $line ?></td>
  101. </tr>
  102. <?php endforeach; ?>
  103. </table>
  104. <a href="#" class="stack-frame-args" data-target="stack-args-<?= $frameId ?>">Toggle Arguments</a>
  105. <div id="stack-args-<?= $frameId ?>" class="stack-args" style="display: none;">
  106. <?php foreach ($params as $param): ?>
  107. <div class="cake-debug"><?= $param ?></div>
  108. <?php endforeach; ?>
  109. </div>
  110. </div>
  111. </li>
  112. <?php endforeach; ?>
  113. </ul>
  114. <?php endforeach; ?>