replaced array() by [] in *generated* PHP code

This commit is contained in:
Fabien Potencier
2015-01-14 09:57:10 +01:00
parent 5388a13641
commit 6d50f987fb
11 changed files with 37 additions and 32 deletions
+2 -2
View File
@@ -180,7 +180,7 @@ class Twig_Compiler
} elseif (is_bool($value)) {
$this->raw($value ? 'true' : 'false');
} elseif (is_array($value)) {
$this->raw('array(');
$this->raw('[');
$first = true;
foreach ($value as $key => $v) {
if (!$first) {
@@ -191,7 +191,7 @@ class Twig_Compiler
$this->raw(' => ');
$this->repr($v);
}
$this->raw(')');
$this->raw(']');
} else {
$this->string($value);
}
+3 -3
View File
@@ -48,9 +48,9 @@ class Twig_Node_CheckSecurity extends Twig_Node
->indent()
->write("\$this->env->getExtension('sandbox')->checkSecurity(\n")
->indent()
->write(!$tags ? "array(),\n" : "array('".implode("', '", array_keys($tags))."'),\n")
->write(!$filters ? "array(),\n" : "array('".implode("', '", array_keys($filters))."'),\n")
->write(!$functions ? "array()\n" : "array('".implode("', '", array_keys($functions))."')\n")
->write(!$tags ? "[],\n" : "['".implode("', '", array_keys($tags))."'],\n")
->write(!$filters ? "[],\n" : "['".implode("', '", array_keys($filters))."'],\n")
->write(!$functions ? "[]\n" : "['".implode("', '", array_keys($functions))."']\n")
->outdent()
->write(");\n")
->outdent()
+2 -2
View File
@@ -67,7 +67,7 @@ class Twig_Node_Expression_Array extends Twig_Node_Expression
*/
public function compile(Twig_Compiler $compiler)
{
$compiler->raw('array(');
$compiler->raw('[');
$first = true;
foreach ($this->getKeyValuePairs() as $pair) {
if (!$first) {
@@ -81,6 +81,6 @@ class Twig_Node_Expression_Array extends Twig_Node_Expression
->subcompile($pair['value'])
;
}
$compiler->raw(')');
$compiler->raw(']');
}
}
+1 -1
View File
@@ -74,7 +74,7 @@ class Twig_Node_Include extends Twig_Node implements Twig_NodeOutputInterface
protected function addTemplateArguments(Twig_Compiler $compiler)
{
if (null === $this->getNode('variables')) {
$compiler->raw(false === $this->getAttribute('only') ? '$context' : 'array()');
$compiler->raw(false === $this->getAttribute('only') ? '$context' : '[]');
} elseif (false === $this->getAttribute('only')) {
$compiler
->raw('array_merge($context, ')
+12 -7
View File
@@ -238,11 +238,11 @@ class Twig_Node_Module extends Twig_Node
->write("\$this->blocks = array_merge(\n")
->indent()
->write("\$this->traits,\n")
->write("array(\n")
->write("[\n")
;
} else {
$compiler
->write("\$this->blocks = array(\n")
->write("\$this->blocks = [\n")
;
}
@@ -253,20 +253,25 @@ class Twig_Node_Module extends Twig_Node
foreach ($this->getNode('blocks') as $name => $node) {
$compiler
->write(sprintf("'%s' => array(\$this, 'block_%s'),\n", $name, $name))
->write(sprintf("'%s' => [\$this, 'block_%s'],\n", $name, $name))
;
}
if ($countTraits) {
$compiler
->outdent()
->write(")\n")
->write("]\n")
->outdent()
->write(");\n")
;
} else {
$compiler
->outdent()
->write("];\n")
;
}
$compiler
->outdent()
->write(");\n")
->outdent()
->subcompile($this->getNode('constructor_end'))
->write("}\n\n")
@@ -276,7 +281,7 @@ class Twig_Node_Module extends Twig_Node
protected function compileDisplay(Twig_Compiler $compiler)
{
$compiler
->write("protected function doDisplay(array \$context, array \$blocks = array())\n", "{\n")
->write("protected function doDisplay(array \$context, array \$blocks = [])\n", "{\n")
->indent()
->subcompile($this->getNode('display_start'))
->subcompile($this->getNode('body'))
+2 -2
View File
@@ -74,7 +74,7 @@ class Twig_Node_Set extends Twig_Node
$compiler->raw(' = ');
if (count($this->getNode('names')) > 1) {
$compiler->write('array(');
$compiler->write('[');
foreach ($this->getNode('values') as $idx => $value) {
if ($idx) {
$compiler->raw(', ');
@@ -82,7 +82,7 @@ class Twig_Node_Set extends Twig_Node
$compiler->subcompile($value);
}
$compiler->raw(')');
$compiler->raw(']');
} else {
if ($this->getAttribute('safe')) {
$compiler
@@ -31,7 +31,7 @@ class Twig_Tests_Node_Expression_ArrayTest extends Twig_Test_NodeTestCase
$node = new Twig_Node_Expression_Array($elements, 1);
return array(
array($node, 'array("foo" => "bar", "bar" => "foo")'),
array($node, '["foo" => "bar", "bar" => "foo"]'),
);
}
}
@@ -34,16 +34,16 @@ class Twig_Tests_Node_Expression_GetAttrTest extends Twig_Test_NodeTestCase
$attr = new Twig_Node_Expression_Constant('bar', 1);
$args = new Twig_Node_Expression_Array(array(), 1);
$node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_Template::ANY_CALL, 1);
$tests[] = array($node, sprintf('%s%s, "bar", array())', $this->getAttributeGetter(), $this->getVariableGetter('foo', 1)));
$tests[] = array($node, sprintf('%s%s, "bar", [])', $this->getAttributeGetter(), $this->getVariableGetter('foo', 1)));
$node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_Template::ARRAY_CALL, 1);
$tests[] = array($node, sprintf('%s%s, "bar", array(), "array")', $this->getAttributeGetter(), $this->getVariableGetter('foo', 1)));
$tests[] = array($node, sprintf('%s%s, "bar", [], "array")', $this->getAttributeGetter(), $this->getVariableGetter('foo', 1)));
$args = new Twig_Node_Expression_Array(array(), 1);
$args->addElement(new Twig_Node_Expression_Name('foo', 1));
$args->addElement(new Twig_Node_Expression_Constant('bar', 1));
$node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_Template::METHOD_CALL, 1);
$tests[] = array($node, sprintf('%s%s, "bar", array(0 => %s, 1 => "bar"), "method")', $this->getAttributeGetter(), $this->getVariableGetter('foo', 1), $this->getVariableGetter('foo')));
$tests[] = array($node, sprintf('%s%s, "bar", [0 => %s, 1 => "bar"], "method")', $this->getAttributeGetter(), $this->getVariableGetter('foo', 1), $this->getVariableGetter('foo')));
return $tests;
}
+3 -3
View File
@@ -56,14 +56,14 @@ EOF
$node = new Twig_Node_Include($expr, $vars, false, false, 1);
$tests[] = array($node, <<<EOF
// line 1
\$this->loadTemplate("foo.twig", null, 1)->display(array_merge(\$context, array("foo" => true)));
\$this->loadTemplate("foo.twig", null, 1)->display(array_merge(\$context, ["foo" => true]));
EOF
);
$node = new Twig_Node_Include($expr, $vars, true, false, 1);
$tests[] = array($node, <<<EOF
// line 1
\$this->loadTemplate("foo.twig", null, 1)->display(array("foo" => true));
\$this->loadTemplate("foo.twig", null, 1)->display(["foo" => true]);
EOF
);
@@ -71,7 +71,7 @@ EOF
$tests[] = array($node, <<<EOF
// line 1
try {
\$this->loadTemplate("foo.twig", null, 1)->display(array("foo" => true));
\$this->loadTemplate("foo.twig", null, 1)->display(["foo" => true]);
} catch (Twig_Error_Loader \$e) {
// ignore missing template
}
+7 -7
View File
@@ -54,11 +54,11 @@ class __TwigTemplate_e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b785
\$this->parent = false;
\$this->blocks = array(
);
\$this->blocks = [
];
}
protected function doDisplay(array \$context, array \$blocks = array())
protected function doDisplay(array \$context, array \$blocks = [])
{
// line 1
echo "foo";
@@ -95,8 +95,8 @@ class __TwigTemplate_e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b785
// line 1
\$this->parent = \$this->loadTemplate("layout.twig", "foo.twig", 1);
\$this->blocks = array(
);
\$this->blocks = [
];
}
protected function doGetParent(array \$context)
@@ -104,7 +104,7 @@ class __TwigTemplate_e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b785
return "layout.twig";
}
protected function doDisplay(array \$context, array \$blocks = array())
protected function doDisplay(array \$context, array \$blocks = [])
{
// line 2
\$context["macro"] = \$this->loadTemplate("foo.twig", "foo.twig", 2);
@@ -152,7 +152,7 @@ class __TwigTemplate_e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b785
return \$this->loadTemplate(((true) ? ("foo") : ("foo")), "foo.twig", 2);
}
protected function doDisplay(array \$context, array \$blocks = array())
protected function doDisplay(array \$context, array \$blocks = [])
{
// line 4
\$context["foo"] = "foo";
+1 -1
View File
@@ -60,7 +60,7 @@ EOF
$node = new Twig_Node_Set(false, $names, $values, 1);
$tests[] = array($node, <<<EOF
// line 1
list(\$context["foo"], \$context["bar"]) = array("foo", {$this->getVariableGetter('bar')});
list(\$context["foo"], \$context["bar"]) = ["foo", {$this->getVariableGetter('bar')}];
EOF
);