diff --git a/src/Node/CheckSecurityNode.php b/src/Node/CheckSecurityNode.php index 3525c9f95..6e591aad4 100644 --- a/src/Node/CheckSecurityNode.php +++ b/src/Node/CheckSecurityNode.php @@ -24,11 +24,16 @@ class CheckSecurityNode extends Node private $usedTags; private $usedFunctions; + /** + * @param array $usedFilters + * @param array $usedTags + * @param array $usedFunctions + */ public function __construct(array $usedFilters, array $usedTags, array $usedFunctions) { - $this->usedFilters = $this->collect($usedFilters); - $this->usedTags = $this->collect($usedTags); - $this->usedFunctions = $this->collect($usedFunctions); + $this->usedFilters = $usedFilters; + $this->usedTags = $usedTags; + $this->usedFunctions = $usedFunctions; parent::__construct(); } @@ -77,14 +82,4 @@ class CheckSecurityNode extends Node ->write("}\n") ; } - - private function collect(array $used) - { - $collected = []; - foreach ($used as $name => $node) { - $collected[$name] = $node instanceof Node ? $node->getTemplateLine() : null; - } - - return $collected; - } } diff --git a/src/NodeVisitor/SandboxNodeVisitor.php b/src/NodeVisitor/SandboxNodeVisitor.php index 1446cee6b..d1108394f 100644 --- a/src/NodeVisitor/SandboxNodeVisitor.php +++ b/src/NodeVisitor/SandboxNodeVisitor.php @@ -34,8 +34,11 @@ use Twig\Node\SetNode; final class SandboxNodeVisitor implements NodeVisitorInterface { private $inAModule = false; + /** @var array */ private $tags; + /** @var array */ private $filters; + /** @var array */ private $functions; private $needsToStringWrap = false; @@ -51,22 +54,22 @@ final class SandboxNodeVisitor implements NodeVisitorInterface } elseif ($this->inAModule) { // look for tags if ($node->getNodeTag() && !isset($this->tags[$node->getNodeTag()])) { - $this->tags[$node->getNodeTag()] = $node; + $this->tags[$node->getNodeTag()] = $node->getTemplateLine(); } // look for filters if ($node instanceof FilterExpression && !isset($this->filters[$node->getNode('filter')->getAttribute('value')])) { - $this->filters[$node->getNode('filter')->getAttribute('value')] = $node; + $this->filters[$node->getNode('filter')->getAttribute('value')] = $node->getTemplateLine(); } // look for functions if ($node instanceof FunctionExpression && !isset($this->functions[$node->getAttribute('name')])) { - $this->functions[$node->getAttribute('name')] = $node; + $this->functions[$node->getAttribute('name')] = $node->getTemplateLine(); } // the .. operator is equivalent to the range() function if ($node instanceof RangeBinary && !isset($this->functions['range'])) { - $this->functions['range'] = $node; + $this->functions['range'] = $node->getTemplateLine(); } if ($node instanceof PrintNode) {