*/
public function compile(Twig_Compiler $compiler)
{
- $compiler->raw(sprintf('$context[\'%s\']', $this->getAttribute('name')));
+ $compiler
+ ->raw('$context[')
+ ->string($this->getAttribute('name'))
+ ->raw(']')
+ ;
}
}
} elseif (isset($specialVars[$name])) {
$compiler->raw($specialVars[$name]);
} else {
- $compiler->raw(sprintf('$this->getContext($context, \'%s\')', $name));
+ $compiler
+ ->raw('$this->getContext($context, ')
+ ->string($name)
+ ->raw(')')
+ ;
}
}
}
$node = new Twig_Node_Expression_AssignName('foo', 0);
return array(
- array($node, '$context[\'foo\']'),
+ array($node, '$context["foo"]'),
);
}
}
$attr = new Twig_Node_Expression_Constant('bar', 0);
$args = new Twig_Node();
$node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_TemplateInterface::ANY_CALL, 0);
- $tests[] = array($node, '$this->getAttribute($this->getContext($context, \'foo\'), "bar", array(), "any", false)');
+ $tests[] = array($node, '$this->getAttribute($this->getContext($context, "foo"), "bar", array(), "any", false)');
$node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_TemplateInterface::ARRAY_CALL, 0);
- $tests[] = array($node, '$this->getAttribute($this->getContext($context, \'foo\'), "bar", array(), "array", false)');
+ $tests[] = array($node, '$this->getAttribute($this->getContext($context, "foo"), "bar", array(), "array", false)');
$args = new Twig_Node(array(
new Twig_Node_Expression_Constant('bar', 0),
));
$node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_TemplateInterface::METHOD_CALL, 0);
- $tests[] = array($node, '$this->getAttribute($this->getContext($context, \'foo\'), "bar", array($this->getContext($context, \'foo\'), "bar", ), "method", false)');
+ $tests[] = array($node, '$this->getAttribute($this->getContext($context, "foo"), "bar", array($this->getContext($context, "foo"), "bar", ), "method", false)');
return $tests;
}
$env = new Twig_Environment(null, array('strict_variables' => true));
return array(
- array($node, '$this->getContext($context, \'foo\')', $env),
- array($node, '$this->getContext($context, \'foo\')'),
+ array($node, '$this->getContext($context, "foo")', $env),
+ array($node, '$this->getContext($context, "foo")'),
array($self, '$this'),
array($context, '$context'),
);
$tests[] = array($node, <<<EOF
\$context['_parent'] = (array) \$context;
-\$context['_seq'] = twig_ensure_traversable(\$this->getContext(\$context, 'items'));
-foreach (\$context['_seq'] as \$context['key'] => \$context['item']) {
- echo \$this->getContext(\$context, 'foo');
+\$context['_seq'] = twig_ensure_traversable(\$this->getContext(\$context, "items"));
+foreach (\$context['_seq'] as \$context["key"] => \$context["item"]) {
+ echo \$this->getContext(\$context, "foo");
}
\$_parent = \$context['_parent'];
unset(\$context['_seq'], \$context['_iterated'], \$context['key'], \$context['item'], \$context['_parent'], \$context['loop']);
$tests[] = array($node, <<<EOF
\$context['_parent'] = (array) \$context;
-\$context['_seq'] = twig_ensure_traversable(\$this->getContext(\$context, 'values'));
+\$context['_seq'] = twig_ensure_traversable(\$this->getContext(\$context, "values"));
\$context['loop'] = array(
'parent' => \$context['_parent'],
'index0' => 0,
\$context['loop']['length'] = \$length;
\$context['loop']['last'] = 1 === \$length;
}
-foreach (\$context['_seq'] as \$context['k'] => \$context['v']) {
- echo \$this->getContext(\$context, 'foo');
+foreach (\$context['_seq'] as \$context["k"] => \$context["v"]) {
+ echo \$this->getContext(\$context, "foo");
++\$context['loop']['index0'];
++\$context['loop']['index'];
\$context['loop']['first'] = false;
$tests[] = array($node, <<<EOF
\$context['_parent'] = (array) \$context;
-\$context['_seq'] = twig_ensure_traversable(\$this->getContext(\$context, 'values'));
+\$context['_seq'] = twig_ensure_traversable(\$this->getContext(\$context, "values"));
\$context['loop'] = array(
'parent' => \$context['_parent'],
'index0' => 0,
'index' => 1,
'first' => true,
);
-foreach (\$context['_seq'] as \$context['k'] => \$context['v']) {
+foreach (\$context['_seq'] as \$context["k"] => \$context["v"]) {
if (!(true)) {
continue;
}
- echo \$this->getContext(\$context, 'foo');
+ echo \$this->getContext(\$context, "foo");
++\$context['loop']['index0'];
++\$context['loop']['index'];
\$context['loop']['first'] = false;
$tests[] = array($node, <<<EOF
\$context['_parent'] = (array) \$context;
-\$context['_seq'] = twig_ensure_traversable(\$this->getContext(\$context, 'values'));
+\$context['_seq'] = twig_ensure_traversable(\$this->getContext(\$context, "values"));
\$context['_iterated'] = false;
\$context['loop'] = array(
'parent' => \$context['_parent'],
\$context['loop']['length'] = \$length;
\$context['loop']['last'] = 1 === \$length;
}
-foreach (\$context['_seq'] as \$context['k'] => \$context['v']) {
- echo \$this->getContext(\$context, 'foo');
+foreach (\$context['_seq'] as \$context["k"] => \$context["v"]) {
+ echo \$this->getContext(\$context, "foo");
\$context['_iterated'] = true;
++\$context['loop']['index0'];
++\$context['loop']['index'];
}
}
if (!\$context['_iterated']) {
- echo \$this->getContext(\$context, 'foo');
+ echo \$this->getContext(\$context, "foo");
}
\$_parent = \$context['_parent'];
unset(\$context['_seq'], \$context['_iterated'], \$context['k'], \$context['v'], \$context['_parent'], \$context['loop']);
$tests[] = array($node, <<<EOF
if (true) {
- echo \$this->getContext(\$context, 'foo');
+ echo \$this->getContext(\$context, "foo");
}
EOF
);
$tests[] = array($node, <<<EOF
if (true) {
- echo \$this->getContext(\$context, 'foo');
+ echo \$this->getContext(\$context, "foo");
} elseif (false) {
- echo \$this->getContext(\$context, 'bar');
+ echo \$this->getContext(\$context, "bar");
}
EOF
);
$tests[] = array($node, <<<EOF
if (true) {
- echo \$this->getContext(\$context, 'foo');
+ echo \$this->getContext(\$context, "foo");
} else {
- echo \$this->getContext(\$context, 'bar');
+ echo \$this->getContext(\$context, "bar");
}
EOF
);
$var = new Twig_Node_Expression_AssignName('macro', 0);
$node = new Twig_Node_Import($macro, $var, 0);
- $tests[] = array($node, '$context[\'macro\'] = $this->env->loadTemplate("foo.twig");');
+ $tests[] = array($node, '$context["macro"] = $this->env->loadTemplate("foo.twig");');
return $tests;
}
{
\$context = array_merge(\$this->env->getGlobals(), \$context);
- \$context['macro'] = \$this->env->loadTemplate("foo.twig");
+ \$context["macro"] = \$this->env->loadTemplate("foo.twig");
\$this->getParent(\$context)->display(\$context, array_merge(\$this->blocks, \$blocks));
}
$names = new Twig_Node(array(new Twig_Node_Expression_AssignName('foo', 0)), array(), 0);
$values = new Twig_Node(array(new Twig_Node_Expression_Constant('foo', 0)), array(), 0);
$node = new Twig_Node_Set(false, $names, $values, 0);
- $tests[] = array($node, '$context[\'foo\'] = "foo";');
+ $tests[] = array($node, '$context["foo"] = "foo";');
$names = new Twig_Node(array(new Twig_Node_Expression_AssignName('foo', 0)), array(), 0);
$values = new Twig_Node(array(new Twig_Node_Print(new Twig_Node_Expression_Constant('foo', 0), 0)), array(), 0);
$tests[] = array($node, <<<EOF
ob_start();
echo "foo";
-\$context['foo'] = new Twig_Markup(ob_get_clean());
+\$context["foo"] = new Twig_Markup(ob_get_clean());
EOF
);
$names = new Twig_Node(array(new Twig_Node_Expression_AssignName('foo', 0)), array(), 0);
$values = new Twig_Node_Text('foo', 0);
$node = new Twig_Node_Set(true, $names, $values, 0);
- $tests[] = array($node, '$context[\'foo\'] = new Twig_Markup("foo");');
+ $tests[] = array($node, '$context["foo"] = new Twig_Markup("foo");');
$names = new Twig_Node(array(new Twig_Node_Expression_AssignName('foo', 0), new Twig_Node_Expression_AssignName('bar', 0)), array(), 0);
$values = new Twig_Node(array(new Twig_Node_Expression_Constant('foo', 0), new Twig_Node_Expression_Name('bar', 0)), array(), 0);
$node = new Twig_Node_Set(false, $names, $values, 0);
$tests[] = array($node, <<<EOF
-list(\$context['foo'], \$context['bar']) = array("foo", \$this->getContext(\$context, 'bar'));
+list(\$context["foo"], \$context["bar"]) = array("foo", \$this->getContext(\$context, "bar"));
EOF
);