ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 ()
 

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.

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

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  }
$lineno
Definition: Node.php:22
Represents a node in the AST.
$attributes
Definition: Node.php:21
$nodes
Definition: Node.php:20

Member Function Documentation

◆ __toString()

Twig_Node::__toString ( )

Definition at line 51 of file Node.php.

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

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  }
$attributes
Definition: Node.php:21
count()
Definition: Node.php:209
+ Here is the call graph for this function:

◆ compile()

Twig_Node::compile ( Twig_Compiler  $compiler)

Compiles the node to PHP.

Implements Twig_NodeInterface.

Definition at line 114 of file Node.php.

Referenced by Twig_Node_Expression_Call\compileCallable().

115  {
116  foreach ($this->nodes as $node) {
117  $node->compile($compiler);
118  }
119  }
+ Here is the caller graph for this function:

◆ count()

◆ getAttribute()

Twig_Node::getAttribute (   $name)
Returns
mixed

Definition at line 152 of file Node.php.

References $name.

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

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  }
+ 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.

References $name.

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  }

◆ 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.

References $lineno.

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  }
$lineno
Definition: Node.php:22

◆ getNode()

Twig_Node::getNode (   $name)
Returns
Twig_Node

Definition at line 186 of file Node.php.

References $name.

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_Node_Expression_Binary_Power\compile(), Twig_Node_Expression_Binary_StartsWith\compile(), Twig_Node_Expression_Binary_Range\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_Filter\compile(), Twig_Node_Expression_Conditional\compile(), Twig_Node_Expression_Test_Sameas\compile(), Twig_Node_Expression_Unary\compile(), Twig_Node_Expression_Binary\compile(), Twig_Node_Expression_MethodCall\compile(), Twig_Node_Expression_Test_Null\compile(), Twig_Node_Expression_Test_Divisibleby\compile(), Twig_Node_Expression_Test_Even\compile(), Twig_Node_Expression_Test_Odd\compile(), Twig_Node_Expression_GetAttr\compile(), Twig_Node_Expression_NullCoalesce\compile(), Twig_Node_Sandbox\compile(), Twig_Node_Do\compile(), Twig_Node_Import\compile(), Twig_Node_SandboxedPrint\compile(), Twig_Node_Expression_Test_Constant\compile(), Twig_Node_Print\compile(), Twig_Node_Block\compile(), Twig_Node_Spaceless\compile(), Twig_Node_With\compile(), Twig_Node_AutoEscape\compile(), Twig_Node_If\compile(), Twig_Node_Macro\compile(), Twig_Extensions_Node_Trans\compile(), Twig_Node_For\compile(), Twig_Node_Expression_Filter_Default\compile(), Twig_Node_Set\compile(), Twig_Node_Expression_Test_Defined\compile(), Twig_Node_Expression_Call\compileArguments(), Twig_Node_Expression_BlockReference\compileBlockArguments(), Twig_Node_Module\compileClassFooter(), Twig_Node_Module\compileConstructor(), Twig_Node_Module\compileDisplay(), Twig_Node_Module\compileGetParent(), Twig_Node_Module\compileIsTraitable(), Twig_Node_Module\compileMacros(), Twig_Node_Module\compileTemplate(), Twig_Node_Expression_BlockReference\compileTemplateCall(), Twig_NodeVisitor_Sandbox\doEnterNode(), Twig_NodeVisitor_Escaper\doEnterNode(), Twig_Profiler_NodeVisitor_Profiler\doLeaveNode(), Twig_NodeVisitor_Sandbox\doLeaveNode(), Twig_NodeVisitor_SafeAnalysis\doLeaveNode(), Twig_NodeVisitor_Escaper\escapePrintNode(), Twig_TokenParser_For\parse(), Twig_NodeVisitor_Escaper\preEscapeFilterNode(), and Twig_Node_SandboxedPrint\removeNodeFilter().

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  }
+ Here is the caller graph for this function:

◆ getNodeTag()

Twig_Node::getNodeTag ( )

Implements Twig_NodeInterface.

Definition at line 136 of file Node.php.

References $tag.

Referenced by Twig_NodeVisitor_Sandbox\doEnterNode().

137  {
138  return $this->tag;
139  }
+ Here is the caller graph for this function:

◆ getTemplateLine()

◆ getTemplateName()

Twig_Node::getTemplateName ( )

◆ hasAttribute()

Twig_Node::hasAttribute (   $name)
Returns
bool

Definition at line 144 of file Node.php.

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

145  {
146  return array_key_exists($name, $this->attributes);
147  }
+ Here is the caller graph for this function:

◆ hasNode()

◆ removeAttribute()

Twig_Node::removeAttribute (   $name)

Definition at line 170 of file Node.php.

References $name.

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

◆ removeNode()

Twig_Node::removeNode (   $name)

Definition at line 204 of file Node.php.

References $name.

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

◆ 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.

References $name, and setTemplateName().

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
+ Here is the call graph for this function:

◆ setNode()

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

Definition at line 195 of file Node.php.

References $name.

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

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  }
Represents a node in the AST.
+ Here is the caller graph for this function:

◆ setTemplateName()

Twig_Node::setTemplateName (   $name)

Definition at line 219 of file Node.php.

References $name.

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

220  {
221  $this->name = $name;
222  foreach ($this->nodes as $node) {
223  if (null !== $node) {
224  $node->setTemplateName($name);
225  }
226  }
227  }
+ 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.

References $n, $name, and $xml.

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

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_Expression_Function\__construct(), Twig_Node_Expression_MethodCall\__construct(), Twig_Node_Expression_NullCoalesce\__construct(), Twig_Node_Expression_TempName\__construct(), Twig_Node_Expression_Test\__construct(), Twig_Node_Expression_Binary\__construct(), Twig_Node_Expression_Conditional\__construct(), Twig_Node_Expression_GetAttr\__construct(), Twig_Node_Expression_Filter\__construct(), Twig_Node_Expression_Constant\__construct(), Twig_Node_Expression_Unary\__construct(), Twig_Node_Expression_Array\__construct(), Twig_Node_SetTemp\__construct(), Twig_Node_ForLoop\__construct(), Twig_Node_Import\__construct(), Twig_Node_Do\__construct(), Twig_Node_Set\__construct(), Twig_Node_With\__construct(), Twig_Extensions_Node_Trans\__construct(), Twig_Node_Sandbox\__construct(), Twig_Node_Flush\__construct(), Twig_Node_Expression_Parent\__construct(), Twig_Node_Block\__construct(), Twig_Node_Print\__construct(), Twig_Node_Expression_Name\__construct(), Twig_Node_Include\__construct(), Twig_Node_Embed\__construct(), Twig_Node_If\__construct(), Twig_Node_Text\__construct(), Twig_Node_BlockReference\__construct(), Twig_Node_Macro\__construct(), Twig_Node_Spaceless\__construct(), Twig_Node_For\__construct(), Twig_Node_Expression_ExtensionReference\__construct(), Twig_Node_Expression_Filter_Default\__construct(), Twig_Node_Expression_BlockReference\__construct(), Twig_Node_AutoEscape\__construct(), Twig_Node_Expression_Test_Defined\__construct(), __construct(), getLine(), and getTemplateLine().

◆ $name

◆ $nodes

◆ $tag


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