ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Twig_Node_If Class Reference

Represents an if node. More...

+ Inheritance diagram for Twig_Node_If:
+ Collaboration diagram for Twig_Node_If:

Public Member Functions

 __construct (Twig_NodeInterface $tests, Twig_NodeInterface $else=null, $lineno, $tag=null)
 
 compile (Twig_Compiler $compiler)
 Compiles the node to PHP. More...
 
- Public Member Functions inherited from Twig_Node
 __construct (array $nodes=array(), array $attributes=array(), $lineno=0, $tag=null)
 Constructor. More...
 
 __toString ()
 
 toXml ($asDom=false)
 
 compile (Twig_Compiler $compiler)
 Compiles the node to PHP. More...
 
 getTemplateLine ()
 
 getLine ()
 
 getNodeTag ()
 
 hasAttribute ($name)
 
 getAttribute ($name)
 
 setAttribute ($name, $value)
 
 removeAttribute ($name)
 
 hasNode ($name)
 
 getNode ($name)
 
 setNode ($name, $node=null)
 
 removeNode ($name)
 
 count ()
 
 getIterator ()
 
 setTemplateName ($name)
 
 getTemplateName ()
 
 setFilename ($name)
 
 getFilename ()
 
 compile (Twig_Compiler $compiler)
 Compiles the node to PHP. More...
 
 getLine ()
 
 getNodeTag ()
 

Additional Inherited Members

- Protected Attributes inherited from Twig_Node
 $nodes
 
 $attributes
 
 $lineno
 
 $tag
 

Detailed Description

Represents an if node.

Author
Fabien Potencier fabie.nosp@m.n@sy.nosp@m.mfony.nosp@m..com

Definition at line 18 of file If.php.

Constructor & Destructor Documentation

◆ __construct()

Twig_Node_If::__construct ( Twig_NodeInterface  $tests,
Twig_NodeInterface  $else = null,
  $lineno,
  $tag = null 
)

Definition at line 20 of file If.php.

21 {
22 $nodes = array('tests' => $tests);
23 if (null !== $else) {
24 $nodes['else'] = $else;
25 }
26
27 parent::__construct($nodes, array(), $lineno, $tag);
28 }
$lineno
Definition: Node.php:22
$nodes
Definition: Node.php:20
$tests
Definition: bench.php:104

References Twig_Node\$lineno, Twig_Node\$nodes, Twig_Node\$tag, and $tests.

Member Function Documentation

◆ compile()

Twig_Node_If::compile ( Twig_Compiler  $compiler)

Compiles the node to PHP.

Reimplemented from Twig_Node.

Definition at line 30 of file If.php.

31 {
32 $compiler->addDebugInfo($this);
33 for ($i = 0, $count = count($this->getNode('tests')); $i < $count; $i += 2) {
34 if ($i > 0) {
35 $compiler
36 ->outdent()
37 ->write('} elseif (')
38 ;
39 } else {
40 $compiler
41 ->write('if (')
42 ;
43 }
44
45 $compiler
46 ->subcompile($this->getNode('tests')->getNode($i))
47 ->raw(") {\n")
48 ->indent()
49 ->subcompile($this->getNode('tests')->getNode($i + 1))
50 ;
51 }
52
53 if ($this->hasNode('else')) {
54 $compiler
55 ->outdent()
56 ->write("} else {\n")
57 ->indent()
58 ->subcompile($this->getNode('else'))
59 ;
60 }
61
62 $compiler
63 ->outdent()
64 ->write("}\n");
65 }
addDebugInfo(Twig_NodeInterface $node)
Adds debugging information.
Definition: Compiler.php:212
outdent($step=1)
Outdents the generated code.
Definition: Compiler.php:267
subcompile(Twig_NodeInterface $node, $raw=true)
Definition: Compiler.php:94
write()
Writes a string to the compiled code by adding indentation.
Definition: Compiler.php:124
hasNode($name)
Definition: Node.php:178
getNode($name)
Definition: Node.php:186
count()
Definition: Node.php:209
$i
Definition: disco.tpl.php:19

References $i, Twig_Compiler\addDebugInfo(), Twig_Node\count(), Twig_Node\getNode(), Twig_Node\hasNode(), Twig_Compiler\outdent(), Twig_Compiler\subcompile(), and Twig_Compiler\write().

+ Here is the call graph for this function:

The documentation for this class was generated from the following file: