leilukin-tumbleblog/includes/lib/Twig/TwigTest.php

68 lines
1.5 KiB
PHP
Raw 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;
use Twig\Node\Expression\TestExpression;
/**
* Represents a template test.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @see https://twig.symfony.com/doc/templates.html#test-operator
*/
2025-01-13 09:56:01 +00:00
final class TwigTest extends AbstractTwigCallable
2024-06-20 14:10:42 +00:00
{
/**
* @param callable|array{class-string, string}|null $callable A callable implementing the test. If null, you need to overwrite the "node_class" option to customize compilation.
*/
public function __construct(string $name, $callable = null, array $options = [])
{
2025-01-13 09:56:01 +00:00
parent::__construct($name, $callable, $options);
2024-06-20 14:10:42 +00:00
$this->options = array_merge([
'node_class' => TestExpression::class,
'one_mandatory_argument' => false,
2025-01-13 09:56:01 +00:00
], $this->options);
2024-06-20 14:10:42 +00:00
}
2025-01-13 09:56:01 +00:00
public function getType(): string
2024-06-20 14:10:42 +00:00
{
2025-01-13 09:56:01 +00:00
return 'test';
2024-06-20 14:10:42 +00:00
}
2025-01-13 09:56:01 +00:00
public function needsCharset(): bool
2024-06-20 14:10:42 +00:00
{
2025-01-13 09:56:01 +00:00
return false;
2024-06-20 14:10:42 +00:00
}
2025-01-13 09:56:01 +00:00
public function needsEnvironment(): bool
2024-06-20 14:10:42 +00:00
{
2025-01-13 09:56:01 +00:00
return false;
2024-06-20 14:10:42 +00:00
}
2025-01-13 09:56:01 +00:00
public function needsContext(): bool
2024-06-20 14:10:42 +00:00
{
2025-01-13 09:56:01 +00:00
return false;
2024-06-20 14:10:42 +00:00
}
2025-01-13 09:56:01 +00:00
public function hasOneMandatoryArgument(): bool
2024-06-20 14:10:42 +00:00
{
2025-01-13 09:56:01 +00:00
return (bool) $this->options['one_mandatory_argument'];
2024-06-20 14:10:42 +00:00
}
2025-01-13 09:56:01 +00:00
public function getMinimalNumberOfRequiredArguments(): int
2024-06-20 14:10:42 +00:00
{
2025-01-13 09:56:01 +00:00
return parent::getMinimalNumberOfRequiredArguments() + 1;
2024-06-20 14:10:42 +00:00
}
}