@@ -71,51 +71,82 @@ function config() {
71
71
* @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#debug
72
72
*/
73
73
function debug ($ var , $ showHtml = null , $ showFrom = true ) {
74
- if (Configure::read ('debug ' ) > 0 ) {
75
- App::uses ('Debugger ' , 'Utility ' );
76
- $ file = '' ;
77
- $ line = '' ;
78
- $ lineInfo = '' ;
79
- if ($ showFrom ) {
80
- $ trace = Debugger::trace (array ('start ' => 1 , 'depth ' => 2 , 'format ' => 'array ' ));
81
- $ file = str_replace (array (CAKE_CORE_INCLUDE_PATH , ROOT ), '' , $ trace [0 ]['file ' ]);
82
- $ line = $ trace [0 ]['line ' ];
83
- }
84
- $ html = <<<HTML
74
+ if (!Configure::read ('debug ' )) {
75
+ return ;
76
+ }
77
+ App::uses ('Debugger ' , 'Utility ' );
78
+
79
+ $ file = '' ;
80
+ $ line = '' ;
81
+ $ lineInfo = '' ;
82
+ if ($ showFrom ) {
83
+ $ trace = Debugger::trace (array ('start ' => 1 , 'depth ' => 2 , 'format ' => 'array ' ));
84
+ $ file = str_replace (array (CAKE_CORE_INCLUDE_PATH , ROOT ), '' , $ trace [0 ]['file ' ]);
85
+ $ line = $ trace [0 ]['line ' ];
86
+ }
87
+ $ html = <<<HTML
85
88
<div class="cake-debug-output">
86
89
%s
87
90
<pre class="cake-debug">
88
91
%s
89
92
</pre>
90
93
</div>
91
94
HTML ;
92
- $ text = <<<TEXT
95
+ $ text = <<<TEXT
93
96
%s
94
97
########## DEBUG ##########
95
98
%s
96
99
###########################
97
100
98
101
TEXT ;
99
- $ template = $ html ;
100
- if (php_sapi_name () === 'cli ' || $ showHtml === false ) {
101
- $ template = $ text ;
102
- if ($ showFrom ) {
103
- $ lineInfo = sprintf ('%s (line %s) ' , $ file , $ line );
104
- }
105
- }
106
- if ($ showHtml === null && $ template !== $ text ) {
107
- $ showHtml = true ;
102
+ $ template = $ html ;
103
+ if (php_sapi_name () === 'cli ' || $ showHtml === false ) {
104
+ $ template = $ text ;
105
+ if ($ showFrom ) {
106
+ $ lineInfo = sprintf ('%s (line %s) ' , $ file , $ line );
108
107
}
109
- $ var = Debugger::exportVar ($ var , 25 );
110
- if ($ showHtml ) {
111
- $ template = $ html ;
112
- $ var = h ($ var );
113
- if ($ showFrom ) {
114
- $ lineInfo = sprintf ('<span><strong>%s</strong> (line <strong>%s</strong>)</span> ' , $ file , $ line );
115
- }
108
+ }
109
+ if ($ showHtml === null && $ template !== $ text ) {
110
+ $ showHtml = true ;
111
+ }
112
+ $ var = Debugger::exportVar ($ var , 25 );
113
+ if ($ showHtml ) {
114
+ $ template = $ html ;
115
+ $ var = h ($ var );
116
+ if ($ showFrom ) {
117
+ $ lineInfo = sprintf ('<span><strong>%s</strong> (line <strong>%s</strong>)</span> ' , $ file , $ line );
116
118
}
117
- printf ($ template , $ lineInfo , $ var );
118
119
}
120
+ printf ($ template , $ lineInfo , $ var );
121
+ }
122
+
123
+ }
124
+
125
+ if (!function_exists ('stackTrace ' )) {
126
+
127
+ /**
128
+ * Outputs a stack trace based on the supplied options.
129
+ *
130
+ * ### Options
131
+ *
132
+ * - `depth` - The number of stack frames to return. Defaults to 999
133
+ * - `args` - Should arguments for functions be shown? If true, the arguments for each method call
134
+ * will be displayed.
135
+ * - `start` - The stack frame to start generating a trace from. Defaults to 1
136
+ *
137
+ * @param array $options Format for outputting stack trace
138
+ * @return mixed Formatted stack trace
139
+ * @see Debugger::trace()
140
+ */
141
+ function stackTrace (array $ options = array ()) {
142
+ if (!Configure::read ('debug ' )) {
143
+ return ;
144
+ }
145
+ App::uses ('Debugger ' , 'Utility ' );
146
+
147
+ $ options += array ('start ' => 0 );
148
+ $ options ['start ' ]++;
149
+ echo Debugger::trace ($ options );
119
150
}
120
151
121
152
}
0 commit comments