Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

eztemplatedebugfunction.php
Go to the documentation of this file.
1 <?php
62 class eZTemplateDebugFunction
63 {
64 public $TimingPointName;
65 public $AccumulatorName;
66 public $LogName;
67 public $TraceName;
76 public function __construct( $timingPoint = 'debug-timing-point',
77 $accumulator = 'debug-accumulator',
78 $log = 'debug-log',
79 $trace = 'debug-trace' )
80 {
81 $this->TimingPointName = $timingPoint;
82 $this->AccumulatorName = $accumulator;
83 $this->LogName = $log;
84 $this->TraceName = $trace;
85 }
86
90 function functionList()
91 {
92 return array( $this->TimingPointName, $this->AccumulatorName, $this->LogName, $this->TraceName );
93 }
94
100 function attributeList()
101 {
102 return array(
103 $this->TimingPointName => true,
104 $this->AccumulatorName => true,
105 $this->LogName => false,
106 $this->TraceName => true
107 );
108 }
109
110 function functionTemplateHints()
111 {
112 return array( $this->TimingPointName => array( 'parameters' => true,
113 'static' => false,
114 'transform-children' => true,
115 'tree-transformation' => true,
116 'transform-parameters' => true ),
117 $this->AccumulatorName => array( 'parameters' => true,
118 'static' => false,
119 'transform-children' => true,
120 'tree-transformation' => true,
121 'transform-parameters' => true ),
122 $this->LogName => array( 'parameters' => true,
123 'static' => false,
124 'transform-children' => true,
125 'tree-transformation' => true,
126 'transform-parameters' => true ),
127 $this->TraceName => array( 'parameters' => true,
128 'static' => false,
129 'transform-children' => true,
130 'tree-transformation' => true,
131 'transform-parameters' => true ) );
132 }
133
134 function templateNodeTransformation( $functionName, &$node,
135 $tpl, $parameters, $privateData )
136 {
137 if ( $functionName == $this->TimingPointName )
138 {
139 $id = false;
140 if ( isset( $parameters['id'] ) )
141 {
142 if ( !eZTemplateNodeTool::isConstantElement( $parameters['id'] ) )
143 return false;
144 $id = eZTemplateNodeTool::elementConstantValue( $parameters['id'] );
145 }
146
147 $newNodes = array();
148
149 $startDescription = "debug-timing-point START: $id";
150 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "eZDebug::addTimingPoint( " . var_export( $startDescription, true ) . " );" );
151
152 $children = eZTemplateNodeTool::extractFunctionNodeChildren( $node );
153 $newNodes = array_merge( $newNodes, $children );
154
155 $endDescription = "debug-timing-point END: $id";
156 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "eZDebug::addTimingPoint( " . var_export( $endDescription, true ) . " );" );
157
158 return $newNodes;
159 }
160 else if ( $functionName == $this->AccumulatorName )
161 {
162 $id = false;
163 if ( isset( $parameters['id'] ) )
164 {
165 if ( !eZTemplateNodeTool::isConstantElement( $parameters['id'] ) )
166 return false;
167 $id = eZTemplateNodeTool::elementConstantValue( $parameters['id'] );
168 }
169
170 $name = false;
171 if ( isset( $parameters['name'] ) )
172 {
173 if ( !eZTemplateNodeTool::isConstantElement( $parameters['name'] ) )
174 return false;
175 $name = eZTemplateNodeTool::elementConstantValue( $parameters['name'] );
176 }
177 // Assign a name (as $functionName) which will be used in the debug output.
178 $name = ( $name === false and $id === false ) ? $functionName : $name;
179 // To uniquely identify this accumulator.
180 $id = $id === false ? uniqID( $functionName . '_' ): $id;
181 $newNodes = array();
182
183 if ( $name )
184 {
185 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "eZDebug::accumulatorStart( " . var_export( $id, true ) . ", 'Debug-Accumulator', " . var_export( $name, true ) . " );" );
186 }
187 else
188 {
189 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "eZDebug::accumulatorStart( " . var_export( $id, true ) . ", 'Debug-Accumulator' );" );
190 }
191
192 $children = eZTemplateNodeTool::extractFunctionNodeChildren( $node );
193 $newNodes = array_merge( $newNodes, $children );
194
195 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "eZDebug::accumulatorStop( " . var_export( $id, true ) . " );" );
196
197 return $newNodes;
198 }
199 else if ( $functionName == $this->LogName )
200 {
201 $nodePlacement = eZTemplateNodeTool::extractFunctionNodePlacement( $node );
202 $newNodes = array();
203
204 $varIsSet = $msgIsSet = false;
205 if ( isset( $parameters['var'] ) )
206 {
207 $varIsSet = true;
208 $var = $parameters['var'];
209 }
210 if ( isset( $parameters['msg'] ) )
211 {
212 $msgIsSet = true;
213 $msg = $parameters['msg'];
214 }
215
216 $newNodes[]= eZTemplateNodeTool::createCodePieceNode( "// debug-log starts\n" );
217
218 if ( $varIsSet )
219 $newNodes[] = eZTemplateNodeTool::createVariableNode( false, $var, $nodePlacement, array( 'treat-value-as-non-object' => true ), 'debug_log_var' );
220 if ( $msgIsSet )
221 $newNodes[] = eZTemplateNodeTool::createVariableNode( false, $msg, $nodePlacement, array( 'treat-value-as-non-object' => true ), 'debug_log_msg' );
222
223 if ( $varIsSet && $msgIsSet )
224 $newNodes[]= eZTemplateNodeTool::createCodePieceNode( "eZDebug::writeDebug( \$debug_log_var, \$debug_log_msg );\n" );
225 elseif ( $msgIsSet )
226 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "eZDebug::writeDebug( \$debug_log_msg );\n" );
227 elseif ( $varIsSet )
228 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "eZDebug::writeDebug( \$debug_log_var );\n" );
229
230 if ( $varIsSet )
231 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "unset( \$debug_log_var );" );
232 if ( $msgIsSet )
233 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "unset( \$debug_log_msg );" );
234
235 $newNodes[]= eZTemplateNodeTool::createCodePieceNode( "// debug-log ends\n" );
236
237 return $newNodes;
238 }
239 else if ( $functionName == $this->TraceName )
240 {
241 $id = false;
242 if ( isset( $parameters['id'] ) )
243 {
244 if ( !eZTemplateNodeTool::isConstantElement( $parameters['id'] ) )
245 return false;
246 $id = eZTemplateNodeTool::elementConstantValue( $parameters['id'] );
247 }
248
249 if ( !$id )
250 $id = 'template-debug';
251
252 $newNodes = array();
253
254 $code = ( "if ( extension_loaded( 'xdebug' ) )\n" .
255 "{\n" .
256 "if ( file_exists( " . var_export( $id . '.xt', true ) . " ) )\n" .
257 "{\n" .
258 "\$fd = fopen( " . var_export( $id . '.xt', true ) . ", 'w' ); fclose( \$fd ); unset( \$fd );\n" .
259 "}\n" .
260 "xdebug_start_trace( " . var_export( $id, true ) . " );\n" .
261 "}\n" );
262 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( $code );
263
264 $children = eZTemplateNodeTool::extractFunctionNodeChildren( $node );
265 $newNodes = array_merge( $newNodes, $children );
266
267 $code = ( "if ( extension_loaded( 'xdebug' ) )\n" .
268 "xdebug_stop_trace();\n" );
269 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( $code );
270
271 return $newNodes;
272 }
273 return false;
274 }
275
279 function process( $tpl, &$textElements, $functionName, $functionChildren, $functionParameters, $functionPlacement, $rootNamespace, $currentNamespace )
280 {
281 switch ( $functionName )
282 {
283 case $this->TimingPointName:
284 {
285 $children = $functionChildren;
286 $parameters = $functionParameters;
287
288 $id = false;
289 if ( isset( $parameters["id"] ) )
290 {
291 $id = $tpl->elementValue( $parameters["id"], $rootNamespace, $currentNamespace, $functionPlacement );
292 }
293
294
295 $startDescription = "debug-timing-point START: $id";
296 eZDebug::addTimingPoint( $startDescription );
297
298 if ( is_array( $children ) )
299 {
300 foreach ( array_keys( $children ) as $childKey )
301 {
302 $child =& $children[$childKey];
303 $tpl->processNode( $child, $textElements, $rootNamespace, $currentNamespace );
304 }
305 }
306
307 $endDescription = "debug-timing-point END: $id";
308 eZDebug::addTimingPoint( $endDescription );
309
310 } break;
311
312 case $this->AccumulatorName:
313 {
314 $children = $functionChildren;
315 $parameters = $functionParameters;
316
317 $id = false;
318 if ( isset( $parameters["id"] ) )
319 {
320 $id = $tpl->elementValue( $parameters["id"], $rootNamespace, $currentNamespace, $functionPlacement );
321 }
322
323 $name = false;
324 if ( isset( $parameters["name"] ) )
325 {
326 $name = $tpl->elementValue( $parameters["name"], $rootNamespace, $currentNamespace, $functionPlacement );
327 }
328
329 // Assign a name (as $functionName) which will be used in the debug output.
330 $name = ( $name === false and $id === false ) ? $functionName : $name;
331 // To uniquely identify this accumulator.
332 $id = $id === false ? uniqID( $functionName . '_' ): $id;
333
334 eZDebug::accumulatorStart( $id, 'Debug-Accumulator', $name );
335
336 if ( is_array( $children ) )
337 {
338 foreach ( array_keys( $children ) as $childKey )
339 {
340 $child =& $children[$childKey];
341 $tpl->processNode( $child, $textElements, $rootNamespace, $currentNamespace );
342 }
343 }
344
345 eZDebug::accumulatorStop( $id );
346
347 } break;
348
349 case $this->LogName:
350 {
351 $parameters = $functionParameters;
352
353 if ( isset( $parameters['var'] ) )
354 $var = $tpl->elementValue( $parameters['var'], $rootNamespace, $currentNamespace, $functionPlacement );
355 if ( isset( $parameters['msg'] ) )
356 $msg = $tpl->elementValue( $parameters['msg'], $rootNamespace, $currentNamespace, $functionPlacement );
357
358 if ( isset( $var ) && isset( $msg ) )
359 eZDebug::writeDebug( $var, $msg );
360 elseif ( isset( $msg ) )
361 eZDebug::writeDebug( $msg );
362 elseif ( isset( $var ) )
363 eZDebug::writeDebug( $var );
364 } break;
365
366 case $this->TraceName:
367 {
368 $children = $functionChildren;
369
370 $id = false;
371 // If we have XDebug we start the trace, execute children and stop it
372 // if not we just execute the children as normal
373 if ( extension_loaded( 'xdebug' ) )
374 {
375 $parameters = $functionParameters;
376 if ( isset( $parameters["id"] ) )
377 {
378 $id = $tpl->elementValue( $parameters["id"], $rootNamespace, $currentNamespace, $functionPlacement );
379 }
380
381 if ( !$id )
382 $id = 'template-debug';
383
384 // If we already have a file, make sure it is truncated
385 if ( file_exists( $id . '.xt' ) )
386 {
387 $fd = fopen( $id, '.xt', 'w' ); fclose( $fd );
388 }
389 xdebug_start_trace( $id );
390
391 if ( is_array( $children ) )
392 {
393 foreach ( array_keys( $children ) as $childKey )
394 {
395 $child =& $children[$childKey];
396 $tpl->processNode( $child, $textElements, $rootNamespace, $currentNamespace );
397 }
398 }
399
400 xdebug_stop_trace();
401 }
402 elseif ( is_array( $children ) )
403 {
404 foreach ( array_keys( $children ) as $childKey )
405 {
406 $child =& $children[$childKey];
407 $tpl->processNode( $child, $textElements, $rootNamespace, $currentNamespace );
408 }
409 }
410
411 } break;
412 }
413 }
414
418 function hasChildren()
419 {
420 return $this->attributeList();
421 }
422
425 public $DebugName;
426 public $AppendDebugName;
427 public $OnceName;
428 }
429
430 ?>
eZDebug\writeDebug
static writeDebug( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:588
eZDebug\addTimingPoint
static addTimingPoint( $description="")
Definition: ezdebug.php:676
eZDebug\accumulatorStart
static accumulatorStart( $key, $inGroup=false, $name=false, $recursive=false)
Definition: ezdebug.php:1361
eZDebug\accumulatorStop
static accumulatorStop( $key, $recursive=false)
Definition: ezdebug.php:1389
eZTemplateDebugFunction
Advanced debug handling.
Definition: eztemplatedebugfunction.php:63
eZTemplateDebugFunction\functionTemplateHints
functionTemplateHints()
Definition: eztemplatedebugfunction.php:110
eZTemplateDebugFunction\$LogName
$LogName
Definition: eztemplatedebugfunction.php:66
eZTemplateDebugFunction\$DebugName
$DebugName
Definition: eztemplatedebugfunction.php:425
eZTemplateDebugFunction\$OnceName
$OnceName
Definition: eztemplatedebugfunction.php:427
eZTemplateDebugFunction\attributeList
attributeList()
Definition: eztemplatedebugfunction.php:100
eZTemplateDebugFunction\__construct
__construct( $timingPoint='debug-timing-point', $accumulator='debug-accumulator', $log='debug-log', $trace='debug-trace')
Definition: eztemplatedebugfunction.php:76
eZTemplateDebugFunction\process
process( $tpl, &$textElements, $functionName, $functionChildren, $functionParameters, $functionPlacement, $rootNamespace, $currentNamespace)
Definition: eztemplatedebugfunction.php:279
eZTemplateDebugFunction\hasChildren
hasChildren()
Definition: eztemplatedebugfunction.php:418
eZTemplateDebugFunction\$TraceName
$TraceName
Definition: eztemplatedebugfunction.php:67
eZTemplateDebugFunction\functionList
functionList()
Definition: eztemplatedebugfunction.php:90
eZTemplateDebugFunction\$AccumulatorName
$AccumulatorName
Definition: eztemplatedebugfunction.php:65
eZTemplateDebugFunction\templateNodeTransformation
templateNodeTransformation( $functionName, &$node, $tpl, $parameters, $privateData)
Definition: eztemplatedebugfunction.php:134
eZTemplateDebugFunction\$AppendDebugName
$AppendDebugName
Definition: eztemplatedebugfunction.php:426
eZTemplateDebugFunction\$TimingPointName
$TimingPointName
Definition: eztemplatedebugfunction.php:64
eZTemplateNodeTool\createVariableNode
static createVariableNode( $originalNode=false, $variableData=false, $variablePlacement=false, $parameters=array(), $variableAssignmentName=false, $onlyExisting=false, $overWrite=true, $assignFromVariable=false, $rememberSet=false)
Definition: eztemplatenodetool.php:395
eZTemplateNodeTool\elementConstantValue
static elementConstantValue( $elements)
Definition: eztemplatenodetool.php:197
eZTemplateNodeTool\createCodePieceNode
static createCodePieceNode( $codePiece, $parameters=array())
Definition: eztemplatenodetool.php:457
eZTemplateNodeTool\extractFunctionNodePlacement
static extractFunctionNodePlacement(&$node)
Definition: eztemplatenodetool.php:660
eZTemplateNodeTool\extractFunctionNodeChildren
static extractFunctionNodeChildren(&$node)
Definition: eztemplatenodetool.php:669
eZTemplateNodeTool\isConstantElement
static isConstantElement( $elements)
Definition: eztemplatenodetool.php:233
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.