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

Twig_NodeTraverser is a node traverser. More...

+ Collaboration diagram for Twig_NodeTraverser:

Public Member Functions

 __construct (Twig_Environment $env, array $visitors=array())
 
 addVisitor (Twig_NodeVisitorInterface $visitor)
 
 traverse (Twig_NodeInterface $node)
 Traverses a node and calls the registered visitors. More...
 

Protected Member Functions

 traverseForVisitor (Twig_NodeVisitorInterface $visitor, Twig_NodeInterface $node=null)
 

Protected Attributes

 $env
 
 $visitors = array()
 

Detailed Description

Twig_NodeTraverser is a node traverser.

It visits all nodes and their children and calls the given visitor for each.

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

Definition at line 21 of file NodeTraverser.php.

Constructor & Destructor Documentation

◆ __construct()

Twig_NodeTraverser::__construct ( Twig_Environment  $env,
array  $visitors = array() 
)
Parameters
Twig_Environment$env
Twig_NodeVisitorInterface[]$visitors

Definition at line 30 of file NodeTraverser.php.

References $env, $visitors, and addVisitor().

31  {
32  $this->env = $env;
33  foreach ($visitors as $visitor) {
34  $this->addVisitor($visitor);
35  }
36  }
addVisitor(Twig_NodeVisitorInterface $visitor)
+ Here is the call graph for this function:

Member Function Documentation

◆ addVisitor()

Twig_NodeTraverser::addVisitor ( Twig_NodeVisitorInterface  $visitor)

Definition at line 38 of file NodeTraverser.php.

References array, and Twig_NodeVisitorInterface\getPriority().

Referenced by __construct().

39  {
40  if (!isset($this->visitors[$visitor->getPriority()])) {
41  $this->visitors[$visitor->getPriority()] = array();
42  }
43 
44  $this->visitors[$visitor->getPriority()][] = $visitor;
45  }
getPriority()
Returns the priority for this visitor.
Create styles array
The data for the language used.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ traverse()

Twig_NodeTraverser::traverse ( Twig_NodeInterface  $node)

Traverses a node and calls the registered visitors.

Returns
Twig_NodeInterface

Definition at line 52 of file NodeTraverser.php.

References $visitors, and traverseForVisitor().

53  {
54  ksort($this->visitors);
55  foreach ($this->visitors as $visitors) {
56  foreach ($visitors as $visitor) {
57  $node = $this->traverseForVisitor($visitor, $node);
58  }
59  }
60 
61  return $node;
62  }
traverseForVisitor(Twig_NodeVisitorInterface $visitor, Twig_NodeInterface $node=null)
+ Here is the call graph for this function:

◆ traverseForVisitor()

Twig_NodeTraverser::traverseForVisitor ( Twig_NodeVisitorInterface  $visitor,
Twig_NodeInterface  $node = null 
)
protected

Definition at line 64 of file NodeTraverser.php.

References $n, Twig_NodeVisitorInterface\enterNode(), and Twig_NodeVisitorInterface\leaveNode().

Referenced by traverse().

65  {
66  if (null === $node) {
67  return;
68  }
69 
70  $node = $visitor->enterNode($node, $this->env);
71 
72  foreach ($node as $k => $n) {
73  if (false !== $n = $this->traverseForVisitor($visitor, $n)) {
74  $node->setNode($k, $n);
75  } else {
76  $node->removeNode($k);
77  }
78  }
79 
80  return $visitor->leaveNode($node, $this->env);
81  }
enterNode(Twig_NodeInterface $node, Twig_Environment $env)
Called before child nodes are visited.
traverseForVisitor(Twig_NodeVisitorInterface $visitor, Twig_NodeInterface $node=null)
$n
Definition: RandomTest.php:85
leaveNode(Twig_NodeInterface $node, Twig_Environment $env)
Called after child nodes are visited.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $env

Twig_NodeTraverser::$env
protected

Definition at line 23 of file NodeTraverser.php.

Referenced by __construct().

◆ $visitors

Twig_NodeTraverser::$visitors = array()
protected

Definition at line 24 of file NodeTraverser.php.

Referenced by __construct(), and traverse().


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