From 39d94dfb40ea69cc50896e043c8b793cdd3f5605 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 19 Oct 2016 14:53:10 -0700 Subject: [PATCH] renamed Twig_Node::getLine() to Twig_Node::getTemplateLine() --- CHANGELOG | 1 + doc/deprecated.rst | 5 +++-- lib/Twig/Compiler.php | 8 ++++---- lib/Twig/ExpressionParser.php | 2 +- lib/Twig/Extension/Core.php | 2 +- lib/Twig/Node.php | 10 ++++++++++ lib/Twig/Node/CheckSecurity.php | 2 +- lib/Twig/Node/Embed.php | 2 +- lib/Twig/Node/Expression/Array.php | 2 +- lib/Twig/Node/Expression/Call.php | 2 +- lib/Twig/Node/Expression/Filter/Default.php | 8 ++++---- lib/Twig/Node/Expression/NullCoalesce.php | 6 +++--- lib/Twig/Node/Expression/Test/Defined.php | 4 ++-- lib/Twig/Node/Import.php | 2 +- lib/Twig/Node/Include.php | 2 +- lib/Twig/Node/Macro.php | 2 +- lib/Twig/Node/Module.php | 6 +++--- lib/Twig/Node/Set.php | 2 +- lib/Twig/NodeInterface.php | 3 +++ lib/Twig/NodeVisitor/Escaper.php | 4 ++-- lib/Twig/NodeVisitor/Optimizer.php | 4 ++-- lib/Twig/NodeVisitor/Sandbox.php | 2 +- lib/Twig/Parser.php | 8 ++++---- lib/Twig/TokenParser/Block.php | 2 +- lib/Twig/TokenParser/For.php | 10 +++++----- lib/Twig/TokenParser/Sandbox.php | 2 +- 26 files changed, 59 insertions(+), 44 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 2994b6aa2..82b387725 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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) diff --git a/doc/deprecated.rst b/doc/deprecated.rst index 3a72d04bc..987a100b2 100644 --- a/doc/deprecated.rst +++ b/doc/deprecated.rst @@ -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 ---------- diff --git a/lib/Twig/Compiler.php b/lib/Twig/Compiler.php index 527821d33..a33e13746 100644 --- a/lib/Twig/Compiler.php +++ b/lib/Twig/Compiler.php @@ -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; diff --git a/lib/Twig/ExpressionParser.php b/lib/Twig/ExpressionParser.php index 8a95da022..3c4cadee0 100644 --- a/lib/Twig/ExpressionParser.php +++ b/lib/Twig/ExpressionParser.php @@ -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; diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php index e08318cc6..e953b8c49 100644 --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@ -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); diff --git a/lib/Twig/Node.php b/lib/Twig/Node.php index 6c8fe0ce7..60a80f3c3 100644 --- a/lib/Twig/Node.php +++ b/lib/Twig/Node.php @@ -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; } diff --git a/lib/Twig/Node/CheckSecurity.php b/lib/Twig/Node/CheckSecurity.php index bf8eb00b2..52db7d2bf 100644 --- a/lib/Twig/Node/CheckSecurity.php +++ b/lib/Twig/Node/CheckSecurity.php @@ -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; } diff --git a/lib/Twig/Node/Embed.php b/lib/Twig/Node/Embed.php index ffa83ae18..d9af37b23 100644 --- a/lib/Twig/Node/Embed.php +++ b/lib/Twig/Node/Embed.php @@ -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(')') diff --git a/lib/Twig/Node/Expression/Array.php b/lib/Twig/Node/Expression/Array.php index 83e583b04..77c95d5a1 100644 --- a/lib/Twig/Node/Expression/Array.php +++ b/lib/Twig/Node/Expression/Array.php @@ -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); diff --git a/lib/Twig/Node/Expression/Call.php b/lib/Twig/Node/Expression/Call.php index 1865043cc..209d0c12e 100644 --- a/lib/Twig/Node/Expression/Call.php +++ b/lib/Twig/Node/Expression/Call.php @@ -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; diff --git a/lib/Twig/Node/Expression/Filter/Default.php b/lib/Twig/Node/Expression/Filter/Default.php index 1827c8886..5ce172bcd 100644 --- a/lib/Twig/Node/Expression/Filter/Default.php +++ b/lib/Twig/Node/Expression/Filter/Default.php @@ -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; } diff --git a/lib/Twig/Node/Expression/NullCoalesce.php b/lib/Twig/Node/Expression/NullCoalesce.php index 10039130c..65fa363b7 100644 --- a/lib/Twig/Node/Expression/NullCoalesce.php +++ b/lib/Twig/Node/Expression/NullCoalesce.php @@ -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); diff --git a/lib/Twig/Node/Expression/Test/Defined.php b/lib/Twig/Node/Expression/Test/Defined.php index 3dc6ff592..c57fe09eb 100644 --- a/lib/Twig/Node/Expression/Test/Defined.php +++ b/lib/Twig/Node/Expression/Test/Defined.php @@ -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); diff --git a/lib/Twig/Node/Import.php b/lib/Twig/Node/Import.php index 61cba18b3..507fb6625 100644 --- a/lib/Twig/Node/Import.php +++ b/lib/Twig/Node/Import.php @@ -39,7 +39,7 @@ class Twig_Node_Import extends Twig_Node ->raw(', ') ->repr($this->getTemplateName()) ->raw(', ') - ->repr($this->getLine()) + ->repr($this->getTemplateLine()) ->raw(')') ; } diff --git a/lib/Twig/Node/Include.php b/lib/Twig/Node/Include.php index 4bb3178f2..714c9915a 100644 --- a/lib/Twig/Node/Include.php +++ b/lib/Twig/Node/Include.php @@ -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(')') ; } diff --git a/lib/Twig/Node/Macro.php b/lib/Twig/Node/Macro.php index c186cd0b9..9280e294c 100644 --- a/lib/Twig/Node/Macro.php +++ b/lib/Twig/Node/Macro.php @@ -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()); } } diff --git a/lib/Twig/Node/Module.php b/lib/Twig/Node/Module.php index e6d4b8b5a..fe7da34d4 100644 --- a/lib/Twig/Node/Module.php +++ b/lib/Twig/Node/Module.php @@ -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 { diff --git a/lib/Twig/Node/Set.php b/lib/Twig/Node/Set.php index e5a660375..b77b8b6ef 100644 --- a/lib/Twig/Node/Set.php +++ b/lib/Twig/Node/Set.php @@ -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); } } diff --git a/lib/Twig/NodeInterface.php b/lib/Twig/NodeInterface.php index 8077349b3..360b45740 100644 --- a/lib/Twig/NodeInterface.php +++ b/lib/Twig/NodeInterface.php @@ -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(); diff --git a/lib/Twig/NodeVisitor/Escaper.php b/lib/Twig/NodeVisitor/Escaper.php index 9aecfee6b..28a979224 100644 --- a/lib/Twig/NodeVisitor/Escaper.php +++ b/lib/Twig/NodeVisitor/Escaper.php @@ -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))); diff --git a/lib/Twig/NodeVisitor/Optimizer.php b/lib/Twig/NodeVisitor/Optimizer.php index 882d2bbbb..64b3e2fed 100644 --- a/lib/Twig/NodeVisitor/Optimizer.php +++ b/lib/Twig/NodeVisitor/Optimizer.php @@ -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; diff --git a/lib/Twig/NodeVisitor/Sandbox.php b/lib/Twig/NodeVisitor/Sandbox.php index 7f1b913b7..a5e23c292 100644 --- a/lib/Twig/NodeVisitor/Sandbox.php +++ b/lib/Twig/NodeVisitor/Sandbox.php @@ -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()); } } diff --git a/lib/Twig/Parser.php b/lib/Twig/Parser.php index 07f6b8d55..9ababd0ad 100644 --- a/lib/Twig/Parser.php +++ b/lib/Twig/Parser.php @@ -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 diff --git a/lib/Twig/TokenParser/Block.php b/lib/Twig/TokenParser/Block.php index a239ad117..a2df92893 100644 --- a/lib/Twig/TokenParser/Block.php +++ b/lib/Twig/TokenParser/Block.php @@ -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(); diff --git a/lib/Twig/TokenParser/For.php b/lib/Twig/TokenParser/For.php index 0d5cd9c02..90553a161 100644 --- a/lib/Twig/TokenParser/For.php +++ b/lib/Twig/TokenParser/For.php @@ -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()); } } diff --git a/lib/Twig/TokenParser/Sandbox.php b/lib/Twig/TokenParser/Sandbox.php index f361fa134..4809d16a4 100644 --- a/lib/Twig/TokenParser/Sandbox.php +++ b/lib/Twig/TokenParser/Sandbox.php @@ -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()); } } }