Skip to content

Commit

Permalink
bug #2122 changed the way we store node filenames (fabpot)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.x branch.

Discussion
----------

changed the way we store node filenames

Commits
-------

4c4657a changed the way we store node filenames
  • Loading branch information
fabpot committed Sep 19, 2016
2 parents 4735c4f + 4c4657a commit 6e25c3f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
14 changes: 1 addition & 13 deletions lib/Twig/Compiler.php
Expand Up @@ -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');
Expand Down Expand Up @@ -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;
}
}
16 changes: 13 additions & 3 deletions lib/Twig/Node.php
Expand Up @@ -22,6 +22,8 @@ class Twig_Node implements Twig_NodeInterface
protected $lineno;
protected $tag;

private $filename;

/**
* Constructor.
*
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 6e25c3f

Please sign in to comment.