exception_stack_trace.php 3.1 KB

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