deprecated Twig_Compiler::getFilename()

This commit is contained in:
Fabien Potencier
2016-09-18 18:35:13 -07:00
parent c418d07c64
commit 1f41e9f9e1
7 changed files with 35 additions and 8 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
* 1.24.3 (2016-XX-XX)
* 1.25.0 (2016-XX-XX)
* n/a
* deprecated Twig_Compiler::getFilename()
* 1.24.2 (2016-09-01)
+20
View File
@@ -36,8 +36,13 @@ class Twig_Compiler implements Twig_CompilerInterface
$this->env = $env;
}
/**
* @deprecated since 1.25 (to be removed in 2.0)
*/
public function getFilename()
{
@trigger_error(sprintf('The %s() method is deprecated since version 1.25 and will be removed in 2.0.', __FUNCTION__), E_USER_DEPRECATED);
return $this->filename;
}
@@ -80,6 +85,9 @@ class Twig_Compiler implements Twig_CompilerInterface
$this->indentation = $indentation;
if ($node instanceof Twig_Node_Module) {
$this->addFilenameAttribute($node, $node->getAttribute('filename'));
// to be removed in 2.0
$this->filename = $node->getAttribute('filename');
}
@@ -274,4 +282,16 @@ 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;
}
}
+7
View File
@@ -228,4 +228,11 @@ class Twig_Node implements Twig_NodeInterface
{
return new ArrayIterator($this->nodes);
}
public function getFilename()
{
if ($this->hasAttribute('module_filename')) {
return $this->getAttribute('module_filename');
}
}
}
+1 -1
View File
@@ -31,7 +31,7 @@ class Twig_Node_Embed extends Twig_Node_Include
->write('$this->loadTemplate(')
->string($this->getAttribute('filename'))
->raw(', ')
->repr($compiler->getFilename())
->repr($this->getFilename())
->raw(', ')
->repr($this->getLine())
->raw(', ')
+1 -1
View File
@@ -37,7 +37,7 @@ class Twig_Node_Import extends Twig_Node
->raw('$this->loadTemplate(')
->subcompile($this->getNode('expr'))
->raw(', ')
->repr($compiler->getFilename())
->repr($this->getFilename())
->raw(', ')
->repr($this->getLine())
->raw(')')
+1 -1
View File
@@ -59,7 +59,7 @@ class Twig_Node_Include extends Twig_Node implements Twig_NodeOutputInterface
->write('$this->loadTemplate(')
->subcompile($this->getNode('expr'))
->raw(', ')
->repr($compiler->getFilename())
->repr($this->getFilename())
->raw(', ')
->repr($this->getLine())
->raw(')')
+3 -3
View File
@@ -112,7 +112,7 @@ class Twig_Node_Module extends Twig_Node
->raw('$this->loadTemplate(')
->subcompile($parent)
->raw(', ')
->repr($compiler->getFilename())
->repr($this->getAttribute('filename'))
->raw(', ')
->repr($this->getNode('parent')->getLine())
->raw(')')
@@ -157,7 +157,7 @@ class Twig_Node_Module extends Twig_Node
->write('$this->parent = $this->loadTemplate(')
->subcompile($parent)
->raw(', ')
->repr($compiler->getFilename())
->repr($this->getAttribute('filename'))
->raw(', ')
->repr($this->getNode('parent')->getLine())
->raw(");\n")
@@ -391,7 +391,7 @@ class Twig_Node_Module extends Twig_Node
->write(sprintf('%s = $this->loadTemplate(', $var))
->subcompile($node)
->raw(', ')
->repr($compiler->getFilename())
->repr($this->getAttribute('filename'))
->raw(', ')
->repr($node->getLine())
->raw(");\n")