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