forked from leftypol/leftypol
Twig update to latest Twig 1.x legacy as per vichan
This commit is contained in:
parent
4ecd84f81d
commit
e6c07544da
198 changed files with 6150 additions and 2506 deletions
|
@ -3,8 +3,8 @@
|
|||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2009 Fabien Potencier
|
||||
* (c) 2009 Armin Ronacher
|
||||
* (c) Fabien Potencier
|
||||
* (c) Armin Ronacher
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
|
@ -20,16 +20,11 @@
|
|||
* {% endfor %}
|
||||
* </ul>
|
||||
* </pre>
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
class Twig_TokenParser_For extends Twig_TokenParser
|
||||
{
|
||||
/**
|
||||
* Parses a token and returns a node.
|
||||
*
|
||||
* @param Twig_Token $token A Twig_Token instance
|
||||
*
|
||||
* @return Twig_NodeInterface A Twig_NodeInterface instance
|
||||
*/
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
$lineno = $token->getLine();
|
||||
|
@ -39,14 +34,13 @@ class Twig_TokenParser_For extends Twig_TokenParser
|
|||
$seq = $this->parser->getExpressionParser()->parseExpression();
|
||||
|
||||
$ifexpr = null;
|
||||
if ($stream->test(Twig_Token::NAME_TYPE, 'if')) {
|
||||
$stream->next();
|
||||
if ($stream->nextIf(Twig_Token::NAME_TYPE, 'if')) {
|
||||
$ifexpr = $this->parser->getExpressionParser()->parseExpression();
|
||||
}
|
||||
|
||||
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
||||
$body = $this->parser->subparse(array($this, 'decideForFork'));
|
||||
if ($stream->next()->getValue() == 'else') {
|
||||
if ('else' == $stream->next()->getValue()) {
|
||||
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
||||
$else = $this->parser->subparse(array($this, 'decideForEnd'), true);
|
||||
} else {
|
||||
|
@ -56,13 +50,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) {
|
||||
|
@ -87,7 +81,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->getFilename());
|
||||
throw new Twig_Error_Syntax('The "loop" variable cannot be used in a looping condition.', $node->getTemplateLine(), $stream->getSourceContext());
|
||||
}
|
||||
|
||||
foreach ($node as $n) {
|
||||
|
@ -106,7 +100,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->getFilename());
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -124,13 +118,10 @@ class Twig_TokenParser_For extends Twig_TokenParser
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the tag name associated with this token parser.
|
||||
*
|
||||
* @return string The tag name
|
||||
*/
|
||||
public function getTag()
|
||||
{
|
||||
return 'for';
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('Twig_TokenParser_For', 'Twig\TokenParser\ForTokenParser', false);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue