exception_stack_trace.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 1.3.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. foreach ($stackTrace as $i => $stack):
  25. $excerpt = $params = [];
  26. $line = null;
  27. if (isset($stack['file'], $stack['line']) && is_numeric($stack['line'])):
  28. $line = $stack['line'];
  29. $excerpt = Debugger::excerpt($stack['file'], $line, 4);
  30. endif;
  31. if (isset($stack['file'])):
  32. $file = $stack['file'];
  33. else:
  34. $file = '[internal function]';
  35. endif;
  36. if (isset($stack['function'])):
  37. if (!empty($stack['args'])):
  38. foreach ((array)$stack['args'] as $arg):
  39. $params[] = Debugger::exportVar($arg, 4);
  40. endforeach;
  41. else:
  42. $params[] = 'No arguments';
  43. endif;
  44. endif;
  45. ?>
  46. <div id="stack-frame-<?= $i ?>" style="display:<?= $i === 0 ? 'block' : 'none'; ?>;" class="stack-details">
  47. <div class="stack-frame-header">
  48. <span class="stack-frame-file">
  49. <?php if ($line !== null): ?>
  50. <?= $this->Html->link(Debugger::trimPath($file), Debugger::editorUrl($file, $line)); ?>
  51. <?php else: ?>
  52. <?= h(Debugger::trimPath($file)); ?>
  53. <?php endif; ?>
  54. </span>
  55. <a href="#" class="toggle-link stack-frame-args" data-target="stack-args-<?= $i ?>">Toggle Arguments</a>
  56. </div>
  57. <table class="code-excerpt" cellspacing="0" cellpadding="0">
  58. <?php $lineno = isset($stack['line']) && is_numeric($stack['line']) ? $stack['line'] - 4 : 0 ?>
  59. <?php foreach ($excerpt as $l => $line): ?>
  60. <tr>
  61. <td class="excerpt-number" data-number="<?= $lineno + $l ?>"></td>
  62. <td class="excerpt-line"><?= $line ?></td>
  63. </tr>
  64. <?php endforeach; ?>
  65. </table>
  66. <div id="stack-args-<?= $i ?>" class="cake-debug" style="display: none;">
  67. <h4>Arguments</h4>
  68. <?php foreach ($params as $param): ?>
  69. <div class="cake-debug"><?= $param ?></div>
  70. <?php endforeach; ?>
  71. </div>
  72. </div>
  73. <?php endforeach; ?>
  74. <?php endforeach; ?>