exception_stack_trace.ctp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * Prints a stack trace for an exception
  4. *
  5. * PHP 5
  6. *
  7. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  8. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  9. *
  10. * Licensed under The MIT License
  11. * For full copyright and license information, please see the LICENSE.txt
  12. * Redistributions of files must retain the above copyright notice.
  13. *
  14. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  15. * @link http://cakephp.org CakePHP(tm) Project
  16. * @package Cake.View.Elements
  17. * @since CakePHP(tm) v 1.3
  18. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  19. */
  20. App::uses('Debugger', 'Utility');
  21. ?>
  22. <h3>Stack Trace</h3>
  23. <ul class="cake-stack-trace">
  24. <?php foreach ($error->getTrace() as $i => $stack): ?>
  25. <li><?php
  26. $excerpt = $arguments = '';
  27. $params = array();
  28. if (isset($stack['file']) && isset($stack['line'])):
  29. printf(
  30. '<a href="#" onclick="traceToggle(event, \'file-excerpt-%s\')">%s line %s</a>',
  31. $i,
  32. Debugger::trimPath($stack['file']),
  33. $stack['line']
  34. );
  35. $excerpt = sprintf('<div id="file-excerpt-%s" class="cake-code-dump" style="display:none;"><pre>', $i);
  36. $excerpt .= implode("\n", Debugger::excerpt($stack['file'], $stack['line'] - 1, 2));
  37. $excerpt .= '</pre></div> ';
  38. else:
  39. echo '<a href="#">[internal function]</a>';
  40. endif;
  41. echo ' &rarr; ';
  42. if ($stack['function']):
  43. $args = array();
  44. if (!empty($stack['args'])):
  45. foreach ((array)$stack['args'] as $arg):
  46. $args[] = Debugger::getType($arg);
  47. $params[] = Debugger::exportVar($arg, 2);
  48. endforeach;
  49. endif;
  50. $called = isset($stack['class']) ? $stack['class'] . $stack['type'] . $stack['function'] : $stack['function'];
  51. printf(
  52. '<a href="#" onclick="traceToggle(event, \'trace-args-%s\')">%s(%s)</a> ',
  53. $i,
  54. $called,
  55. h(implode(', ', $args))
  56. );
  57. $arguments = sprintf('<div id="trace-args-%s" class="cake-code-dump" style="display: none;"><pre>', $i);
  58. $arguments .= h(implode("\n", $params));
  59. $arguments .= '</pre></div>';
  60. endif;
  61. echo $excerpt;
  62. echo $arguments;
  63. ?></li>
  64. <?php endforeach; ?>
  65. </ul>
  66. <script type="text/javascript">
  67. function traceToggle(event, id) {
  68. var el = document.getElementById(id);
  69. el.style.display = (el.style.display === 'block') ? 'none' : 'block';
  70. event.preventDefault();
  71. return false;
  72. }
  73. </script>