mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-10 17:36:53 +00:00
fixed more short array notations
This commit is contained in:
@@ -26,7 +26,7 @@ class Twig_Node_Block extends Twig_Node
|
||||
{
|
||||
$compiler
|
||||
->addDebugInfo($this)
|
||||
->write(sprintf("public function block_%s(\$context, array \$blocks = array())\n", $this->getAttribute('name')), "{\n")
|
||||
->write(sprintf("public function block_%s(\$context, array \$blocks = [])\n", $this->getAttribute('name')), "{\n")
|
||||
->indent()
|
||||
;
|
||||
|
||||
|
||||
@@ -48,9 +48,9 @@ class Twig_Node_CheckSecurity extends Twig_Node
|
||||
->indent()
|
||||
->write("\$this->env->getExtension('Twig_Extension_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()
|
||||
|
||||
@@ -15,6 +15,7 @@ abstract class Twig_Node_Expression_Call extends Twig_Node_Expression
|
||||
protected function compileCallable(Twig_Compiler $compiler)
|
||||
{
|
||||
$closingParenthesis = false;
|
||||
$isArray = false;
|
||||
if ($this->hasAttribute('callable') && $callable = $this->getAttribute('callable')) {
|
||||
if (is_string($callable) && false === strpos($callable, '::')) {
|
||||
$compiler->raw($callable);
|
||||
@@ -30,24 +31,25 @@ abstract class Twig_Node_Expression_Call extends Twig_Node_Expression
|
||||
$compiler->raw(sprintf('$this->env->getExtension(\'%s\')->%s', get_class($callable[0]), $callable[1]));
|
||||
} else {
|
||||
$type = ucfirst($this->getAttribute('type'));
|
||||
$compiler->raw(sprintf('call_user_func_array($this->env->get%s(\'%s\')->getCallable(), array', $type, $this->getAttribute('name')));
|
||||
$compiler->raw(sprintf('call_user_func_array($this->env->get%s(\'%s\')->getCallable(), ', $type, $this->getAttribute('name')));
|
||||
$closingParenthesis = true;
|
||||
$isArray = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$compiler->raw($this->getAttribute('thing')->compile());
|
||||
}
|
||||
|
||||
$this->compileArguments($compiler);
|
||||
$this->compileArguments($compiler, $isArray);
|
||||
|
||||
if ($closingParenthesis) {
|
||||
$compiler->raw(')');
|
||||
}
|
||||
}
|
||||
|
||||
protected function compileArguments(Twig_Compiler $compiler)
|
||||
protected function compileArguments(Twig_Compiler $compiler, $isArray = false)
|
||||
{
|
||||
$compiler->raw('(');
|
||||
$compiler->raw($isArray ? '[' : '(');
|
||||
|
||||
$first = true;
|
||||
|
||||
@@ -96,7 +98,7 @@ abstract class Twig_Node_Expression_Call extends Twig_Node_Expression
|
||||
}
|
||||
}
|
||||
|
||||
$compiler->raw(')');
|
||||
$compiler->raw($isArray ? ']' : ')');
|
||||
}
|
||||
|
||||
protected function getArguments($callable, $arguments)
|
||||
@@ -248,7 +250,7 @@ abstract class Twig_Node_Expression_Call extends Twig_Node_Expression
|
||||
$callableName = $r->getDeclaringClass()->name.'::'.$callableName;
|
||||
}
|
||||
|
||||
throw new LogicException(sprintf('The last parameter of "%s" for %s "%s" must be an array with default value, eg. "array $arg = array()".', $callableName, $this->getAttribute('type'), $this->getAttribute('name')));
|
||||
throw new LogicException(sprintf('The last parameter of "%s" for %s "%s" must be an array with default value, eg. "array $arg = []".', $callableName, $this->getAttribute('type'), $this->getAttribute('name')));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ class Twig_Node_Expression_GetAttr extends Twig_Node_Expression
|
||||
if ($this->hasNode('arguments')) {
|
||||
$compiler->raw(', ')->subcompile($this->getNode('arguments'));
|
||||
} else {
|
||||
$compiler->raw(', array()');
|
||||
$compiler->raw(', []');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -51,12 +51,12 @@ class Twig_Node_For extends Twig_Node
|
||||
|
||||
if ($this->getAttribute('with_loop')) {
|
||||
$compiler
|
||||
->write("\$context['loop'] = array(\n")
|
||||
->write("\$context['loop'] = [\n")
|
||||
->write(" 'parent' => \$context['_parent'],\n")
|
||||
->write(" 'index0' => 0,\n")
|
||||
->write(" 'index' => 1,\n")
|
||||
->write(" 'first' => true,\n")
|
||||
->write(");\n")
|
||||
->write("];\n")
|
||||
;
|
||||
|
||||
if (!$this->getAttribute('ifexpr')) {
|
||||
|
||||
@@ -74,7 +74,7 @@ class Twig_Node_Include extends Twig_Node implements Twig_NodeOutputInterface
|
||||
protected function addTemplateArguments(Twig_Compiler $compiler)
|
||||
{
|
||||
if (!$this->hasNode('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, ')
|
||||
|
||||
@@ -64,7 +64,7 @@ class Twig_Node_Macro extends Twig_Node
|
||||
;
|
||||
|
||||
$compiler
|
||||
->write("\$context = \$this->env->mergeGlobals(array(\n")
|
||||
->write("\$context = \$this->env->mergeGlobals([\n")
|
||||
->indent()
|
||||
;
|
||||
|
||||
@@ -91,14 +91,14 @@ class Twig_Node_Macro extends Twig_Node
|
||||
->repr($count)
|
||||
->raw(' ? array_slice(func_get_args(), ')
|
||||
->repr($count)
|
||||
->raw(") : array(),\n")
|
||||
->raw(") : [],\n")
|
||||
;
|
||||
}
|
||||
|
||||
$compiler
|
||||
->outdent()
|
||||
->write("));\n\n")
|
||||
->write("\$blocks = array();\n\n")
|
||||
->write("]);\n\n")
|
||||
->write("\$blocks = [];\n\n")
|
||||
->write("ob_start();\n")
|
||||
->write("try {\n")
|
||||
->indent()
|
||||
|
||||
@@ -257,11 +257,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")
|
||||
;
|
||||
}
|
||||
|
||||
@@ -272,20 +272,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")
|
||||
@@ -295,7 +300,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'))
|
||||
|
||||
@@ -44,7 +44,7 @@ class Twig_Node_With extends Twig_Node
|
||||
;
|
||||
|
||||
if ($this->getAttribute('only')) {
|
||||
$compiler->write("\$context = array('_parent' => \$context);\n");
|
||||
$compiler->write("\$context = ['_parent' => \$context];\n");
|
||||
} else {
|
||||
$compiler->write("\$context['_parent'] = \$context;\n");
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ class Twig_Tests_Node_BlockTest extends Twig_Test_NodeTestCase
|
||||
return [
|
||||
[$node, <<<EOF
|
||||
// line 1
|
||||
public function block_foo(\$context, array \$blocks = array())
|
||||
public function block_foo(\$context, array \$blocks = [])
|
||||
{
|
||||
echo "foo";
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ class Twig_Tests_Node_Expression_CallTest extends \PHPUnit\Framework\TestCase
|
||||
|
||||
/**
|
||||
* @expectedException LogicException
|
||||
* @expectedExceptionMessage The last parameter of "Twig_Tests_Node_Expression_CallTest::customFunctionWithArbitraryArguments" for function "foo" must be an array with default value, eg. "array $arg = array()".
|
||||
* @expectedExceptionMessage The last parameter of "Twig_Tests_Node_Expression_CallTest::customFunctionWithArbitraryArguments" for function "foo" must be an array with default value, eg. "array $arg = []".
|
||||
*/
|
||||
public function testResolveArgumentsWithMissingParameterForArbitraryArguments()
|
||||
{
|
||||
@@ -104,7 +104,7 @@ class Twig_Tests_Node_Expression_CallTest extends \PHPUnit\Framework\TestCase
|
||||
|
||||
/**
|
||||
* @expectedException LogicException
|
||||
* @expectedExceptionMessageRegExp #^The last parameter of "custom_Twig_Tests_Node_Expression_CallTest_function" for function "foo" must be an array with default value, eg\. "array \$arg \= array\(\)"\.$#
|
||||
* @expectedExceptionMessageRegExp #^The last parameter of "custom_Twig_Tests_Node_Expression_CallTest_function" for function "foo" must be an array with default value, eg\. "array \$arg \= \[\]"\.$#
|
||||
*/
|
||||
public function testResolveArgumentsWithMissingParameterForArbitraryArgumentsOnFunction()
|
||||
{
|
||||
@@ -114,7 +114,7 @@ class Twig_Tests_Node_Expression_CallTest extends \PHPUnit\Framework\TestCase
|
||||
|
||||
/**
|
||||
* @expectedException LogicException
|
||||
* @expectedExceptionMessageRegExp #^The last parameter of "CallableTestClass\:\:__invoke" for function "foo" must be an array with default value, eg\. "array \$arg \= array\(\)"\.$#
|
||||
* @expectedExceptionMessageRegExp #^The last parameter of "CallableTestClass\:\:__invoke" for function "foo" must be an array with default value, eg\. "array \$arg \= \[\]"\.$#
|
||||
*/
|
||||
public function testResolveArgumentsWithMissingParameterForArbitraryArgumentsOnObject()
|
||||
{
|
||||
|
||||
@@ -70,7 +70,7 @@ class Twig_Tests_Node_Expression_FilterTest extends Twig_Test_NodeTestCase
|
||||
// filter as an anonymous function
|
||||
if (PHP_VERSION_ID >= 50300) {
|
||||
$node = $this->createFilter(new Twig_Node_Expression_Constant('foo', 1), 'anonymous');
|
||||
$tests[] = [$node, 'call_user_func_array($this->env->getFilter(\'anonymous\')->getCallable(), array("foo"))'];
|
||||
$tests[] = [$node, 'call_user_func_array($this->env->getFilter(\'anonymous\')->getCallable(), ["foo"])'];
|
||||
}
|
||||
|
||||
// needs environment
|
||||
|
||||
@@ -84,7 +84,7 @@ class Twig_Tests_Node_Expression_FunctionTest extends Twig_Test_NodeTestCase
|
||||
// function as an anonymous function
|
||||
if (PHP_VERSION_ID >= 50300) {
|
||||
$node = $this->createFunction('anonymous', [new Twig_Node_Expression_Constant('foo', 1)]);
|
||||
$tests[] = [$node, 'call_user_func_array($this->env->getFunction(\'anonymous\')->getCallable(), array("foo"))'];
|
||||
$tests[] = [$node, 'call_user_func_array($this->env->getFunction(\'anonymous\')->getCallable(), ["foo"])'];
|
||||
}
|
||||
|
||||
return $tests;
|
||||
|
||||
@@ -37,7 +37,7 @@ class Twig_Tests_Node_Expression_TestTest extends Twig_Test_NodeTestCase
|
||||
// test as an anonymous function
|
||||
if (PHP_VERSION_ID >= 50300) {
|
||||
$node = $this->createTest(new Twig_Node_Expression_Constant('foo', 1), 'anonymous', [new Twig_Node_Expression_Constant('foo', 1)]);
|
||||
$tests[] = [$node, 'call_user_func_array($this->env->getTest(\'anonymous\')->getCallable(), array("foo", "foo"))'];
|
||||
$tests[] = [$node, 'call_user_func_array($this->env->getTest(\'anonymous\')->getCallable(), ["foo", "foo"])'];
|
||||
}
|
||||
|
||||
// arbitrary named arguments
|
||||
|
||||
@@ -75,12 +75,12 @@ EOF
|
||||
// line 1
|
||||
\$context['_parent'] = \$context;
|
||||
\$context['_seq'] = twig_ensure_traversable({$this->getVariableGetter('values')});
|
||||
\$context['loop'] = array(
|
||||
\$context['loop'] = [
|
||||
'parent' => \$context['_parent'],
|
||||
'index0' => 0,
|
||||
'index' => 1,
|
||||
'first' => true,
|
||||
);
|
||||
];
|
||||
if (is_array(\$context['_seq']) || (is_object(\$context['_seq']) && \$context['_seq'] instanceof Countable)) {
|
||||
\$length = count(\$context['_seq']);
|
||||
\$context['loop']['revindex0'] = \$length - 1;
|
||||
@@ -118,12 +118,12 @@ EOF
|
||||
// line 1
|
||||
\$context['_parent'] = \$context;
|
||||
\$context['_seq'] = twig_ensure_traversable({$this->getVariableGetter('values')});
|
||||
\$context['loop'] = array(
|
||||
\$context['loop'] = [
|
||||
'parent' => \$context['_parent'],
|
||||
'index0' => 0,
|
||||
'index' => 1,
|
||||
'first' => true,
|
||||
);
|
||||
];
|
||||
foreach (\$context['_seq'] as \$context["k"] => \$context["v"]) {
|
||||
if (true) {
|
||||
echo {$this->getVariableGetter('foo')};
|
||||
@@ -152,12 +152,12 @@ EOF
|
||||
\$context['_parent'] = \$context;
|
||||
\$context['_seq'] = twig_ensure_traversable({$this->getVariableGetter('values')});
|
||||
\$context['_iterated'] = false;
|
||||
\$context['loop'] = array(
|
||||
\$context['loop'] = [
|
||||
'parent' => \$context['_parent'],
|
||||
'index0' => 0,
|
||||
'index' => 1,
|
||||
'first' => true,
|
||||
);
|
||||
];
|
||||
if (is_array(\$context['_seq']) || (is_object(\$context['_seq']) && \$context['_seq'] instanceof Countable)) {
|
||||
\$length = count(\$context['_seq']);
|
||||
\$context['loop']['revindex0'] = \$length - 1;
|
||||
|
||||
@@ -36,7 +36,7 @@ class Twig_Tests_Node_MacroTest extends Twig_Test_NodeTestCase
|
||||
$varargs = '$__varargs__';
|
||||
} else {
|
||||
$declaration = '';
|
||||
$varargs = 'func_num_args() > 2 ? array_slice(func_get_args(), 2) : array()';
|
||||
$varargs = 'func_num_args() > 2 ? array_slice(func_get_args(), 2) : []';
|
||||
}
|
||||
|
||||
return [
|
||||
@@ -44,13 +44,13 @@ class Twig_Tests_Node_MacroTest extends Twig_Test_NodeTestCase
|
||||
// line 1
|
||||
public function getfoo(\$__foo__ = null, \$__bar__ = "Foo"$declaration)
|
||||
{
|
||||
\$context = \$this->env->mergeGlobals(array(
|
||||
\$context = \$this->env->mergeGlobals([
|
||||
"foo" => \$__foo__,
|
||||
"bar" => \$__bar__,
|
||||
"varargs" => $varargs,
|
||||
));
|
||||
]);
|
||||
|
||||
\$blocks = array();
|
||||
\$blocks = [];
|
||||
|
||||
ob_start();
|
||||
try {
|
||||
|
||||
@@ -54,11 +54,11 @@ class __TwigTemplate_%x extends Twig_Template
|
||||
|
||||
\$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";
|
||||
@@ -108,8 +108,8 @@ class __TwigTemplate_%x extends Twig_Template
|
||||
|
||||
// line 1
|
||||
\$this->parent = \$this->loadTemplate("layout.twig", "foo.twig", 1);
|
||||
\$this->blocks = array(
|
||||
);
|
||||
\$this->blocks = [
|
||||
];
|
||||
}
|
||||
|
||||
protected function doGetParent(array \$context)
|
||||
@@ -117,7 +117,7 @@ class __TwigTemplate_%x extends Twig_Template
|
||||
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);
|
||||
@@ -179,7 +179,7 @@ class __TwigTemplate_%x extends Twig_Template
|
||||
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";
|
||||
|
||||
Reference in New Issue
Block a user