changed the way we store node filenames

This commit is contained in:
Fabien Potencier
2016-09-19 11:04:18 -07:00
parent 4735c4fe8f
commit 4c4657a764
2 changed files with 14 additions and 16 deletions
+1 -13
View File
@@ -85,7 +85,7 @@ class Twig_Compiler implements Twig_CompilerInterface
$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 @@ class Twig_Compiler implements Twig_CompilerInterface
{
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;
}
}
+13 -3
View File
@@ -22,6 +22,8 @@ class Twig_Node implements Twig_NodeInterface
protected $lineno;
protected $tag;
private $filename;
/**
* Constructor.
*
@@ -229,10 +231,18 @@ class Twig_Node implements Twig_NodeInterface
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;
}
}