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