*/
class Twig_Node_For extends Twig_Node
{
- public function __construct(Twig_Node_Expression_AssignName $keyTarget, Twig_Node_Expression_AssignName $valueTarget, Twig_Node_Expression $seq, Twig_NodeInterface $body, Twig_NodeInterface $else = null, Twig_Node_Expression $joinedBy = null, $lineno, $tag = null)
+ public function __construct(Twig_Node_Expression_AssignName $keyTarget, Twig_Node_Expression_AssignName $valueTarget, Twig_Node_Expression $seq, Twig_NodeInterface $body, Twig_NodeInterface $else = null, $lineno, $tag = null)
{
- parent::__construct(array('key_target' => $keyTarget, 'value_target' => $valueTarget, 'seq' => $seq, 'body' => $body, 'else' => $else, 'joined_with' => $joinedBy), array('with_loop' => true), $lineno, $tag);
+ parent::__construct(array('key_target' => $keyTarget, 'value_target' => $valueTarget, 'seq' => $seq, 'body' => $body, 'else' => $else), array('with_loop' => true), $lineno, $tag);
}
/**
->raw(");\n")
;
- if (null !== $this->getNode('else') || null !== $this->getNode('joined_with')) {
+ if (null !== $this->getNode('else')) {
$compiler->write("\$context['_iterated'] = false;\n");
}
->indent()
;
- if (null !== $this->getNode('joined_with')) {
- $compiler
- ->write("if (\$context['_iterated']) {\n")
- ->indent()
- ->write("echo ")
- ->subcompile($this->getNode('joined_with'))
- ->raw(";\n")
- ->outdent()
- ->write("}\n");
- }
-
$compiler->subcompile($this->getNode('body'));
- if (null !== $this->getNode('else') || null !== $this->getNode('joined_with')) {
+ if (null !== $this->getNode('else')) {
$compiler->write("\$context['_iterated'] = true;\n");
}
$this->parser->getStream()->expect(Twig_Token::OPERATOR_TYPE, 'in');
$seq = $this->parser->getExpressionParser()->parseExpression();
- $joinedBy = null;
- if ($this->parser->getStream()->test('joined')) {
- $this->parser->getStream()->next();
- $this->parser->getStream()->expect('by');
- $joinedBy = $this->parser->getExpressionParser()->parseExpression();
- }
-
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
$body = $this->parser->subparse(array($this, 'decideForFork'));
if ($this->parser->getStream()->next()->getValue() == 'else') {
$valueTarget = $targets->getNode(0);
}
- return new Twig_Node_For($keyTarget, $valueTarget, $seq, $body, $else, $joinedBy, $lineno, $this->getTag());
+ return new Twig_Node_For($keyTarget, $valueTarget, $seq, $body, $else, $lineno, $this->getTag());
}
public function decideForFork($token)
$seq = new Twig_Node_Expression_Name('items', 0);
$body = new Twig_Node_Print(new Twig_Node_Expression_Name('foo', 0), 0);
$else = null;
- $node = new Twig_Node_For($keyTarget, $valueTarget, $seq, $body, $else, null, 0);
+ $node = new Twig_Node_For($keyTarget, $valueTarget, $seq, $body, $else, 0);
$node->setAttribute('with_loop', false);
$this->assertEquals($keyTarget, $node->getNode('key_target'));
$this->assertEquals(null, $node->getNode('else'));
$else = new Twig_Node_Print(new Twig_Node_Expression_Name('foo', 0), 0);
- $node = new Twig_Node_For($keyTarget, $valueTarget, $seq, $body, $else, null, 0);
+ $node = new Twig_Node_For($keyTarget, $valueTarget, $seq, $body, $else, 0);
$node->setAttribute('with_loop', false);
$this->assertEquals($else, $node->getNode('else'));
}
$seq = new Twig_Node_Expression_Name('items', 0);
$body = new Twig_Node_Print(new Twig_Node_Expression_Name('foo', 0), 0);
$else = null;
- $node = new Twig_Node_For($keyTarget, $valueTarget, $seq, $body, $else, null, 0);
+ $node = new Twig_Node_For($keyTarget, $valueTarget, $seq, $body, $else, 0);
$node->setAttribute('with_loop', false);
$tests[] = array($node, <<<EOF
$seq = new Twig_Node_Expression_Name('values', 0);
$body = new Twig_Node_Print(new Twig_Node_Expression_Name('foo', 0), 0);
$else = null;
- $joinedBy = new Twig_Node_Expression_Constant(', ', 0);
- $node = new Twig_Node_For($keyTarget, $valueTarget, $seq, $body, $else, $joinedBy, 0);
+ $node = new Twig_Node_For($keyTarget, $valueTarget, $seq, $body, $else, 0);
$node->setAttribute('with_loop', true);
$tests[] = array($node, <<<EOF
\$context['_parent'] = (array) \$context;
\$context['_seq'] = twig_ensure_traversable((isset(\$context['values']) ? \$context['values'] : null));
-\$context['_iterated'] = false;
\$context['loop'] = array(
'parent' => \$context['_parent'],
'index0' => 0,
\$context['loop']['last'] = 1 === \$length;
}
foreach (\$context['_seq'] as \$context['k'] => \$context['v']) {
- if (\$context['_iterated']) {
- echo ", ";
- }
echo (isset(\$context['foo']) ? \$context['foo'] : null);
- \$context['_iterated'] = true;
++\$context['loop']['index0'];
++\$context['loop']['index'];
\$context['loop']['first'] = false;
$seq = new Twig_Node_Expression_Name('values', 0);
$body = new Twig_Node_Print(new Twig_Node_Expression_Name('foo', 0), 0);
$else = new Twig_Node_Print(new Twig_Node_Expression_Name('foo', 0), 0);
- $node = new Twig_Node_For($keyTarget, $valueTarget, $seq, $body, $else, null, 0);
+ $node = new Twig_Node_For($keyTarget, $valueTarget, $seq, $body, $else, 0);
$node->setAttribute('with_loop', true);
$tests[] = array($node, <<<EOF