renamed Twig_Node::getName() to Twig_Node::getTemplateName()

This commit is contained in:
Fabien Potencier
2016-10-19 14:40:55 -07:00
parent 63c2d08ddb
commit e231aa539f
12 changed files with 38 additions and 20 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
* 1.27.0 (2016-XX-XX) * 1.27.0 (2016-XX-XX)
* deprecated Twig_Template::getSource() in favor of Twig_Template::getSourceContext() * deprecated Twig_Template::getSource() in favor of Twig_Template::getSourceContext()
* deprecated Twig_Node::getFilename() in favor of Twig_Node::getName() * deprecated Twig_Node::getFilename() in favor of Twig_Node::getTemplateName()
* deprecated the "filename" escaping strategy (use "name" instead) * deprecated the "filename" escaping strategy (use "name" instead)
* added Twig_Source to hold information about the original template * added Twig_Source to hold information about the original template
* deprecated Twig_Error::getTemplateFile() and Twig_Error::setTemplateFile() in favor of Twig_Error::getTemplateName() and Twig_Error::setTemplateName() * deprecated Twig_Error::getTemplateFile() and Twig_Error::setTemplateFile() in favor of Twig_Error::getTemplateName() and Twig_Error::setTemplateName()
+2 -2
View File
@@ -122,8 +122,8 @@ Nodes
* As of Twig 1.27, the ``filename`` attribute on ``Twig_Node_Module`` is * As of Twig 1.27, the ``filename`` attribute on ``Twig_Node_Module`` is
deprecated. Use ``getName()`` instead. deprecated. Use ``getName()`` instead.
* As of Twig 1.27, the ``getFilename()`` method is deprecated, use * As of Twig 1.27, the ``Twig_Node::getFilename()`` method is deprecated, use
``getName()`` instead. ``Twig_Node::getName()`` instead.
Interfaces Interfaces
---------- ----------
+1 -1
View File
@@ -86,7 +86,7 @@ class Twig_Compiler implements Twig_CompilerInterface
if ($node instanceof Twig_Node_Module) { if ($node instanceof Twig_Node_Module) {
// to be removed in 2.0 // to be removed in 2.0
$this->filename = $node->getName(); $this->filename = $node->getTemplateName();
} }
$node->compile($this); $node->compile($this);
+6 -6
View File
@@ -240,17 +240,17 @@ class Twig_Node implements Twig_NodeInterface
return new ArrayIterator($this->nodes); return new ArrayIterator($this->nodes);
} }
public function setName($name) public function setTemplateName($name)
{ {
$this->name = $name; $this->name = $name;
foreach ($this->nodes as $node) { foreach ($this->nodes as $node) {
if (null !== $node) { if (null !== $node) {
$node->setName($name); $node->setTemplateName($name);
} }
} }
} }
public function getName() public function getTemplateName()
{ {
return $this->name; return $this->name;
} }
@@ -260,9 +260,9 @@ class Twig_Node implements Twig_NodeInterface
*/ */
public function setFilename($name) public function setFilename($name)
{ {
@trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use setName() instead.', E_USER_DEPRECATED); @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use setTemplateName() instead.', E_USER_DEPRECATED);
$this->setName($name); $this->setTemplateName($name);
} }
/** /**
@@ -270,7 +270,7 @@ class Twig_Node implements Twig_NodeInterface
*/ */
public function getFilename() public function getFilename()
{ {
@trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use getName() instead.', E_USER_DEPRECATED); @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use getTemplateName() instead.', E_USER_DEPRECATED);
return $this->name; return $this->name;
} }
+1 -1
View File
@@ -33,7 +33,7 @@ class Twig_Node_Embed extends Twig_Node_Include
->write('$this->loadTemplate(') ->write('$this->loadTemplate(')
->string($this->getAttribute('name')) ->string($this->getAttribute('name'))
->raw(', ') ->raw(', ')
->repr($this->getName()) ->repr($this->getTemplateName())
->raw(', ') ->raw(', ')
->repr($this->getLine()) ->repr($this->getLine())
->raw(', ') ->raw(', ')
+1 -1
View File
@@ -37,7 +37,7 @@ class Twig_Node_Import extends Twig_Node
->raw('$this->loadTemplate(') ->raw('$this->loadTemplate(')
->subcompile($this->getNode('expr')) ->subcompile($this->getNode('expr'))
->raw(', ') ->raw(', ')
->repr($this->getName()) ->repr($this->getTemplateName())
->raw(', ') ->raw(', ')
->repr($this->getLine()) ->repr($this->getLine())
->raw(')') ->raw(')')
+1 -1
View File
@@ -64,7 +64,7 @@ class Twig_Node_Include extends Twig_Node implements Twig_NodeOutputInterface
->write('$this->loadTemplate(') ->write('$this->loadTemplate(')
->subcompile($this->getNode('expr')) ->subcompile($this->getNode('expr'))
->raw(', ') ->raw(', ')
->repr($this->getName()) ->repr($this->getTemplateName())
->raw(', ') ->raw(', ')
->repr($this->getLine()) ->repr($this->getLine())
->raw(')') ->raw(')')
+4 -4
View File
@@ -51,14 +51,14 @@ class Twig_Node_Module extends Twig_Node
parent::__construct($nodes, array( parent::__construct($nodes, array(
// source to be remove in 2.0 // source to be remove in 2.0
'source' => $this->source->getCode(), 'source' => $this->source->getCode(),
// filename to be remove in 2.0 (use getName() instead) // filename to be remove in 2.0 (use getTemplateName() instead)
'filename' => $this->source->getName(), 'filename' => $this->source->getName(),
'index' => null, 'index' => null,
'embedded_templates' => $embeddedTemplates, 'embedded_templates' => $embeddedTemplates,
), 1); ), 1);
// populate the template name of all node children // populate the template name of all node children
$this->setName($this->source->getName()); $this->setTemplateName($this->source->getName());
} }
public function setIndex($index) public function setIndex($index)
@@ -154,7 +154,7 @@ class Twig_Node_Module extends Twig_Node
{ {
$compiler $compiler
->write("\n\n") ->write("\n\n")
// if the filename contains */, add a blank to avoid a PHP parse error // if the template name contains */, add a blank to avoid a PHP parse error
->write('/* '.str_replace('*/', '* /', $this->source->getName())." */\n") ->write('/* '.str_replace('*/', '* /', $this->source->getName())." */\n")
->write('class '.$compiler->getEnvironment()->getTemplateClass($this->source->getName(), $this->getAttribute('index'))) ->write('class '.$compiler->getEnvironment()->getTemplateClass($this->source->getName(), $this->getAttribute('index')))
->raw(sprintf(" extends %s\n", $compiler->getEnvironment()->getBaseTemplateClass())) ->raw(sprintf(" extends %s\n", $compiler->getEnvironment()->getBaseTemplateClass()))
@@ -447,7 +447,7 @@ class Twig_Node_Module extends Twig_Node
->write(sprintf('%s = $this->loadTemplate(', $var)) ->write(sprintf('%s = $this->loadTemplate(', $var))
->subcompile($node) ->subcompile($node)
->raw(', ') ->raw(', ')
->repr($node->getName()) ->repr($node->getTemplateName())
->raw(', ') ->raw(', ')
->repr($node->getLine()) ->repr($node->getLine())
->raw(");\n") ->raw(");\n")
+1 -1
View File
@@ -34,7 +34,7 @@ class Twig_NodeVisitor_Escaper extends Twig_BaseNodeVisitor
protected function doEnterNode(Twig_Node $node, Twig_Environment $env) protected function doEnterNode(Twig_Node $node, Twig_Environment $env)
{ {
if ($node instanceof Twig_Node_Module) { if ($node instanceof Twig_Node_Module) {
if ($env->hasExtension('Twig_Extension_Escaper') && $defaultStrategy = $env->getExtension('Twig_Extension_Escaper')->getDefaultStrategy($node->getName())) { if ($env->hasExtension('Twig_Extension_Escaper') && $defaultStrategy = $env->getExtension('Twig_Extension_Escaper')->getDefaultStrategy($node->getTemplateName())) {
$this->defaultStrategy = $defaultStrategy; $this->defaultStrategy = $defaultStrategy;
} }
$this->safeVars = array(); $this->safeVars = array();
+1 -1
View File
@@ -48,7 +48,7 @@ class Twig_TokenParser_Embed extends Twig_TokenParser_Include
$stream->expect(Twig_Token::BLOCK_END_TYPE); $stream->expect(Twig_Token::BLOCK_END_TYPE);
return new Twig_Node_Embed($module->getName(), $module->getAttribute('index'), $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag()); return new Twig_Node_Embed($module->getTemplateName(), $module->getAttribute('index'), $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag());
} }
public function decideBlockEnd(Twig_Token $token) public function decideBlockEnd(Twig_Token $token)
@@ -0,0 +1,18 @@
--TEST--
"filename" autoescape strategy
--TEMPLATE--
{{ br -}}
{{ include('index.html.twig') -}}
{{ include('index.txt.twig') -}}
--TEMPLATE(index.html.twig)--
{{ br -}}
--TEMPLATE(index.txt.twig)--
{{ br -}}
--DATA--
return array('br' => '<br />')
--CONFIG--
return array('autoescape' => 'filename')
--EXPECT--
&lt;br /&gt;
&lt;br /&gt;
<br />
+1 -1
View File
@@ -25,7 +25,7 @@ class Twig_Tests_Node_ModuleTest extends Twig_Test_NodeTestCase
$this->assertEquals($blocks, $node->getNode('blocks')); $this->assertEquals($blocks, $node->getNode('blocks'));
$this->assertEquals($macros, $node->getNode('macros')); $this->assertEquals($macros, $node->getNode('macros'));
$this->assertEquals($parent, $node->getNode('parent')); $this->assertEquals($parent, $node->getNode('parent'));
$this->assertEquals($source->getName(), $node->getName()); $this->assertEquals($source->getName(), $node->getTemplateName());
} }
public function getTests() public function getTests()