exception_stack_trace.php 2.7 KB

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