leilukin-tumbleblog/includes/lib/Twig/Node/Expression/TestExpression.php

40 lines
1023 B
PHP
Raw Permalink Normal View History

2024-06-20 14:10:42 +00:00
<?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;
use Twig\Node\Node;
class TestExpression extends CallExpression
{
public function __construct(Node $node, string $name, ?Node $arguments, int $lineno)
{
$nodes = ['node' => $node];
if (null !== $arguments) {
$nodes['arguments'] = $arguments;
}
2024-09-05 17:51:48 +00:00
parent::__construct($nodes, ['name' => $name, 'type' => 'test'], $lineno);
2024-06-20 14:10:42 +00:00
}
public function compile(Compiler $compiler): void
{
2024-09-05 17:51:48 +00:00
$test = $compiler->getEnvironment()->getTest($this->getAttribute('name'));
2024-06-20 14:10:42 +00:00
$this->setAttribute('arguments', $test->getArguments());
$this->setAttribute('callable', $test->getCallable());
$this->setAttribute('is_variadic', $test->isVariadic());
$this->compileCallable($compiler);
}
}