Yaffs site version 1.1
[yaffs-website] / vendor / twig / twig / lib / Twig / BaseNodeVisitor.php
1 <?php
2
3 /*
4  * This file is part of Twig.
5  *
6  * (c) 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
12 /**
13  * Twig_BaseNodeVisitor can be used to make node visitors compatible with Twig 1.x and 2.x.
14  *
15  * @author Fabien Potencier <fabien@symfony.com>
16  */
17 abstract class Twig_BaseNodeVisitor implements Twig_NodeVisitorInterface
18 {
19     final public function enterNode(Twig_NodeInterface $node, Twig_Environment $env)
20     {
21         if (!$node instanceof Twig_Node) {
22             throw new LogicException('Twig_BaseNodeVisitor only supports Twig_Node instances.');
23         }
24
25         return $this->doEnterNode($node, $env);
26     }
27
28     final public function leaveNode(Twig_NodeInterface $node, Twig_Environment $env)
29     {
30         if (!$node instanceof Twig_Node) {
31             throw new LogicException('Twig_BaseNodeVisitor only supports Twig_Node instances.');
32         }
33
34         return $this->doLeaveNode($node, $env);
35     }
36
37     /**
38      * Called before child nodes are visited.
39      *
40      * @return Twig_Node The modified node
41      */
42     abstract protected function doEnterNode(Twig_Node $node, Twig_Environment $env);
43
44     /**
45      * Called after child nodes are visited.
46      *
47      * @return Twig_Node|false The modified node or false if the node must be removed
48      */
49     abstract protected function doLeaveNode(Twig_Node $node, Twig_Environment $env);
50 }
51
52 class_alias('Twig_BaseNodeVisitor', 'Twig\NodeVisitor\AbstractNodeVisitor', false);
53 class_exists('Twig_Environment');
54 class_exists('Twig_Node');