new Twig_TokenParser_Filter(),
new Twig_TokenParser_Macro(),
new Twig_TokenParser_Import(),
+ new Twig_TokenParser_Set(),
);
}
class Twig_Node_Set extends Twig_Node
{
- protected $name;
+ protected $names;
protected $value;
+ protected $isMultitarget;
- public function __construct($name, Twig_Node_Expression $value, $lineno)
+ public function __construct($isMultitarget, $names, Twig_Node_Expression $value, $lineno)
{
parent::__construct($lineno);
- $this->name = $name;
+ $this->isMultitarget = $isMultitarget;
+ $this->names = $names;
$this->value = $value;
}
public function compile($compiler)
{
+ $compiler->addDebugInfo($this);
+
+ if ($this->isMultitarget)
+ {
+ $compiler->write('list(');
+ foreach ($this->names as $idx => $node)
+ {
+ if ($idx)
+ {
+ $compiler->raw(', ');
+ }
+
+ $compiler
+ ->raw('$context[')
+ ->string($node->getName())
+ ->raw(']')
+ ;
+ }
+ $compiler->raw(')');
+ }
+ else
+ {
+ $compiler
+ ->write('$context[')
+ ->string($this->names->getName())
+ ->raw(']')
+ ;
+ }
+
$compiler
- ->addDebugInfo($this)
- ->write('$context[')
- ->string($this->name)
- ->write('] = ')
+ ->raw(' = ')
->subcompile($this->value)
->raw(";\n")
;
public function parse(Twig_Token $token)
{
$lineno = $token->getLine();
- $name = $this->parser->getStream()->expect(Twig_Token::NAME_TYPE)->getValue();
+ list($isMultitarget, $names) = $this->parser->getExpressionParser()->parseAssignmentExpression();
+ $this->parser->getStream()->expect(Twig_Token::NAME_TYPE, 'as');
$value = $this->parser->getExpressionParser()->parseExpression();
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
- return new Twig_Node_Set($name, $value, $lineno, $this->getTag());
+ return new Twig_Node_Set($isMultitarget, $names, $value, $lineno, $this->getTag());
}
public function getTag()