exception_stack_trace.php 2.7 KB

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