mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-12 18:36:53 +00:00
deprecated Twig_Node::getFilename() in favor of Twig_Node::getName()
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
* 1.27.0 (2016-XX-XX)
|
||||
|
||||
* deprecated Twig_Node::getFilename() in favor of Twig_Node::getName()
|
||||
* deprecated the "filename" escaping strategy (use "name" instead)
|
||||
* 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()
|
||||
|
||||
+4
-1
@@ -120,7 +120,10 @@ Nodes
|
||||
Twig 2.x.
|
||||
|
||||
* As of Twig 1.27, the ``filename`` attribute on ``Twig_Node_Module`` is
|
||||
deprecated. Use ``name`` instead.
|
||||
deprecated. Use ``getName()`` instead.
|
||||
|
||||
* As of Twig 1.27, the ``getFilename()`` method is deprecated, use
|
||||
``getName()`` instead.
|
||||
|
||||
Interfaces
|
||||
----------
|
||||
|
||||
@@ -85,10 +85,8 @@ class Twig_Compiler implements Twig_CompilerInterface
|
||||
$this->indentation = $indentation;
|
||||
|
||||
if ($node instanceof Twig_Node_Module) {
|
||||
$node->setFilename($node->getAttribute('name'));
|
||||
|
||||
// to be removed in 2.0
|
||||
$this->filename = $node->getAttribute('name');
|
||||
$this->filename = $node->getName();
|
||||
}
|
||||
|
||||
$node->compile($this);
|
||||
|
||||
+25
-5
@@ -22,7 +22,7 @@ class Twig_Node implements Twig_NodeInterface
|
||||
protected $lineno;
|
||||
protected $tag;
|
||||
|
||||
private $filename;
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@@ -240,18 +240,38 @@ class Twig_Node implements Twig_NodeInterface
|
||||
return new ArrayIterator($this->nodes);
|
||||
}
|
||||
|
||||
public function setFilename($filename)
|
||||
public function setName($name)
|
||||
{
|
||||
$this->filename = $filename;
|
||||
$this->name = $name;
|
||||
foreach ($this->nodes as $node) {
|
||||
if (null !== $node) {
|
||||
$node->setFilename($filename);
|
||||
$node->setName($name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since 1.27 (to be removed in 2.0)
|
||||
*/
|
||||
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);
|
||||
|
||||
$this->setName($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since 1.27 (to be removed in 2.0)
|
||||
*/
|
||||
public function getFilename()
|
||||
{
|
||||
return $this->filename;
|
||||
@trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use getName() instead.', E_USER_DEPRECATED);
|
||||
|
||||
return $this->name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ class Twig_Node_Embed extends Twig_Node_Include
|
||||
->write('$this->loadTemplate(')
|
||||
->string($this->getAttribute('name'))
|
||||
->raw(', ')
|
||||
->repr($this->getFilename())
|
||||
->repr($this->getName())
|
||||
->raw(', ')
|
||||
->repr($this->getLine())
|
||||
->raw(', ')
|
||||
|
||||
@@ -37,7 +37,7 @@ class Twig_Node_Import extends Twig_Node
|
||||
->raw('$this->loadTemplate(')
|
||||
->subcompile($this->getNode('expr'))
|
||||
->raw(', ')
|
||||
->repr($this->getFilename())
|
||||
->repr($this->getName())
|
||||
->raw(', ')
|
||||
->repr($this->getLine())
|
||||
->raw(')')
|
||||
|
||||
@@ -64,7 +64,7 @@ class Twig_Node_Include extends Twig_Node implements Twig_NodeOutputInterface
|
||||
->write('$this->loadTemplate(')
|
||||
->subcompile($this->getNode('expr'))
|
||||
->raw(', ')
|
||||
->repr($this->getFilename())
|
||||
->repr($this->getName())
|
||||
->raw(', ')
|
||||
->repr($this->getLine())
|
||||
->raw(')')
|
||||
|
||||
+21
-17
@@ -21,13 +21,15 @@
|
||||
*/
|
||||
class Twig_Node_Module extends Twig_Node
|
||||
{
|
||||
private $source;
|
||||
|
||||
public function __construct(Twig_NodeInterface $body, Twig_Node_Expression $parent = null, Twig_NodeInterface $blocks, Twig_NodeInterface $macros, Twig_NodeInterface $traits, $embeddedTemplates, $name, $source = '')
|
||||
{
|
||||
if (!$name instanceof Twig_Source) {
|
||||
@trigger_error(sprintf('Passing a string as the $name argument of %s() is deprecated since version 1.27. Pass a Twig_Source instance instead.', __METHOD__), E_USER_DEPRECATED);
|
||||
$source = new Twig_Source($source, $name);
|
||||
$this->source = new Twig_Source($source, $name);
|
||||
} else {
|
||||
$source = $name;
|
||||
$this->source = $name;
|
||||
}
|
||||
|
||||
$nodes = array(
|
||||
@@ -47,14 +49,16 @@ class Twig_Node_Module extends Twig_Node
|
||||
|
||||
// embedded templates are set as attributes so that they are only visited once by the visitors
|
||||
parent::__construct($nodes, array(
|
||||
'source' => $source->getCode(),
|
||||
'name' => $source->getName(),
|
||||
// filename to be remove in 2.0 (use name instead)
|
||||
'filename' => $source->getName(),
|
||||
'path' => $source->getPath(),
|
||||
// source to be remove in 2.0
|
||||
'source' => $this->source->getCode(),
|
||||
// filename to be remove in 2.0 (use getName() instead)
|
||||
'filename' => $this->source->getName(),
|
||||
'index' => null,
|
||||
'embedded_templates' => $embeddedTemplates,
|
||||
), 1);
|
||||
|
||||
// populate the template name of all node children
|
||||
$this->setName($this->source->getName());
|
||||
}
|
||||
|
||||
public function setIndex($index)
|
||||
@@ -132,7 +136,7 @@ class Twig_Node_Module extends Twig_Node
|
||||
->raw('$this->loadTemplate(')
|
||||
->subcompile($parent)
|
||||
->raw(', ')
|
||||
->repr($this->getAttribute('name'))
|
||||
->repr($this->source->getName())
|
||||
->raw(', ')
|
||||
->repr($parent->getLine())
|
||||
->raw(')')
|
||||
@@ -151,8 +155,8 @@ class Twig_Node_Module extends Twig_Node
|
||||
$compiler
|
||||
->write("\n\n")
|
||||
// if the filename contains */, add a blank to avoid a PHP parse error
|
||||
->write('/* '.str_replace('*/', '* /', $this->getAttribute('name'))." */\n")
|
||||
->write('class '.$compiler->getEnvironment()->getTemplateClass($this->getAttribute('name'), $this->getAttribute('index')))
|
||||
->write('/* '.str_replace('*/', '* /', $this->source->getName())." */\n")
|
||||
->write('class '.$compiler->getEnvironment()->getTemplateClass($this->source->getName(), $this->getAttribute('index')))
|
||||
->raw(sprintf(" extends %s\n", $compiler->getEnvironment()->getBaseTemplateClass()))
|
||||
->write("{\n")
|
||||
->indent()
|
||||
@@ -177,7 +181,7 @@ class Twig_Node_Module extends Twig_Node
|
||||
->write('$this->parent = $this->loadTemplate(')
|
||||
->subcompile($parent)
|
||||
->raw(', ')
|
||||
->repr($this->getAttribute('name'))
|
||||
->repr($this->source->getName())
|
||||
->raw(', ')
|
||||
->repr($parent->getLine())
|
||||
->raw(");\n")
|
||||
@@ -335,7 +339,7 @@ class Twig_Node_Module extends Twig_Node
|
||||
->write("public function getTemplateName()\n", "{\n")
|
||||
->indent()
|
||||
->write('return ')
|
||||
->repr($this->getAttribute('name'))
|
||||
->repr($this->source->getName())
|
||||
->raw(";\n")
|
||||
->outdent()
|
||||
->write("}\n\n")
|
||||
@@ -411,7 +415,7 @@ class Twig_Node_Module extends Twig_Node
|
||||
->write("public function getSource()\n", "{\n")
|
||||
->indent()
|
||||
->write('return ')
|
||||
->string($compiler->getEnvironment()->isDebug() ? $this->getAttribute('source') : '')
|
||||
->string($compiler->getEnvironment()->isDebug() ? $this->source->getCode() : '')
|
||||
->raw(";\n")
|
||||
->outdent()
|
||||
->write("}\n\n")
|
||||
@@ -424,11 +428,11 @@ class Twig_Node_Module extends Twig_Node
|
||||
->write("public function getSourceContext()\n", "{\n")
|
||||
->indent()
|
||||
->write('return new Twig_Source(')
|
||||
->string($compiler->getEnvironment()->isDebug() ? $this->getAttribute('source') : '')
|
||||
->string($compiler->getEnvironment()->isDebug() ? $this->source->getCode() : '')
|
||||
->raw(', ')
|
||||
->string($this->getAttribute('name'))
|
||||
->string($this->source->getName())
|
||||
->raw(', ')
|
||||
->string($this->getAttribute('path'))
|
||||
->string($this->source->getPath())
|
||||
->raw(");\n")
|
||||
->outdent()
|
||||
->write("}\n")
|
||||
@@ -442,7 +446,7 @@ class Twig_Node_Module extends Twig_Node
|
||||
->write(sprintf('%s = $this->loadTemplate(', $var))
|
||||
->subcompile($node)
|
||||
->raw(', ')
|
||||
->repr($this->getAttribute('name'))
|
||||
->repr($node->getName())
|
||||
->raw(', ')
|
||||
->repr($node->getLine())
|
||||
->raw(");\n")
|
||||
|
||||
@@ -34,7 +34,7 @@ class Twig_NodeVisitor_Escaper extends Twig_BaseNodeVisitor
|
||||
protected function doEnterNode(Twig_Node $node, Twig_Environment $env)
|
||||
{
|
||||
if ($node instanceof Twig_Node_Module) {
|
||||
if ($env->hasExtension('Twig_Extension_Escaper') && $defaultStrategy = $env->getExtension('Twig_Extension_Escaper')->getDefaultStrategy($node->getAttribute('name'))) {
|
||||
if ($env->hasExtension('Twig_Extension_Escaper') && $defaultStrategy = $env->getExtension('Twig_Extension_Escaper')->getDefaultStrategy($node->getName())) {
|
||||
$this->defaultStrategy = $defaultStrategy;
|
||||
}
|
||||
$this->safeVars = array();
|
||||
|
||||
@@ -48,7 +48,7 @@ class Twig_TokenParser_Embed extends Twig_TokenParser_Include
|
||||
|
||||
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
||||
|
||||
return new Twig_Node_Embed($module->getAttribute('name'), $module->getAttribute('index'), $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag());
|
||||
return new Twig_Node_Embed($module->getName(), $module->getAttribute('index'), $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag());
|
||||
}
|
||||
|
||||
public function decideBlockEnd(Twig_Token $token)
|
||||
|
||||
@@ -47,7 +47,7 @@ class Twig_Tests_ExpressionParserTest extends PHPUnit_Framework_TestCase
|
||||
public function testArrayExpression($template, $expected)
|
||||
{
|
||||
$env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false));
|
||||
$stream = $env->tokenize(new Twig_Source($template, 'index'));
|
||||
$stream = $env->tokenize(new Twig_Source($template));
|
||||
$parser = new Twig_Parser($env);
|
||||
|
||||
$this->assertEquals($expected, $parser->parse($stream)->getNode('body')->getNode(0)->getNode('expr'));
|
||||
@@ -167,7 +167,7 @@ class Twig_Tests_ExpressionParserTest extends PHPUnit_Framework_TestCase
|
||||
public function testStringExpression($template, $expected)
|
||||
{
|
||||
$env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false, 'optimizations' => 0));
|
||||
$stream = $env->tokenize(new Twig_Source($template, 'index'));
|
||||
$stream = $env->tokenize(new Twig_Source($template));
|
||||
$parser = new Twig_Parser($env);
|
||||
|
||||
$this->assertEquals($expected, $parser->parse($stream)->getNode('body')->getNode(0)->getNode('expr'));
|
||||
|
||||
@@ -25,7 +25,7 @@ class Twig_Tests_Node_ModuleTest extends Twig_Test_NodeTestCase
|
||||
$this->assertEquals($blocks, $node->getNode('blocks'));
|
||||
$this->assertEquals($macros, $node->getNode('macros'));
|
||||
$this->assertEquals($parent, $node->getNode('parent'));
|
||||
$this->assertEquals($source->getName(), $node->getAttribute('name'));
|
||||
$this->assertEquals($source->getName(), $node->getName());
|
||||
}
|
||||
|
||||
public function getTests()
|
||||
|
||||
Reference in New Issue
Block a user