<?php /* * This file is part of Twig. * * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Twig; use Twig\Node\Node; use Twig\NodeVisitor\NodeVisitorInterface; /** * A node traverser. * * It visits all nodes and their children and calls the given visitor for each. * * @author Fabien Potencier <fabien@symfony.com> */ final class NodeTraverser { private $env; private $visitors = []; /** * @param NodeVisitorInterface[] $visitors */ public function __construct(Environment $env, array $visitors = []) { $this->env = $env; foreach ($visitors as $visitor) { $this->addVisitor($visitor); } } public function addVisitor(NodeVisitorInterface $visitor) { $this->visitors[$visitor->getPriority()][] = $visitor; } /** * Traverses a node and calls the registered visitors. * * @return Node */ public function traverse(Node $node) { ksort($this->visitors); foreach ($this->visitors as $visitors) { foreach ($visitors as $visitor) { $node = $this->traverseForVisitor($visitor, $node); } } return $node; } private function traverseForVisitor(NodeVisitorInterface $visitor, Node $node) { $node = $visitor->enterNode($node, $this->env); foreach ($node as $k => $n) { if (false !== $m = $this->traverseForVisitor($visitor, $n)) { if ($m !== $n) { $node->setNode($k, $m); } } else { $node->removeNode($k); } } return $visitor->leaveNode($node, $this->env); } } class_alias('Twig\NodeTraverser', 'Twig_NodeTraverser');
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
Cache | Folder | 0755 |
|
|
Error | Folder | 0755 |
|
|
Extension | Folder | 0755 |
|
|
Loader | Folder | 0755 |
|
|
Node | Folder | 0755 |
|
|
NodeVisitor | Folder | 0755 |
|
|
Profiler | Folder | 0755 |
|
|
RuntimeLoader | Folder | 0755 |
|
|
Sandbox | Folder | 0755 |
|
|
Test | Folder | 0755 |
|
|
TokenParser | Folder | 0755 |
|
|
Util | Folder | 0755 |
|
|
Compiler.php | File | 5.49 KB | 0644 |
|
Environment.php | File | 27.69 KB | 0644 |
|
ExpressionParser.php | File | 28.5 KB | 0644 |
|
ExtensionSet.php | File | 13.37 KB | 0644 |
|
FileExtensionEscapingStrategy.php | File | 1.49 KB | 0644 |
|
Lexer.php | File | 15.33 KB | 0644 |
|
Markup.php | File | 853 B | 0644 |
|
NodeTraverser.php | File | 1.84 KB | 0644 |
|
Parser.php | File | 12.65 KB | 0644 |
|
Source.php | File | 1022 B | 0644 |
|
Template.php | File | 12.22 KB | 0644 |
|
TemplateWrapper.php | File | 3.47 KB | 0644 |
|
Token.php | File | 5.65 KB | 0644 |
|
TokenStream.php | File | 3.62 KB | 0644 |
|
TwigFilter.php | File | 3.54 KB | 0644 |
|
TwigFunction.php | File | 3.3 KB | 0644 |
|
TwigTest.php | File | 2.45 KB | 0644 |
|