From 4c4657a76447df74948ffc40e264766f9b5cf20c Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 19 Sep 2016 11:04:18 -0700 Subject: [PATCH] changed the way we store node filenames --- lib/Twig/Compiler.php | 14 +------------- lib/Twig/Node.php | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/lib/Twig/Compiler.php b/lib/Twig/Compiler.php index bc4d5da06d..b79de126fe 100644 --- a/lib/Twig/Compiler.php +++ b/lib/Twig/Compiler.php @@ -85,7 +85,7 @@ public function compile(Twig_NodeInterface $node, $indentation = 0) $this->indentation = $indentation; if ($node instanceof Twig_Node_Module) { - $this->addFilenameAttribute($node, $node->getAttribute('filename')); + $node->setFilename($node->getAttribute('filename')); // to be removed in 2.0 $this->filename = $node->getAttribute('filename'); @@ -282,16 +282,4 @@ public function getVarName() { return sprintf('__internal_%s', hash('sha256', uniqid(mt_rand(), true), false)); } - - private function addFilenameAttribute(Twig_Node $node, $filename) - { - $node->setAttribute('module_filename', $filename); - foreach ($node as $n) { - if (null !== $n) { - $this->addFilenameAttribute($n, $filename); - } - } - - return $node; - } } diff --git a/lib/Twig/Node.php b/lib/Twig/Node.php index 80aed3220d..7688a59fe4 100644 --- a/lib/Twig/Node.php +++ b/lib/Twig/Node.php @@ -22,6 +22,8 @@ class Twig_Node implements Twig_NodeInterface protected $lineno; protected $tag; + private $filename; + /** * Constructor. * @@ -229,10 +231,18 @@ public function getIterator() return new ArrayIterator($this->nodes); } - public function getFilename() + public function setFilename($filename) { - if ($this->hasAttribute('module_filename')) { - return $this->getAttribute('module_filename'); + $this->filename = $filename; + foreach ($this->nodes as $node) { + if (null !== $node) { + $node->setFilename($filename); + } } } + + public function getFilename() + { + return $this->filename; + } }