ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Twig_Node Class Reference

Represents a node in the AST. More...

+ Inheritance diagram for Twig_Node:
+ Collaboration diagram for Twig_Node:

Public Member Functions

 __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 ()
 

Protected Attributes

 $nodes
 
 $attributes
 
 $lineno
 
 $tag
 

Private Attributes

 $name
 

Detailed Description

Represents a node in the AST.

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

Definition at line 18 of file Node.php.

Constructor & Destructor Documentation

◆ __construct()

Twig_Node::__construct ( array  $nodes = array(),
array  $attributes = array(),
  $lineno = 0,
  $tag = null 
)

Constructor.

The nodes are automatically made available as properties ($this->node). The attributes are automatically made available as array items ($this['name']).

Parameters
array$nodesAn array of named nodes
array$attributesAn array of attributes (should not be nodes)
int$linenoThe line number
string$tagThe tag name associated with the Node

Definition at line 38 of file Node.php.

39 {
40 foreach ($nodes as $name => $node) {
41 if (!$node instanceof Twig_NodeInterface) {
42 @trigger_error(sprintf('Using "%s" for the value of node "%s" of "%s" is deprecated since version 1.25 and will be removed in 2.0.', is_object($node) ? get_class($node) : null === $node ? 'null' : gettype($node), $name, get_class($this)), E_USER_DEPRECATED);
43 }
44 }
45 $this->nodes = $nodes;
46 $this->attributes = $attributes;
47 $this->lineno = $lineno;
48 $this->tag = $tag;
49 }
sprintf('%.4f', $callTime)
$lineno
Definition: Node.php:22
$nodes
Definition: Node.php:20
$attributes
Definition: Node.php:21
Represents a node in the AST.

References $attributes, $lineno, $name, $nodes, $tag, and sprintf.

Member Function Documentation

◆ __toString()

Twig_Node::__toString ( )

Definition at line 51 of file Node.php.

52 {
53 $attributes = array();
54 foreach ($this->attributes as $name => $value) {
55 $attributes[] = sprintf('%s: %s', $name, str_replace("\n", '', var_export($value, true)));
56 }
57
58 $repr = array(get_class($this).'('.implode(', ', $attributes));
59
60 if (count($this->nodes)) {
61 foreach ($this->nodes as $name => $node) {
62 $len = strlen($name) + 4;
63 $noderepr = array();
64 foreach (explode("\n", (string) $node) as $line) {
65 $noderepr[] = str_repeat(' ', $len).$line;
66 }
67
68 $repr[] = sprintf(' %s: %s', $name, ltrim(implode("\n", $noderepr)));
69 }
70
71 $repr[] = ')';
72 } else {
73 $repr[0] .= ')';
74 }
75
76 return implode("\n", $repr);
77 }
count()
Definition: Node.php:209

References $attributes, $name, count(), and sprintf.

+ Here is the call graph for this function:

◆ compile()

Twig_Node::compile ( Twig_Compiler  $compiler)

Compiles the node to PHP.

Implements Twig_NodeInterface.

Reimplemented in Twig_Extensions_Node_Trans, Twig_Node_AutoEscape, Twig_Node_Block, Twig_Node_BlockReference, Twig_Node_CheckSecurity, Twig_Node_Do, Twig_Node_Expression_Array, Twig_Node_Expression_AssignName, Twig_Node_Expression_Binary, Twig_Node_Expression_Binary_EndsWith, Twig_Node_Expression_Binary_FloorDiv, Twig_Node_Expression_Binary_In, Twig_Node_Expression_Binary_Matches, Twig_Node_Expression_Binary_NotIn, Twig_Node_Expression_Binary_Power, Twig_Node_Expression_Binary_Range, Twig_Node_Expression_Binary_StartsWith, Twig_Node_Expression_BlockReference, Twig_Node_Expression_Conditional, Twig_Node_Expression_Constant, Twig_Node_Expression_ExtensionReference, Twig_Node_Expression_Filter, Twig_Node_Expression_Filter_Default, Twig_Node_Expression_Function, Twig_Node_Expression_GetAttr, Twig_Node_Expression_MethodCall, Twig_Node_Expression_Name, Twig_Node_Expression_NullCoalesce, Twig_Node_Expression_Parent, Twig_Node_Expression_TempName, Twig_Node_Expression_Test, Twig_Node_Expression_Test_Constant, Twig_Node_Expression_Test_Defined, Twig_Node_Expression_Test_Divisibleby, Twig_Node_Expression_Test_Even, Twig_Node_Expression_Test_Null, Twig_Node_Expression_Test_Odd, Twig_Node_Expression_Test_Sameas, Twig_Node_Expression_Unary, Twig_Node_Flush, Twig_Node_For, Twig_Node_ForLoop, Twig_Node_If, Twig_Node_Import, Twig_Node_Include, Twig_Node_Macro, Twig_Node_Module, Twig_Node_Print, Twig_Node_Sandbox, Twig_Node_SandboxedPrint, Twig_Node_Set, Twig_Node_SetTemp, Twig_Node_Spaceless, Twig_Node_Text, Twig_Node_With, Twig_Profiler_Node_EnterProfile, and Twig_Profiler_Node_LeaveProfile.

Definition at line 114 of file Node.php.

115 {
116 foreach ($this->nodes as $node) {
117 $node->compile($compiler);
118 }
119 }

Referenced by Twig_Node_Expression_Call\compileCallable().

+ Here is the caller graph for this function:

◆ count()

Twig_Node::count ( )

◆ getAttribute()

Twig_Node::getAttribute (   $name)
Returns
mixed

Definition at line 152 of file Node.php.

153 {
154 if (!array_key_exists($name, $this->attributes)) {
155 throw new LogicException(sprintf('Attribute "%s" does not exist for Node "%s".', $name, get_class($this)));
156 }
157
158 return $this->attributes[$name];
159 }

References $name, and sprintf.

Referenced by Twig_Node_Set\__construct(), Twig_Node_Expression_Array\__construct(), Twig_Node_Expression_Filter_Default\__construct(), Twig_Node_Embed\addGetTemplate(), Twig_Node_Include\addTemplateArguments(), Twig_Extensions_Node_Trans\compile(), Twig_Node_Block\compile(), Twig_Node_BlockReference\compile(), Twig_Node_Expression_AssignName\compile(), Twig_Node_Expression_BlockReference\compile(), Twig_Node_Expression_Constant\compile(), Twig_Node_Expression_ExtensionReference\compile(), Twig_Node_Expression_Function\compile(), Twig_Node_Expression_GetAttr\compile(), Twig_Node_Expression_MethodCall\compile(), Twig_Node_Expression_Name\compile(), Twig_Node_Expression_Parent\compile(), Twig_Node_Expression_TempName\compile(), Twig_Node_Expression_Test\compile(), Twig_Node_For\compile(), Twig_Node_ForLoop\compile(), Twig_Node_Import\compile(), Twig_Node_Include\compile(), Twig_Node_Macro\compile(), Twig_Node_Module\compile(), Twig_Node_Set\compile(), Twig_Node_SetTemp\compile(), Twig_Node_Text\compile(), Twig_Node_With\compile(), Twig_Profiler_Node_EnterProfile\compile(), Twig_Profiler_Node_LeaveProfile\compile(), Twig_Node_Expression_Call\compileArguments(), Twig_Node_Expression_Call\compileCallable(), Twig_Extensions_Node_Trans\compileString(), Twig_Node_Module\compileTemplate(), Twig_NodeVisitor_Escaper\doEnterNode(), Twig_NodeVisitor_Sandbox\doEnterNode(), Twig_NodeVisitor_Escaper\doLeaveNode(), Twig_NodeVisitor_SafeAnalysis\doLeaveNode(), Twig_Profiler_NodeVisitor_Profiler\doLeaveNode(), Twig_Node_Expression_Call\getArguments(), Twig_Node_Expression_Call\getCallableParameters(), Twig_Node_Expression_Name\isSimple(), and Twig_Node_Expression_Name\isSpecial().

+ Here is the caller graph for this function:

◆ getFilename()

Twig_Node::getFilename ( )
Deprecated:
since 1.27 (to be removed in 2.0)

Definition at line 247 of file Node.php.

248 {
249 @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use getTemplateName() instead.', E_USER_DEPRECATED);
250
251 return $this->name;
252 }

References $name.

◆ getIterator()

Twig_Node::getIterator ( )

Definition at line 214 of file Node.php.

215 {
216 return new ArrayIterator($this->nodes);
217 }

◆ getLine()

Twig_Node::getLine ( )
Deprecated:
since 1.27 (to be removed in 2.0)

Implements Twig_NodeInterface.

Definition at line 129 of file Node.php.

130 {
131 @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use getTemplateLine() instead.', E_USER_DEPRECATED);
132
133 return $this->lineno;
134 }

References $lineno.

Referenced by Twig_ExpressionParser\parseSubscriptExpression().

+ Here is the caller graph for this function:

◆ getNode()

Twig_Node::getNode (   $name)
Returns
Twig_Node

Definition at line 186 of file Node.php.

187 {
188 if (!array_key_exists($name, $this->nodes)) {
189 throw new LogicException(sprintf('Node "%s" does not exist for Node "%s".', $name, get_class($this)));
190 }
191
192 return $this->nodes[$name];
193 }

References $name, and sprintf.

Referenced by Twig_Node_Set\__construct(), Twig_Node_Include\addGetTemplate(), Twig_Node_Include\addTemplateArguments(), Twig_Node_Expression_Test_Defined\changeIgnoreStrictCheck(), Twig_Extensions_TokenParser_Trans\checkTransString(), Twig_Extensions_Node_Trans\compile(), Twig_Node_AutoEscape\compile(), Twig_Node_Block\compile(), Twig_Node_Do\compile(), Twig_Node_Expression_Binary\compile(), Twig_Node_Expression_Binary_EndsWith\compile(), Twig_Node_Expression_Binary_In\compile(), Twig_Node_Expression_Binary_Matches\compile(), Twig_Node_Expression_Binary_NotIn\compile(), Twig_Node_Expression_Binary_Power\compile(), Twig_Node_Expression_Binary_Range\compile(), Twig_Node_Expression_Binary_StartsWith\compile(), Twig_Node_Expression_Conditional\compile(), Twig_Node_Expression_Filter\compile(), Twig_Node_Expression_Filter_Default\compile(), Twig_Node_Expression_GetAttr\compile(), Twig_Node_Expression_MethodCall\compile(), Twig_Node_Expression_NullCoalesce\compile(), Twig_Node_Expression_Test_Constant\compile(), Twig_Node_Expression_Test_Defined\compile(), Twig_Node_Expression_Test_Divisibleby\compile(), Twig_Node_Expression_Test_Even\compile(), Twig_Node_Expression_Test_Null\compile(), Twig_Node_Expression_Test_Odd\compile(), Twig_Node_Expression_Test_Sameas\compile(), Twig_Node_Expression_Unary\compile(), Twig_Node_For\compile(), Twig_Node_If\compile(), Twig_Node_Import\compile(), Twig_Node_Macro\compile(), Twig_Node_Print\compile(), Twig_Node_Sandbox\compile(), Twig_Node_SandboxedPrint\compile(), Twig_Node_Set\compile(), Twig_Node_Spaceless\compile(), Twig_Node_With\compile(), Twig_Node_Expression_Call\compileArguments(), Twig_Node_Expression_BlockReference\compileBlockArguments(), compileClassFooter(), Twig_Node_Module\compileConstructor(), compileDisplay(), Twig_Node_Module\compileGetParent(), compileIsTraitable(), compileMacros(), Twig_Node_Module\compileTemplate(), Twig_Node_Expression_BlockReference\compileTemplateCall(), Twig_NodeVisitor_Escaper\doEnterNode(), Twig_NodeVisitor_Sandbox\doEnterNode(), Twig_NodeVisitor_SafeAnalysis\doLeaveNode(), Twig_NodeVisitor_Sandbox\doLeaveNode(), Twig_Profiler_NodeVisitor_Profiler\doLeaveNode(), Twig_NodeVisitor_Escaper\escapePrintNode(), Twig_NodeVisitor_Escaper\preEscapeFilterNode(), and Twig_Node_SandboxedPrint\removeNodeFilter().

+ Here is the caller graph for this function:

◆ getNodeTag()

Twig_Node::getNodeTag ( )

Implements Twig_NodeInterface.

Definition at line 136 of file Node.php.

137 {
138 return $this->tag;
139 }

References $tag.

Referenced by Twig_NodeVisitor_Sandbox\doEnterNode().

+ Here is the caller graph for this function:

◆ getTemplateLine()

◆ getTemplateName()

◆ hasAttribute()

Twig_Node::hasAttribute (   $name)
Returns
bool

Definition at line 144 of file Node.php.

145 {
146 return array_key_exists($name, $this->attributes);
147 }

References $name.

Referenced by Twig_Node_Expression_Call\compileArguments(), Twig_Node_Expression_Call\compileCallable(), Twig_Node_Expression_Call\getArguments(), and Twig_Node_Expression_Call\getCallableParameters().

+ Here is the caller graph for this function:

◆ hasNode()

◆ removeAttribute()

Twig_Node::removeAttribute (   $name)

Definition at line 170 of file Node.php.

171 {
172 unset($this->attributes[$name]);
173 }

References $name.

◆ removeNode()

Twig_Node::removeNode (   $name)

Definition at line 204 of file Node.php.

205 {
206 unset($this->nodes[$name]);
207 }

References $name.

◆ setAttribute()

Twig_Node::setAttribute (   $name,
  $value 
)

◆ setFilename()

Twig_Node::setFilename (   $name)
Deprecated:
since 1.27 (to be removed in 2.0)

Definition at line 237 of file Node.php.

238 {
239 @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use setTemplateName() instead.', E_USER_DEPRECATED);
240
241 $this->setTemplateName($name);
242 }
setTemplateName($name)
Definition: Node.php:219

References $name, and setTemplateName().

+ Here is the call graph for this function:

◆ setNode()

Twig_Node::setNode (   $name,
  $node = null 
)

Definition at line 195 of file Node.php.

196 {
197 if (!$node instanceof Twig_NodeInterface) {
198 @trigger_error(sprintf('Using "%s" for the value of node "%s" of "%s" is deprecated since version 1.25 and will be removed in 2.0.', is_object($node) ? get_class($node) : null === $node ? 'null' : gettype($node), $name, get_class($this)), E_USER_DEPRECATED);
199 }
200
201 $this->nodes[$name] = $node;
202 }

References $name, and sprintf.

Referenced by Twig_Node_Set\__construct(), Twig_NodeVisitor_Sandbox\doLeaveNode(), Twig_Profiler_NodeVisitor_Profiler\doLeaveNode(), and Twig_NodeVisitor_Escaper\preEscapeFilterNode().

+ Here is the caller graph for this function:

◆ setTemplateName()

Twig_Node::setTemplateName (   $name)

Definition at line 219 of file Node.php.

220 {
221 $this->name = $name;
222 foreach ($this->nodes as $node) {
223 if (null !== $node) {
224 $node->setTemplateName($name);
225 }
226 }
227 }

References $name.

Referenced by Twig_Node_Module\__construct(), and setFilename().

+ Here is the caller graph for this function:

◆ toXml()

Twig_Node::toXml (   $asDom = false)
Deprecated:
since 1.16.1 (to be removed in 2.0)

Definition at line 82 of file Node.php.

83 {
84 @trigger_error(sprintf('%s is deprecated since version 1.16.1 and will be removed in 2.0.', __METHOD__), E_USER_DEPRECATED);
85
86 $dom = new DOMDocument('1.0', 'UTF-8');
87 $dom->formatOutput = true;
88 $dom->appendChild($xml = $dom->createElement('twig'));
89
90 $xml->appendChild($node = $dom->createElement('node'));
91 $node->setAttribute('class', get_class($this));
92
93 foreach ($this->attributes as $name => $value) {
94 $node->appendChild($attribute = $dom->createElement('attribute'));
95 $attribute->setAttribute('name', $name);
96 $attribute->appendChild($dom->createTextNode($value));
97 }
98
99 foreach ($this->nodes as $name => $n) {
100 if (null === $n) {
101 continue;
102 }
103
104 $child = $n->toXml(true)->getElementsByTagName('node')->item(0);
105 $child = $dom->importNode($child, true);
106 $child->setAttribute('name', $name);
107
108 $node->appendChild($child);
109 }
110
111 return $asDom ? $dom : $dom->saveXML();
112 }
$n
Definition: RandomTest.php:85
$xml
Definition: metadata.php:240

References $n, $name, $xml, and sprintf.

Field Documentation

◆ $attributes

Twig_Node::$attributes
protected

Definition at line 21 of file Node.php.

Referenced by __construct(), and __toString().

◆ $lineno

Twig_Node::$lineno
protected

Definition at line 22 of file Node.php.

Referenced by Twig_Node_Set\__construct(), Twig_Node_Text\__construct(), Twig_Node_Flush\__construct(), Twig_Node_ForLoop\__construct(), Twig_Node_Embed\__construct(), Twig_Node_Expression_Name\__construct(), Twig_Node_Expression_TempName\__construct(), Twig_Node_SetTemp\__construct(), Twig_Node_BlockReference\__construct(), Twig_Node_Expression_ExtensionReference\__construct(), Twig_Node_Expression_Parent\__construct(), Twig_Node_Expression_Function\__construct(), Twig_Node_Block\__construct(), Twig_Node_Macro\__construct(), Twig_Node_Expression_Constant\__construct(), Twig_Node_AutoEscape\__construct(), Twig_Node_Expression_Array\__construct(), __construct(), Twig_Extensions_Node_Trans\__construct(), Twig_Node_With\__construct(), Twig_Node_Do\__construct(), Twig_Node_Print\__construct(), Twig_Node_Import\__construct(), Twig_Node_Include\__construct(), Twig_Node_Expression_Conditional\__construct(), Twig_Node_Expression_MethodCall\__construct(), Twig_Node_Expression_GetAttr\__construct(), Twig_Node_For\__construct(), Twig_Node_Spaceless\__construct(), Twig_Node_Sandbox\__construct(), Twig_Node_Expression_Binary\__construct(), Twig_Node_Expression_NullCoalesce\__construct(), Twig_Node_Expression_BlockReference\__construct(), Twig_Node_Expression_Unary\__construct(), Twig_Node_Expression_Test\__construct(), Twig_Node_Expression_Test_Defined\__construct(), Twig_Node_Expression_Filter\__construct(), Twig_Node_Expression_Filter_Default\__construct(), Twig_Node_If\__construct(), getLine(), and getTemplateLine().

◆ $name

◆ $nodes

◆ $tag


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