Update Twig to v2.15.4

This commit is contained in:
slawkens
2023-02-02 10:37:45 +01:00
parent e552bcfe82
commit 130f7ba405
309 changed files with 3802 additions and 4005 deletions

View File

@@ -11,30 +11,45 @@
namespace Twig;
use Twig\Node\Expression\TestExpression;
/**
* Represents a template test.
*
* @final
* @final since Twig 2.4.0
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @see https://twig.symfony.com/doc/templates.html#test-operator
*/
class TwigTest
{
protected $name;
protected $callable;
protected $options;
private $name;
private $callable;
private $options;
private $arguments = [];
public function __construct($name, $callable, array $options = [])
/**
* Creates a template test.
*
* @param string $name Name of this test
* @param callable|null $callable A callable implementing the test. If null, you need to overwrite the "node_class" option to customize compilation.
* @param array $options Options array
*/
public function __construct(string $name, $callable = null, array $options = [])
{
if (__CLASS__ !== static::class) {
@trigger_error('Overriding '.__CLASS__.' is deprecated since Twig 2.4.0 and the class will be final in 3.0.', \E_USER_DEPRECATED);
}
$this->name = $name;
$this->callable = $callable;
$this->options = array_merge([
'is_variadic' => false,
'node_class' => '\Twig\Node\Expression\TestExpression',
'node_class' => TestExpression::class,
'deprecated' => false,
'alternative' => null,
'one_mandatory_argument' => false,
], $options);
}
@@ -43,6 +58,11 @@ class TwigTest
return $this->name;
}
/**
* Returns the callable to execute for this test.
*
* @return callable|null
*/
public function getCallable()
{
return $this->callable;
@@ -53,6 +73,16 @@ class TwigTest
return $this->options['node_class'];
}
public function setArguments($arguments)
{
$this->arguments = $arguments;
}
public function getArguments()
{
return $this->arguments;
}
public function isVariadic()
{
return $this->options['is_variadic'];
@@ -73,15 +103,13 @@ class TwigTest
return $this->options['alternative'];
}
public function setArguments($arguments)
public function hasOneMandatoryArgument(): bool
{
$this->arguments = $arguments;
}
public function getArguments()
{
return $this->arguments;
return (bool) $this->options['one_mandatory_argument'];
}
}
class_alias('Twig\TwigTest', 'Twig_SimpleTest');
// For Twig 1.x compatibility
class_alias('Twig\TwigTest', 'Twig_SimpleTest', false);
class_alias('Twig\TwigTest', 'Twig_Test');