*/
public function addVisitor(Twig_NodeVisitorInterface $visitor)
{
- $this->visitors[] = $visitor;
+ if (!isset($this->visitors[$visitor->getPriority()])) {
+ $this->visitors[$visitor->getPriority()] = array();
+ }
+
+ $this->visitors[$visitor->getPriority()][] = $visitor;
}
/**
return null;
}
- foreach ($this->visitors as $visitor) {
- $node = $visitor->enterNode($node, $this->env);
+ ksort($this->visitors);
+ foreach ($this->visitors as $visitors) {
+ foreach ($visitors as $visitor) {
+ $node = $visitor->enterNode($node, $this->env);
+ }
}
foreach ($node as $k => $n) {
}
}
- foreach ($this->visitors as $visitor) {
- $node = $visitor->leaveNode($node, $this->env);
+ foreach ($this->visitors as $visitors) {
+ foreach ($visitors as $visitor) {
+ $node = $visitor->leaveNode($node, $this->env);
+ }
}
return $node;
$args = new Twig_Node(array(new Twig_Node_Expression_Constant((string) $type, $line)));
return new Twig_Node_Expression_Filter($node, $name, $args, $line);
}
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getPriority()
+ {
+ return 0;
+ }
}
* @param Twig_NodeInterface The modified node
*/
public function leaveNode(Twig_NodeInterface $node, Twig_Environment $env);
+
+ /**
+ * Returns the priority.
+ *
+ * @return $priority The priority
+ */
+ public function getPriority();
}