exception_stack_trace.ctp 2.3 KB

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