PluginProbe
Elementor Website Builder – more than just a page builder / 3.28.0-dev1
Elementor Website Builder – more than just a page builder v3.28.0-dev1
4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 All 452 releases
elementor / vendor_prefixed / twig / src / NodeTraverser.php

NodeTraverser.php in Elementor Website Builder – more than just a page builder 3.28.0-dev1, at vendor_prefixed/twig/src/NodeTraverser.php

68 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 namespace ElementorDeps\Twig;
12
13 use ElementorDeps\Twig\Node\Node;
14 use ElementorDeps\Twig\NodeVisitor\NodeVisitorInterface;
15 /**
16 * A node traverser.
17 *
18 * It visits all nodes and their children and calls the given visitor for each.
19 *
20 * @author Fabien Potencier <fabien@symfony.com>
21 */
22 final class NodeTraverser
23 {
24 private $env;
25 private $visitors = [];
26 /**
27 * @param NodeVisitorInterface[] $visitors
28 */
29 public function __construct(Environment $env, array $visitors = [])
30 {
31 $this->env = $env;
32 foreach ($visitors as $visitor) {
33 $this->addVisitor($visitor);
34 }
35 }
36 public function addVisitor(NodeVisitorInterface $visitor) : void
37 {
38 $this->visitors[$visitor->getPriority()][] = $visitor;
39 }
40 /**
41 * Traverses a node and calls the registered visitors.
42 */
43 public function traverse(Node $node) : Node
44 {
45 \ksort($this->visitors);
46 foreach ($this->visitors as $visitors) {
47 foreach ($visitors as $visitor) {
48 $node = $this->traverseForVisitor($visitor, $node);
49 }
50 }
51 return $node;
52 }
53 private function traverseForVisitor(NodeVisitorInterface $visitor, Node $node) : ?Node
54 {
55 $node = $visitor->enterNode($node, $this->env);
56 foreach ($node as $k => $n) {
57 if (null !== ($m = $this->traverseForVisitor($visitor, $n))) {
58 if ($m !== $n) {
59 $node->setNode($k, $m);
60 }
61 } else {
62 $node->removeNode($k);
63 }
64 }
65 return $visitor->leaveNode($node, $this->env);
66 }
67 }
68