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 12namespace Twig\NodeVisitor; 13 14use Twig\Environment; 15use Twig\Node\Node; 16 17/** 18 * Used to make node visitors compatible with Twig 1.x and 2.x. 19 * 20 * @author Fabien Potencier <fabien@symfony.com> 21 */ 22abstract class AbstractNodeVisitor implements NodeVisitorInterface 23{ 24 final public function enterNode(\Twig_NodeInterface $node, Environment $env) 25 { 26 if (!$node instanceof Node) { 27 throw new \LogicException(sprintf('%s only supports \Twig\Node\Node instances.', __CLASS__)); 28 } 29 30 return $this->doEnterNode($node, $env); 31 } 32 33 final public function leaveNode(\Twig_NodeInterface $node, Environment $env) 34 { 35 if (!$node instanceof Node) { 36 throw new \LogicException(sprintf('%s only supports \Twig\Node\Node instances.', __CLASS__)); 37 } 38 39 return $this->doLeaveNode($node, $env); 40 } 41 42 /** 43 * Called before child nodes are visited. 44 * 45 * @return Node The modified node 46 */ 47 abstract protected function doEnterNode(Node $node, Environment $env); 48 49 /** 50 * Called after child nodes are visited. 51 * 52 * @return Node|false The modified node or false if the node must be removed 53 */ 54 abstract protected function doLeaveNode(Node $node, Environment $env); 55} 56 57class_alias('Twig\NodeVisitor\AbstractNodeVisitor', 'Twig_BaseNodeVisitor'); 58