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

Represents a set node. More...

+ Inheritance diagram for Twig_Node_Set:
+ Collaboration diagram for Twig_Node_Set:

Public Member Functions

 __construct ($capture, Twig_NodeInterface $names, Twig_NodeInterface $values, $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 ()
 

Additional Inherited Members

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

Detailed Description

Represents a set node.

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

Definition at line 17 of file Set.php.

Constructor & Destructor Documentation

◆ __construct()

Twig_Node_Set::__construct (   $capture,
Twig_NodeInterface  $names,
Twig_NodeInterface  $values,
  $lineno,
  $tag = null 
)

Definition at line 19 of file Set.php.

References Twig_Node\$lineno, Twig_Node\$tag, Twig_Node\getAttribute(), Twig_Node\getNode(), Twig_Node\setAttribute(), and Twig_Node\setNode().

20  {
21  parent::__construct(array('names' => $names, 'values' => $values), array('capture' => $capture, 'safe' => false), $lineno, $tag);
22 
23  /*
24  * Optimizes the node when capture is used for a large block of text.
25  *
26  * {% set foo %}foo{% endset %} is compiled to $context['foo'] = new Twig_Markup("foo");
27  */
28  if ($this->getAttribute('capture')) {
29  $this->setAttribute('safe', true);
30 
31  $values = $this->getNode('values');
32  if ($values instanceof Twig_Node_Text) {
33  $this->setNode('values', new Twig_Node_Expression_Constant($values->getAttribute('data'), $values->getTemplateLine()));
34  $this->setAttribute('capture', false);
35  }
36  }
37  }
$lineno
Definition: Node.php:22
setNode($name, $node=null)
Definition: Node.php:195
getAttribute($name)
Definition: Node.php:152
getNode($name)
Definition: Node.php:186
Represents a text node.
Definition: Text.php:18
setAttribute($name, $value)
Definition: Node.php:165
+ Here is the call graph for this function:

Member Function Documentation

◆ compile()

Twig_Node_Set::compile ( Twig_Compiler  $compiler)

Compiles the node to PHP.

Implements Twig_NodeInterface.

Definition at line 39 of file Set.php.

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

40  {
41  $compiler->addDebugInfo($this);
42 
43  if (count($this->getNode('names')) > 1) {
44  $compiler->write('list(');
45  foreach ($this->getNode('names') as $idx => $node) {
46  if ($idx) {
47  $compiler->raw(', ');
48  }
49 
50  $compiler->subcompile($node);
51  }
52  $compiler->raw(')');
53  } else {
54  if ($this->getAttribute('capture')) {
55  $compiler
56  ->write("ob_start();\n")
57  ->subcompile($this->getNode('values'))
58  ;
59  }
60 
61  $compiler->subcompile($this->getNode('names'), false);
62 
63  if ($this->getAttribute('capture')) {
64  $compiler->raw(" = ('' === \$tmp = ob_get_clean()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset())");
65  }
66  }
67 
68  if (!$this->getAttribute('capture')) {
69  $compiler->raw(' = ');
70 
71  if (count($this->getNode('names')) > 1) {
72  $compiler->write('array(');
73  foreach ($this->getNode('values') as $idx => $value) {
74  if ($idx) {
75  $compiler->raw(', ');
76  }
77 
78  $compiler->subcompile($value);
79  }
80  $compiler->raw(')');
81  } else {
82  if ($this->getAttribute('safe')) {
83  $compiler
84  ->raw("('' === \$tmp = ")
85  ->subcompile($this->getNode('values'))
86  ->raw(") ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset())")
87  ;
88  } else {
89  $compiler->subcompile($this->getNode('values'));
90  }
91  }
92  }
93 
94  $compiler->raw(";\n");
95  }
raw($string)
Adds a raw string to the compiled code.
Definition: Compiler.php:112
subcompile(Twig_NodeInterface $node, $raw=true)
Definition: Compiler.php:94
getAttribute($name)
Definition: Node.php:152
getNode($name)
Definition: Node.php:186
count()
Definition: Node.php:209
addDebugInfo(Twig_NodeInterface $node)
Adds debugging information.
Definition: Compiler.php:212
write()
Writes a string to the compiled code by adding indentation.
Definition: Compiler.php:124
+ Here is the call graph for this function:

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