mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-12 10:26:32 +00:00
renamed Twig_Node::getLine() to Twig_Node::getTemplateLine()
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
* 1.27.0 (2016-XX-XX)
|
||||
|
||||
* deprecated Twig_Node::getLine() in favor of Twig_Node::getTemplateLine()
|
||||
* deprecated Twig_Template::getSource() in favor of Twig_Template::getSourceContext()
|
||||
* deprecated Twig_Node::getFilename() in favor of Twig_Node::getTemplateName()
|
||||
* deprecated the "filename" escaping strategy (use "name" instead)
|
||||
|
||||
+3
-2
@@ -122,8 +122,9 @@ Nodes
|
||||
* As of Twig 1.27, the ``filename`` attribute on ``Twig_Node_Module`` is
|
||||
deprecated. Use ``getName()`` instead.
|
||||
|
||||
* As of Twig 1.27, the ``Twig_Node::getFilename()`` method is deprecated, use
|
||||
``Twig_Node::getName()`` instead.
|
||||
* As of Twig 1.27, the ``Twig_Node::getFilename()/Twig_Node::getLine()``
|
||||
methods are deprecated, use
|
||||
``Twig_Node::getTemplateName()/Twig_Node::getTemplateLine()`` instead.
|
||||
|
||||
Interfaces
|
||||
----------
|
||||
|
||||
@@ -213,8 +213,8 @@ class Twig_Compiler implements Twig_CompilerInterface
|
||||
*/
|
||||
public function addDebugInfo(Twig_NodeInterface $node)
|
||||
{
|
||||
if ($node->getLine() != $this->lastLine) {
|
||||
$this->write(sprintf("// line %d\n", $node->getLine()));
|
||||
if ($node->getTemplateLine() != $this->lastLine) {
|
||||
$this->write(sprintf("// line %d\n", $node->getTemplateLine()));
|
||||
|
||||
// when mbstring.func_overload is set to 2
|
||||
// mb_substr_count() replaces substr_count()
|
||||
@@ -226,9 +226,9 @@ class Twig_Compiler implements Twig_CompilerInterface
|
||||
$this->sourceLine += substr_count($this->source, "\n", $this->sourceOffset);
|
||||
}
|
||||
$this->sourceOffset = strlen($this->source);
|
||||
$this->debugInfo[$this->sourceLine] = $node->getLine();
|
||||
$this->debugInfo[$this->sourceLine] = $node->getTemplateLine();
|
||||
|
||||
$this->lastLine = $node->getLine();
|
||||
$this->lastLine = $node->getTemplateLine();
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
||||
@@ -216,7 +216,7 @@ class Twig_ExpressionParser
|
||||
|
||||
$expr = array_shift($nodes);
|
||||
foreach ($nodes as $node) {
|
||||
$expr = new Twig_Node_Expression_Binary_Concat($expr, $node, $node->getLine());
|
||||
$expr = new Twig_Node_Expression_Binary_Concat($expr, $node, $node->getTemplateLine());
|
||||
}
|
||||
|
||||
return $expr;
|
||||
|
||||
@@ -274,7 +274,7 @@ class Twig_Extension_Core extends Twig_Extension
|
||||
public function parseTestExpression(Twig_Parser $parser, Twig_NodeInterface $node)
|
||||
{
|
||||
$stream = $parser->getStream();
|
||||
list($name, $test) = $this->getTest($parser, $node->getLine());
|
||||
list($name, $test) = $this->getTest($parser, $node->getTemplateLine());
|
||||
|
||||
if ($test instanceof Twig_SimpleTest && $test->isDeprecated()) {
|
||||
$message = sprintf('Twig Test "%s" is deprecated', $name);
|
||||
|
||||
@@ -118,8 +118,18 @@ class Twig_Node implements Twig_NodeInterface
|
||||
}
|
||||
}
|
||||
|
||||
public function getTemplateLine()
|
||||
{
|
||||
return $this->lineno;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since 1.27 (to be removed in 2.0)
|
||||
*/
|
||||
public function getLine()
|
||||
{
|
||||
@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->lineno;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ class Twig_Node_CheckSecurity extends Twig_Node
|
||||
foreach (array('tags', 'filters', 'functions') as $type) {
|
||||
foreach ($this->{'used'.ucfirst($type)} as $name => $node) {
|
||||
if ($node instanceof Twig_Node) {
|
||||
${$type}[$name] = $node->getLine();
|
||||
${$type}[$name] = $node->getTemplateLine();
|
||||
} else {
|
||||
${$type}[$node] = null;
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ class Twig_Node_Embed extends Twig_Node_Include
|
||||
->raw(', ')
|
||||
->repr($this->getTemplateName())
|
||||
->raw(', ')
|
||||
->repr($this->getLine())
|
||||
->repr($this->getTemplateLine())
|
||||
->raw(', ')
|
||||
->string($this->getAttribute('index'))
|
||||
->raw(')')
|
||||
|
||||
@@ -54,7 +54,7 @@ class Twig_Node_Expression_Array extends Twig_Node_Expression
|
||||
public function addElement(Twig_Node_Expression $value, Twig_Node_Expression $key = null)
|
||||
{
|
||||
if (null === $key) {
|
||||
$key = new Twig_Node_Expression_Constant(++$this->index, $value->getLine());
|
||||
$key = new Twig_Node_Expression_Constant(++$this->index, $value->getTemplateLine());
|
||||
}
|
||||
|
||||
array_push($this->nodes, $key, $value);
|
||||
|
||||
@@ -205,7 +205,7 @@ abstract class Twig_Node_Expression_Call extends Twig_Node_Expression
|
||||
throw new Twig_Error_Syntax(sprintf(
|
||||
'Unknown argument%s "%s" for %s "%s(%s)".',
|
||||
count($parameters) > 1 ? 's' : '', implode('", "', array_keys($parameters)), $callType, $callName, implode(', ', $names)
|
||||
), $unknownParameter ? $unknownParameter->getLine() : -1);
|
||||
), $unknownParameter ? $unknownParameter->getTemplateLine() : -1);
|
||||
}
|
||||
|
||||
return $arguments;
|
||||
|
||||
@@ -22,13 +22,13 @@ class Twig_Node_Expression_Filter_Default extends Twig_Node_Expression_Filter
|
||||
{
|
||||
public function __construct(Twig_NodeInterface $node, Twig_Node_Expression_Constant $filterName, Twig_NodeInterface $arguments, $lineno, $tag = null)
|
||||
{
|
||||
$default = new Twig_Node_Expression_Filter($node, new Twig_Node_Expression_Constant('default', $node->getLine()), $arguments, $node->getLine());
|
||||
$default = new Twig_Node_Expression_Filter($node, new Twig_Node_Expression_Constant('default', $node->getTemplateLine()), $arguments, $node->getTemplateLine());
|
||||
|
||||
if ('default' === $filterName->getAttribute('value') && ($node instanceof Twig_Node_Expression_Name || $node instanceof Twig_Node_Expression_GetAttr)) {
|
||||
$test = new Twig_Node_Expression_Test_Defined(clone $node, 'defined', new Twig_Node(), $node->getLine());
|
||||
$false = count($arguments) ? $arguments->getNode(0) : new Twig_Node_Expression_Constant('', $node->getLine());
|
||||
$test = new Twig_Node_Expression_Test_Defined(clone $node, 'defined', new Twig_Node(), $node->getTemplateLine());
|
||||
$false = count($arguments) ? $arguments->getNode(0) : new Twig_Node_Expression_Constant('', $node->getTemplateLine());
|
||||
|
||||
$node = new Twig_Node_Expression_Conditional($test, $default, $false, $node->getLine());
|
||||
$node = new Twig_Node_Expression_Conditional($test, $default, $false, $node->getTemplateLine());
|
||||
} else {
|
||||
$node = $default;
|
||||
}
|
||||
|
||||
@@ -13,9 +13,9 @@ class Twig_Node_Expression_NullCoalesce extends Twig_Node_Expression_Conditional
|
||||
public function __construct(Twig_NodeInterface $left, Twig_NodeInterface $right, $lineno)
|
||||
{
|
||||
$test = new Twig_Node_Expression_Binary_And(
|
||||
new Twig_Node_Expression_Test_Defined(clone $left, 'defined', new Twig_Node(), $left->getLine()),
|
||||
new Twig_Node_Expression_Unary_Not(new Twig_Node_Expression_Test_Null($left, 'null', new Twig_Node(), $left->getLine()), $left->getLine()),
|
||||
$left->getLine()
|
||||
new Twig_Node_Expression_Test_Defined(clone $left, 'defined', new Twig_Node(), $left->getTemplateLine()),
|
||||
new Twig_Node_Expression_Unary_Not(new Twig_Node_Expression_Test_Null($left, 'null', new Twig_Node(), $left->getTemplateLine()), $left->getTemplateLine()),
|
||||
$left->getTemplateLine()
|
||||
);
|
||||
|
||||
parent::__construct($test, $left, $right, $lineno);
|
||||
|
||||
@@ -32,9 +32,9 @@ class Twig_Node_Expression_Test_Defined extends Twig_Node_Expression_Test
|
||||
|
||||
$this->changeIgnoreStrictCheck($node);
|
||||
} elseif ($node instanceof Twig_Node_Expression_Constant || $node instanceof Twig_Node_Expression_Array) {
|
||||
$node = new Twig_Node_Expression_Constant(true, $node->getLine());
|
||||
$node = new Twig_Node_Expression_Constant(true, $node->getTemplateLine());
|
||||
} else {
|
||||
throw new Twig_Error_Syntax('The "defined" test only works with simple variables.', $this->getLine());
|
||||
throw new Twig_Error_Syntax('The "defined" test only works with simple variables.', $this->getTemplateLine());
|
||||
}
|
||||
|
||||
parent::__construct($node, $name, $arguments, $lineno);
|
||||
|
||||
@@ -39,7 +39,7 @@ class Twig_Node_Import extends Twig_Node
|
||||
->raw(', ')
|
||||
->repr($this->getTemplateName())
|
||||
->raw(', ')
|
||||
->repr($this->getLine())
|
||||
->repr($this->getTemplateLine())
|
||||
->raw(')')
|
||||
;
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ class Twig_Node_Include extends Twig_Node implements Twig_NodeOutputInterface
|
||||
->raw(', ')
|
||||
->repr($this->getTemplateName())
|
||||
->raw(', ')
|
||||
->repr($this->getLine())
|
||||
->repr($this->getTemplateLine())
|
||||
->raw(')')
|
||||
;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ class Twig_Node_Macro extends Twig_Node
|
||||
{
|
||||
foreach ($arguments as $argumentName => $argument) {
|
||||
if (self::VARARGS_NAME === $argumentName) {
|
||||
throw new Twig_Error_Syntax(sprintf('The argument "%s" in macro "%s" cannot be defined because the variable "%s" is reserved for arbitrary arguments.', self::VARARGS_NAME, $name, self::VARARGS_NAME), $argument->getLine());
|
||||
throw new Twig_Error_Syntax(sprintf('The argument "%s" in macro "%s" cannot be defined because the variable "%s" is reserved for arbitrary arguments.', self::VARARGS_NAME, $name, self::VARARGS_NAME), $argument->getTemplateLine());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -138,7 +138,7 @@ class Twig_Node_Module extends Twig_Node
|
||||
->raw(', ')
|
||||
->repr($this->source->getName())
|
||||
->raw(', ')
|
||||
->repr($parent->getLine())
|
||||
->repr($parent->getTemplateLine())
|
||||
->raw(')')
|
||||
;
|
||||
}
|
||||
@@ -183,7 +183,7 @@ class Twig_Node_Module extends Twig_Node
|
||||
->raw(', ')
|
||||
->repr($this->source->getName())
|
||||
->raw(', ')
|
||||
->repr($parent->getLine())
|
||||
->repr($parent->getTemplateLine())
|
||||
->raw(");\n")
|
||||
;
|
||||
}
|
||||
@@ -449,7 +449,7 @@ class Twig_Node_Module extends Twig_Node
|
||||
->raw(', ')
|
||||
->repr($node->getTemplateName())
|
||||
->raw(', ')
|
||||
->repr($node->getLine())
|
||||
->repr($node->getTemplateLine())
|
||||
->raw(");\n")
|
||||
;
|
||||
} else {
|
||||
|
||||
@@ -30,7 +30,7 @@ class Twig_Node_Set extends Twig_Node
|
||||
|
||||
$values = $this->getNode('values');
|
||||
if ($values instanceof Twig_Node_Text) {
|
||||
$this->setNode('values', new Twig_Node_Expression_Constant($values->getAttribute('data'), $values->getLine()));
|
||||
$this->setNode('values', new Twig_Node_Expression_Constant($values->getAttribute('data'), $values->getTemplateLine()));
|
||||
$this->setAttribute('capture', false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,9 @@ interface Twig_NodeInterface extends Countable, IteratorAggregate
|
||||
*/
|
||||
public function compile(Twig_Compiler $compiler);
|
||||
|
||||
/**
|
||||
* @deprecated since 1.27 (to be removed in 2.0)
|
||||
*/
|
||||
public function getLine();
|
||||
|
||||
public function getNodeTag();
|
||||
|
||||
@@ -90,7 +90,7 @@ class Twig_NodeVisitor_Escaper extends Twig_BaseNodeVisitor
|
||||
|
||||
return new $class(
|
||||
$this->getEscaperFilter($type, $expression),
|
||||
$node->getLine()
|
||||
$node->getTemplateLine()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ class Twig_NodeVisitor_Escaper extends Twig_BaseNodeVisitor
|
||||
|
||||
protected function getEscaperFilter($type, Twig_NodeInterface $node)
|
||||
{
|
||||
$line = $node->getLine();
|
||||
$line = $node->getTemplateLine();
|
||||
$name = new Twig_Node_Expression_Constant('escape', $line);
|
||||
$args = new Twig_Node(array(new Twig_Node_Expression_Constant((string) $type, $line), new Twig_Node_Expression_Constant(null, $line), new Twig_Node_Expression_Constant(true, $line)));
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ class Twig_NodeVisitor_Optimizer extends Twig_BaseNodeVisitor
|
||||
if (!$expression && get_class($node) !== 'Twig_Node' && $prependedNodes = array_shift($this->prependedNodes)) {
|
||||
$nodes = array();
|
||||
foreach (array_unique($prependedNodes) as $name) {
|
||||
$nodes[] = new Twig_Node_SetTemp($name, $node->getLine());
|
||||
$nodes[] = new Twig_Node_SetTemp($name, $node->getTemplateLine());
|
||||
}
|
||||
|
||||
$nodes[] = $node;
|
||||
@@ -114,7 +114,7 @@ class Twig_NodeVisitor_Optimizer extends Twig_BaseNodeVisitor
|
||||
if ('Twig_Node_Expression_Name' === get_class($node) && $node->isSimple()) {
|
||||
$this->prependedNodes[0][] = $node->getAttribute('name');
|
||||
|
||||
return new Twig_Node_Expression_TempName($node->getAttribute('name'), $node->getLine());
|
||||
return new Twig_Node_Expression_TempName($node->getAttribute('name'), $node->getTemplateLine());
|
||||
}
|
||||
|
||||
return $node;
|
||||
|
||||
@@ -51,7 +51,7 @@ class Twig_NodeVisitor_Sandbox extends Twig_BaseNodeVisitor
|
||||
|
||||
// wrap print to check __toString() calls
|
||||
if ($node instanceof Twig_Node_Print) {
|
||||
return new Twig_Node_SandboxedPrint($node->getNode('expr'), $node->getLine(), $node->getNodeTag());
|
||||
return new Twig_Node_SandboxedPrint($node->getNode('expr'), $node->getTemplateLine(), $node->getNodeTag());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -249,7 +249,7 @@ class Twig_Parser implements Twig_ParserInterface
|
||||
|
||||
public function setBlock($name, Twig_Node_Block $value)
|
||||
{
|
||||
$this->blocks[$name] = new Twig_Node_Body(array($value), array(), $value->getLine());
|
||||
$this->blocks[$name] = new Twig_Node_Body(array($value), array(), $value->getTemplateLine());
|
||||
}
|
||||
|
||||
public function hasMacro($name)
|
||||
@@ -260,7 +260,7 @@ class Twig_Parser implements Twig_ParserInterface
|
||||
public function setMacro($name, Twig_Node_Macro $node)
|
||||
{
|
||||
if ($this->isReservedMacroName($name)) {
|
||||
throw new Twig_Error_Syntax(sprintf('"%s" cannot be used as a macro name as it is a reserved keyword.', $name), $node->getLine(), $this->stream->getSourceContext()->getName());
|
||||
throw new Twig_Error_Syntax(sprintf('"%s" cannot be used as a macro name as it is a reserved keyword.', $name), $node->getTemplateLine(), $this->stream->getSourceContext()->getName());
|
||||
}
|
||||
|
||||
$this->macros[$name] = $node;
|
||||
@@ -378,10 +378,10 @@ class Twig_Parser implements Twig_ParserInterface
|
||||
(!$node instanceof Twig_Node_Text && !$node instanceof Twig_Node_BlockReference && $node instanceof Twig_NodeOutputInterface)
|
||||
) {
|
||||
if (false !== strpos((string) $node, chr(0xEF).chr(0xBB).chr(0xBF))) {
|
||||
throw new Twig_Error_Syntax('A template that extends another one cannot start with a byte order mark (BOM); it must be removed.', $node->getLine(), $this->stream->getSourceContext()->getName());
|
||||
throw new Twig_Error_Syntax('A template that extends another one cannot start with a byte order mark (BOM); it must be removed.', $node->getTemplateLine(), $this->stream->getSourceContext()->getName());
|
||||
}
|
||||
|
||||
throw new Twig_Error_Syntax('A template that extends another one cannot include contents outside Twig blocks. Did you forget to put the contents inside a {% block %} tag?', $node->getLine(), $this->stream->getSourceContext()->getName());
|
||||
throw new Twig_Error_Syntax('A template that extends another one cannot include contents outside Twig blocks. Did you forget to put the contents inside a {% block %} tag?', $node->getTemplateLine(), $this->stream->getSourceContext()->getName());
|
||||
}
|
||||
|
||||
// bypass "set" nodes as they "capture" the output
|
||||
|
||||
@@ -28,7 +28,7 @@ class Twig_TokenParser_Block extends Twig_TokenParser
|
||||
$stream = $this->parser->getStream();
|
||||
$name = $stream->expect(Twig_Token::NAME_TYPE)->getValue();
|
||||
if ($this->parser->hasBlock($name)) {
|
||||
throw new Twig_Error_Syntax(sprintf("The block '%s' has already been defined line %d.", $name, $this->parser->getBlock($name)->getLine()), $stream->getCurrent()->getLine(), $stream->getSourceContext()->getName());
|
||||
throw new Twig_Error_Syntax(sprintf("The block '%s' has already been defined line %d.", $name, $this->parser->getBlock($name)->getTemplateLine()), $stream->getCurrent()->getLine(), $stream->getSourceContext()->getName());
|
||||
}
|
||||
$this->parser->setBlock($name, $block = new Twig_Node_Block($name, new Twig_Node(array()), $lineno));
|
||||
$this->parser->pushLocalScope();
|
||||
|
||||
@@ -48,13 +48,13 @@ class Twig_TokenParser_For extends Twig_TokenParser
|
||||
|
||||
if (count($targets) > 1) {
|
||||
$keyTarget = $targets->getNode(0);
|
||||
$keyTarget = new Twig_Node_Expression_AssignName($keyTarget->getAttribute('name'), $keyTarget->getLine());
|
||||
$keyTarget = new Twig_Node_Expression_AssignName($keyTarget->getAttribute('name'), $keyTarget->getTemplateLine());
|
||||
$valueTarget = $targets->getNode(1);
|
||||
$valueTarget = new Twig_Node_Expression_AssignName($valueTarget->getAttribute('name'), $valueTarget->getLine());
|
||||
$valueTarget = new Twig_Node_Expression_AssignName($valueTarget->getAttribute('name'), $valueTarget->getTemplateLine());
|
||||
} else {
|
||||
$keyTarget = new Twig_Node_Expression_AssignName('_key', $lineno);
|
||||
$valueTarget = $targets->getNode(0);
|
||||
$valueTarget = new Twig_Node_Expression_AssignName($valueTarget->getAttribute('name'), $valueTarget->getLine());
|
||||
$valueTarget = new Twig_Node_Expression_AssignName($valueTarget->getAttribute('name'), $valueTarget->getTemplateLine());
|
||||
}
|
||||
|
||||
if ($ifexpr) {
|
||||
@@ -79,7 +79,7 @@ class Twig_TokenParser_For extends Twig_TokenParser
|
||||
protected function checkLoopUsageCondition(Twig_TokenStream $stream, Twig_NodeInterface $node)
|
||||
{
|
||||
if ($node instanceof Twig_Node_Expression_GetAttr && $node->getNode('node') instanceof Twig_Node_Expression_Name && 'loop' == $node->getNode('node')->getAttribute('name')) {
|
||||
throw new Twig_Error_Syntax('The "loop" variable cannot be used in a looping condition.', $node->getLine(), $stream->getSourceContext()->getName());
|
||||
throw new Twig_Error_Syntax('The "loop" variable cannot be used in a looping condition.', $node->getTemplateLine(), $stream->getSourceContext()->getName());
|
||||
}
|
||||
|
||||
foreach ($node as $n) {
|
||||
@@ -98,7 +98,7 @@ class Twig_TokenParser_For extends Twig_TokenParser
|
||||
if ($node instanceof Twig_Node_Expression_GetAttr && $node->getNode('node') instanceof Twig_Node_Expression_Name && 'loop' == $node->getNode('node')->getAttribute('name')) {
|
||||
$attribute = $node->getNode('attribute');
|
||||
if ($attribute instanceof Twig_Node_Expression_Constant && in_array($attribute->getAttribute('value'), array('length', 'revindex0', 'revindex', 'last'))) {
|
||||
throw new Twig_Error_Syntax(sprintf('The "loop.%s" variable is not defined when looping with a condition.', $attribute->getAttribute('value')), $node->getLine(), $stream->getSourceContext()->getName());
|
||||
throw new Twig_Error_Syntax(sprintf('The "loop.%s" variable is not defined when looping with a condition.', $attribute->getAttribute('value')), $node->getTemplateLine(), $stream->getSourceContext()->getName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ class Twig_TokenParser_Sandbox extends Twig_TokenParser
|
||||
}
|
||||
|
||||
if (!$node instanceof Twig_Node_Include) {
|
||||
throw new Twig_Error_Syntax('Only "include" tags are allowed within a "sandbox" section.', $node->getLine(), $stream->getSourceContext()->getName());
|
||||
throw new Twig_Error_Syntax('Only "include" tags are allowed within a "sandbox" section.', $node->getTemplateLine(), $stream->getSourceContext()->getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user