Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame^] | 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 | namespace Twig\NodeVisitor; |
| 13 | |
| 14 | use Twig\Environment; |
| 15 | use Twig\Node\Node; |
| 16 | |
| 17 | /** |
| 18 | * Used to make node visitors compatible with Twig 1.x and 2.x. |
| 19 | * |
| 20 | * To be removed in Twig 3.1. |
| 21 | * |
| 22 | * @author Fabien Potencier <fabien@symfony.com> |
| 23 | */ |
| 24 | abstract class AbstractNodeVisitor implements NodeVisitorInterface |
| 25 | { |
| 26 | final public function enterNode(Node $node, Environment $env): Node |
| 27 | { |
| 28 | return $this->doEnterNode($node, $env); |
| 29 | } |
| 30 | |
| 31 | final public function leaveNode(Node $node, Environment $env): ?Node |
| 32 | { |
| 33 | return $this->doLeaveNode($node, $env); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Called before child nodes are visited. |
| 38 | * |
| 39 | * @return Node The modified node |
| 40 | */ |
| 41 | abstract protected function doEnterNode(Node $node, Environment $env); |
| 42 | |
| 43 | /** |
| 44 | * Called after child nodes are visited. |
| 45 | * |
| 46 | * @return Node|null The modified node or null if the node must be removed |
| 47 | */ |
| 48 | abstract protected function doLeaveNode(Node $node, Environment $env); |
| 49 | } |