mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-12 10:26:32 +00:00
fixed variadic support
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
* 2.7.3 (2019-XX-XX)
|
||||
|
||||
* fixed variadic support
|
||||
* fixed CheckToStringNode implementation (broken when a function/filter is variadic)
|
||||
|
||||
* 2.7.3 (2019-03-21)
|
||||
|
||||
@@ -146,7 +146,7 @@ abstract class CallExpression extends AbstractExpression
|
||||
throw new \LogicException($message);
|
||||
}
|
||||
|
||||
$callableParameters = $this->getCallableParameters($callable, $isVariadic);
|
||||
list($callableParameters, $isPhpVariadic) = $this->getCallableParameters($callable, $isVariadic);
|
||||
$arguments = [];
|
||||
$names = [];
|
||||
$missingArguments = [];
|
||||
@@ -191,7 +191,7 @@ abstract class CallExpression extends AbstractExpression
|
||||
}
|
||||
|
||||
if ($isVariadic) {
|
||||
$arbitraryArguments = new ArrayExpression([], -1);
|
||||
$arbitraryArguments = $isPhpVariadic ? new VariadicExpression([], -1) : new ArrayExpression([], -1);
|
||||
foreach ($parameters as $key => $value) {
|
||||
if (\is_int($key)) {
|
||||
$arbitraryArguments->addElement($value);
|
||||
@@ -234,7 +234,7 @@ abstract class CallExpression extends AbstractExpression
|
||||
{
|
||||
list($r) = $this->reflectCallable($callable);
|
||||
if (null === $r) {
|
||||
return [];
|
||||
return [[], false];
|
||||
}
|
||||
|
||||
$parameters = $r->getParameters();
|
||||
@@ -252,10 +252,14 @@ abstract class CallExpression extends AbstractExpression
|
||||
array_shift($parameters);
|
||||
}
|
||||
}
|
||||
$isPhpVariadic = false;
|
||||
if ($isVariadic) {
|
||||
$argument = end($parameters);
|
||||
if ($argument && $argument->isArray() && $argument->isDefaultValueAvailable() && [] === $argument->getDefaultValue()) {
|
||||
array_pop($parameters);
|
||||
} else if ($argument && $argument->isVariadic()) {
|
||||
array_pop($parameters);
|
||||
$isPhpVariadic = true;
|
||||
} else {
|
||||
$callableName = $r->name;
|
||||
if ($r instanceof \ReflectionMethod) {
|
||||
@@ -266,7 +270,7 @@ abstract class CallExpression extends AbstractExpression
|
||||
}
|
||||
}
|
||||
|
||||
return $parameters;
|
||||
return [$parameters, $isPhpVariadic];
|
||||
}
|
||||
|
||||
private function reflectCallable($callable)
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Twig\Node\Expression;
|
||||
|
||||
use Twig\Compiler;
|
||||
|
||||
class VariadicExpression extends ArrayExpression
|
||||
{
|
||||
public function compile(Compiler $compiler)
|
||||
{
|
||||
$compiler->raw('...');
|
||||
|
||||
parent::compile($compiler);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user