mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-31 12:37:15 +00:00
Move static attributes for Function|Filter|TestExpression to the constructor
This commit is contained in:
@@ -19,12 +19,16 @@ class FilterExpression extends CallExpression
|
||||
{
|
||||
public function __construct(Node $node, ConstantExpression $filterName, Node $arguments, int $lineno, ?string $tag = null)
|
||||
{
|
||||
parent::__construct(['node' => $node, 'filter' => $filterName, 'arguments' => $arguments], [], $lineno, $tag);
|
||||
parent::__construct(['node' => $node, 'filter' => $filterName, 'arguments' => $arguments], ['name' => $filterName->getAttribute('value'), 'type' => 'filter'], $lineno, $tag);
|
||||
}
|
||||
|
||||
public function compile(Compiler $compiler): void
|
||||
{
|
||||
$name = $this->getNode('filter')->getAttribute('value');
|
||||
if ($name !== $this->getAttribute('name')) {
|
||||
trigger_deprecation('twig/twig', '3.11', 'Changing the value of a "filter" node in a NodeVisitor class is not supported anymore.');
|
||||
$this->setAttribute('name', $name);
|
||||
}
|
||||
if ('raw' === $name) {
|
||||
trigger_deprecation('twig/twig', '3.11', 'Creating the "raw" filter via "FilterExpression" is deprecated; use "RawFilter" instead.');
|
||||
|
||||
@@ -34,8 +38,6 @@ class FilterExpression extends CallExpression
|
||||
}
|
||||
$filter = $compiler->getEnvironment()->getFilter($name);
|
||||
|
||||
$this->setAttribute('name', $name);
|
||||
$this->setAttribute('type', 'filter');
|
||||
$this->setAttribute('needs_charset', $filter->needsCharset());
|
||||
$this->setAttribute('needs_environment', $filter->needsEnvironment());
|
||||
$this->setAttribute('needs_context', $filter->needsContext());
|
||||
|
||||
@@ -19,7 +19,7 @@ class FunctionExpression extends CallExpression
|
||||
{
|
||||
public function __construct(string $name, Node $arguments, int $lineno)
|
||||
{
|
||||
parent::__construct(['arguments' => $arguments], ['name' => $name, 'is_defined_test' => false], $lineno);
|
||||
parent::__construct(['arguments' => $arguments], ['name' => $name, 'type' => 'function', 'is_defined_test' => false], $lineno);
|
||||
}
|
||||
|
||||
public function compile(Compiler $compiler)
|
||||
@@ -27,8 +27,6 @@ class FunctionExpression extends CallExpression
|
||||
$name = $this->getAttribute('name');
|
||||
$function = $compiler->getEnvironment()->getFunction($name);
|
||||
|
||||
$this->setAttribute('name', $name);
|
||||
$this->setAttribute('type', 'function');
|
||||
$this->setAttribute('needs_charset', $function->needsCharset());
|
||||
$this->setAttribute('needs_environment', $function->needsEnvironment());
|
||||
$this->setAttribute('needs_context', $function->needsContext());
|
||||
|
||||
@@ -23,16 +23,13 @@ class TestExpression extends CallExpression
|
||||
$nodes['arguments'] = $arguments;
|
||||
}
|
||||
|
||||
parent::__construct($nodes, ['name' => $name], $lineno);
|
||||
parent::__construct($nodes, ['name' => $name, 'type' => 'test'], $lineno);
|
||||
}
|
||||
|
||||
public function compile(Compiler $compiler): void
|
||||
{
|
||||
$name = $this->getAttribute('name');
|
||||
$test = $compiler->getEnvironment()->getTest($name);
|
||||
$test = $compiler->getEnvironment()->getTest($this->getAttribute('name'));
|
||||
|
||||
$this->setAttribute('name', $name);
|
||||
$this->setAttribute('type', 'test');
|
||||
$this->setAttribute('arguments', $test->getArguments());
|
||||
$this->setAttribute('callable', $test->getCallable());
|
||||
$this->setAttribute('is_variadic', $test->isVariadic());
|
||||
|
||||
Reference in New Issue
Block a user