ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Module.php File Reference

Go to the source code of this file.

Data Structures

class  Twig_Node_Module
 Represents a module node. More...
 

Functions

 compileDisplay (Twig_Compiler $compiler)
 
 compileClassFooter (Twig_Compiler $compiler)
 
 compileMacros (Twig_Compiler $compiler)
 
 compileGetTemplateName (Twig_Compiler $compiler)
 
 compileIsTraitable (Twig_Compiler $compiler)
 
 compileDebugInfo (Twig_Compiler $compiler)
 
 compileGetSource (Twig_Compiler $compiler)
 
 compileGetSourceContext (Twig_Compiler $compiler)
 
 compileLoadTemplate (Twig_Compiler $compiler, $node, $var)
 

Function Documentation

◆ compileClassFooter()

compileClassFooter ( Twig_Compiler  $compiler)
protected

Definition at line 322 of file Module.php.

323 {
324 $compiler
325 ->subcompile($this->getNode('class_end'))
326 ->outdent()
327 ->write("}\n")
328 ;
329 }
subcompile(Twig_NodeInterface $node, $raw=true)
Definition: Compiler.php:94

References Twig_Node\getNode(), and Twig_Compiler\subcompile().

Referenced by Twig_Node_Module\compileTemplate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ compileDebugInfo()

compileDebugInfo ( Twig_Compiler  $compiler)
protected

Definition at line 401 of file Module.php.

402 {
403 $compiler
404 ->write("public function getDebugInfo()\n", "{\n")
405 ->indent()
406 ->write(sprintf("return %s;\n", str_replace("\n", '', var_export(array_reverse($compiler->getDebugInfo(), true), true))))
407 ->outdent()
408 ->write("}\n\n")
409 ;
410 }
write()
Writes a string to the compiled code by adding indentation.
Definition: Compiler.php:124

References Twig_Compiler\getDebugInfo(), and Twig_Compiler\write().

Referenced by Twig_Node_Module\compileTemplate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ compileDisplay()

compileDisplay ( Twig_Compiler  $compiler)
protected

Definition at line 295 of file Module.php.

296 {
297 $compiler
298 ->write("protected function doDisplay(array \$context, array \$blocks = array())\n", "{\n")
299 ->indent()
300 ->subcompile($this->getNode('display_start'))
301 ->subcompile($this->getNode('body'))
302 ;
303
304 if ($this->hasNode('parent')) {
305 $parent = $this->getNode('parent');
306 $compiler->addDebugInfo($parent);
307 if ($parent instanceof Twig_Node_Expression_Constant) {
308 $compiler->write('$this->parent');
309 } else {
310 $compiler->write('$this->getParent($context)');
311 }
312 $compiler->raw("->display(\$context, array_merge(\$this->blocks, \$blocks));\n");
313 }
314
315 $compiler
316 ->subcompile($this->getNode('display_end'))
317 ->outdent()
318 ->write("}\n\n")
319 ;
320 }
raw($string)
Adds a raw string to the compiled code.
Definition: Compiler.php:112
addDebugInfo(Twig_NodeInterface $node)
Adds debugging information.
Definition: Compiler.php:212

References Twig_Compiler\addDebugInfo(), Twig_Node\getNode(), Twig_Node\hasNode(), Twig_Compiler\raw(), Twig_Compiler\subcompile(), and Twig_Compiler\write().

Referenced by Twig_Node_Module\compileTemplate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ compileGetSource()

compileGetSource ( Twig_Compiler  $compiler)
protected

Definition at line 412 of file Module.php.

413 {
414 $compiler
415 ->write("/** @deprecated since 1.27 (to be removed in 2.0). Use getSourceContext() instead */\n")
416 ->write("public function getSource()\n", "{\n")
417 ->indent()
418 ->write("@trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use getSourceContext() instead.', E_USER_DEPRECATED);\n\n")
419 ->write('return $this->getSourceContext()->getCode();')
420 ->raw("\n")
421 ->outdent()
422 ->write("}\n\n")
423 ;
424 }

References Twig_Compiler\write().

Referenced by Twig_Node_Module\compileTemplate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ compileGetSourceContext()

compileGetSourceContext ( Twig_Compiler  $compiler)
protected

Definition at line 426 of file Module.php.

427 {
428 $compiler
429 ->write("public function getSourceContext()\n", "{\n")
430 ->indent()
431 ->write('return new Twig_Source(')
432 ->string($compiler->getEnvironment()->isDebug() ? $this->source->getCode() : '')
433 ->raw(', ')
434 ->string($this->source->getName())
435 ->raw(', ')
436 ->string($this->source->getPath())
437 ->raw(");\n")
438 ->outdent()
439 ->write("}\n")
440 ;
441 }
getEnvironment()
Returns the environment instance related to this compiler.
Definition: Compiler.php:50

References Twig_Compiler\getEnvironment(), and Twig_Compiler\write().

Referenced by Twig_Node_Module\compileTemplate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ compileGetTemplateName()

compileGetTemplateName ( Twig_Compiler  $compiler)
protected

Definition at line 336 of file Module.php.

337 {
338 $compiler
339 ->write("public function getTemplateName()\n", "{\n")
340 ->indent()
341 ->write('return ')
342 ->repr($this->source->getName())
343 ->raw(";\n")
344 ->outdent()
345 ->write("}\n\n")
346 ;
347 }

References Twig_Compiler\write().

Referenced by Twig_Node_Module\compileTemplate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ compileIsTraitable()

compileIsTraitable ( Twig_Compiler  $compiler)
protected

Definition at line 349 of file Module.php.

350 {
351 // A template can be used as a trait if:
352 // * it has no parent
353 // * it has no macros
354 // * it has no body
355 //
356 // Put another way, a template can be used as a trait if it
357 // only contains blocks and use statements.
358 $traitable = !$this->hasNode('parent') && 0 === count($this->getNode('macros'));
359 if ($traitable) {
360 if ($this->getNode('body') instanceof Twig_Node_Body) {
361 $nodes = $this->getNode('body')->getNode(0);
362 } else {
363 $nodes = $this->getNode('body');
364 }
365
366 if (!count($nodes)) {
367 $nodes = new Twig_Node(array($nodes));
368 }
369
370 foreach ($nodes as $node) {
371 if (!count($node)) {
372 continue;
373 }
374
375 if ($node instanceof Twig_Node_Text && ctype_space($node->getAttribute('data'))) {
376 continue;
377 }
378
379 if ($node instanceof Twig_Node_BlockReference) {
380 continue;
381 }
382
383 $traitable = false;
384 break;
385 }
386 }
387
388 if ($traitable) {
389 return;
390 }
391
392 $compiler
393 ->write("public function isTraitable()\n", "{\n")
394 ->indent()
395 ->write(sprintf("return %s;\n", $traitable ? 'true' : 'false'))
396 ->outdent()
397 ->write("}\n\n")
398 ;
399 }
Represents a block call node.
Represents a body node.
Definition: Body.php:18
Represents a text node.
Definition: Text.php:19
Represents a node in the AST.
Definition: Node.php:19

References Twig_Node\$nodes, Twig_Node\count(), Twig_Node\getNode(), Twig_Node\hasNode(), and Twig_Compiler\write().

Referenced by Twig_Node_Module\compileTemplate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ compileLoadTemplate()

compileLoadTemplate ( Twig_Compiler  $compiler,
  $node,
  $var 
)
protected

Definition at line 443 of file Module.php.

444 {
445 if ($node instanceof Twig_Node_Expression_Constant) {
446 $compiler
447 ->write(sprintf('%s = $this->loadTemplate(', $var))
448 ->subcompile($node)
449 ->raw(', ')
450 ->repr($node->getTemplateName())
451 ->raw(', ')
452 ->repr($node->getTemplateLine())
453 ->raw(");\n")
454 ;
455 } else {
456 throw new LogicException('Trait templates can only be constant nodes.');
457 }
458 }

References Twig_Compiler\write().

Referenced by Twig_Node_Module\compileConstructor().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ compileMacros()

compileMacros ( Twig_Compiler  $compiler)
protected

Definition at line 331 of file Module.php.

332 {
333 $compiler->subcompile($this->getNode('macros'));
334 }

References Twig_Node\getNode(), and Twig_Compiler\subcompile().

Referenced by Twig_Node_Module\compileTemplate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: