PEEL Shopping
Open source ecommerce : PEEL Shopping
NodeTraverser.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of Twig.
5  *
6  * (c) 2009 Fabien Potencier
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
20 {
21  protected $env;
22  protected $visitors;
23 
30  public function __construct(Twig_Environment $env, array $visitors = array())
31  {
32  $this->env = $env;
33  $this->visitors = array();
34  foreach ($visitors as $visitor) {
35  $this->addVisitor($visitor);
36  }
37  }
38 
44  public function addVisitor(Twig_NodeVisitorInterface $visitor)
45  {
46  if (!isset($this->visitors[$visitor->getPriority()])) {
47  $this->visitors[$visitor->getPriority()] = array();
48  }
49 
50  $this->visitors[$visitor->getPriority()][] = $visitor;
51  }
52 
58  public function traverse(Twig_NodeInterface $node)
59  {
60  ksort($this->visitors);
61  foreach ($this->visitors as $visitors) {
62  foreach ($visitors as $visitor) {
63  $node = $this->traverseForVisitor($visitor, $node);
64  }
65  }
66 
67  return $node;
68  }
69 
70  protected function traverseForVisitor(Twig_NodeVisitorInterface $visitor, Twig_NodeInterface $node = null)
71  {
72  if (null === $node) {
73  return null;
74  }
75 
76  $node = $visitor->enterNode($node, $this->env);
77 
78  foreach ($node as $k => $n) {
79  if (false !== $n = $this->traverseForVisitor($visitor, $n)) {
80  $node->setNode($k, $n);
81  } else {
82  $node->removeNode($k);
83  }
84  }
85 
86  return $visitor->leaveNode($node, $this->env);
87  }
88 }
getPriority()
Returns the priority for this visitor.
Twig_NodeTraverser is a node traverser.
traverse(Twig_NodeInterface $node)
Traverses a node and calls the registered visitors.
addVisitor(Twig_NodeVisitorInterface $visitor)
Adds a visitor.
leaveNode(Twig_NodeInterface $node, Twig_Environment $env)
Called after child nodes are visited.
Twig_NodeVisitorInterface is the interface the all node visitor classes must implement.
Represents a node in the AST.
Stores the Twig configuration.
Definition: Environment.php:17
enterNode(Twig_NodeInterface $node, Twig_Environment $env)
Called before child nodes are visited.
__construct(Twig_Environment $env, array $visitors=array())
Constructor.
traverseForVisitor(Twig_NodeVisitorInterface $visitor, Twig_NodeInterface $node=null)

This documentation for Open ecommerce PEEL Shopping and PEEL.fr has been generated by Doxygen on Thu Oct 15 2015 14:41:19 - Peel ecommerce is a product of Agence web Advisto SAS. All rights reserved.