YiiDebugViewRenderer.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. /**
  3. * YiiDebugViewRenderer class file.
  4. *
  5. * @author Sergey Malyshev <malyshev.php@gmail.com>
  6. */
  7. /**
  8. * YiiDebugViewRenderer represents an ...
  9. *
  10. * Description of YiiDebugViewRenderer
  11. *
  12. * @author Sergey Malyshev <malyshev.php@gmail.com>
  13. * @version $Id$
  14. * @package
  15. * @since 1.1.7
  16. */
  17. class YiiDebugViewRenderer extends YiiDebugComponentProxy
  18. {
  19. protected $abstract = array(
  20. 'fileExtension' => '.php',
  21. );
  22. protected $_debugStackTrace = array();
  23. public function getDebugStackTrace()
  24. {
  25. return $this->_debugStackTrace;
  26. }
  27. public function renderFile($context, $sourceFile, $data, $return)
  28. {
  29. $this->collectDebugInfo($context, $sourceFile, $data);
  30. if (false !== $this->getIsProxy())
  31. {
  32. return $this->instance->renderFile($context,$sourceFile,$data,$return);
  33. }
  34. return $context->renderInternal($sourceFile,$data,$return);
  35. }
  36. public function generateViewFile($sourceFile, $viewFile)
  37. {
  38. if (false !== $this->getIsProxy())
  39. {
  40. return $this->instance->generateViewFile($sourceFile, $viewFile);
  41. }
  42. }
  43. protected function getDebugBacktrace()
  44. {
  45. // @see "http://www.php.net/manual/en/function.debug-backtrace.php"
  46. //
  47. // debug_backtrace Changelog
  48. //
  49. // Version Description
  50. // 5.4.0 Added the optional parameter limit.
  51. // 5.3.6 The parameter provide_object changed to options and
  52. // additional option DEBUG_BACKTRACE_IGNORE_ARGS is added.
  53. // 5.2.5 Added the optional parameter provide_object.
  54. // 5.1.1 Added the current object as a possible return element.
  55. if (version_compare(PHP_VERSION, '5.4.0', '>='))
  56. {
  57. // signature is:
  58. // array debug_backtrace ([ int $options = DEBUG_BACKTRACE_PROVIDE_OBJECT [, int $limit = 0 ]] )
  59. //
  60. // possible values for $options:
  61. // - DEBUG_BACKTRACE_PROVIDE_OBJECT
  62. // - DEBUG_BACKTRACE_IGNORE_ARGS
  63. // - DEBUG_BACKTRACE_PROVIDE_OBJECT | DEBUG_BACKTRACE_IGNORE_ARGS
  64. $debugBacktrace = debug_backtrace( DEBUG_BACKTRACE_PROVIDE_OBJECT );
  65. }
  66. elseif (version_compare(PHP_VERSION, '5.3.6', '>='))
  67. {
  68. // signature is:
  69. // array debug_backtrace ([ int $options = DEBUG_BACKTRACE_PROVIDE_OBJECT ] )
  70. //
  71. // possible values for $options:
  72. // - DEBUG_BACKTRACE_PROVIDE_OBJECT
  73. // - DEBUG_BACKTRACE_IGNORE_ARGS
  74. // - DEBUG_BACKTRACE_PROVIDE_OBJECT | DEBUG_BACKTRACE_IGNORE_ARGS
  75. $debugBacktrace = debug_backtrace( DEBUG_BACKTRACE_PROVIDE_OBJECT );
  76. }
  77. elseif (version_compare(PHP_VERSION, '5.2.5', '>='))
  78. {
  79. // signature is:
  80. // array debug_backtrace ([ bool $provide_object = TRUE ] )
  81. $debugBacktrace = debug_backtrace( true );
  82. }
  83. else /* version < 5.2.5 */
  84. {
  85. // signature is:
  86. // array debug_backtrace ( )
  87. $debugBacktrace = debug_backtrace();
  88. }
  89. return $debugBacktrace;
  90. }
  91. protected function collectDebugInfo($context, $sourceFile, $data)
  92. {
  93. if($context instanceof YiiDebugToolbar || false !== ($context instanceof YiiDebugToolbarPanel))
  94. return;
  95. $backTrace = $this->getDebugBacktrace();
  96. $backTraceItem = null;
  97. while($backTraceItem = array_shift($backTrace))
  98. {
  99. if(isset($backTraceItem['object']) && $backTraceItem['object'] && ($backTraceItem['object'] instanceof $context) && in_array($backTraceItem['function'], array(
  100. 'render',
  101. 'renderPartial'
  102. )) )
  103. {
  104. break;
  105. }
  106. }
  107. array_push($this->_debugStackTrace, array(
  108. 'context'=>$context,
  109. 'contextProperties'=> get_object_vars($context),
  110. 'action'=> $context instanceof CController ? $context->action : null,
  111. 'actionParams'=> ($context instanceof CController && method_exists($context, 'getActionParams'))
  112. ? $context->actionParams
  113. : null,
  114. 'route'=> $context instanceof CController ? $context->route : null,
  115. 'sourceFile'=>$sourceFile,
  116. 'data'=>$data,
  117. 'backTrace'=>$backTraceItem,
  118. 'reflection' => new ReflectionObject($context)
  119. ));
  120. }
  121. }