mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-31 04:27:00 +00:00
Support two words test guard
This commit is contained in:
committed by
Fabien Potencier
parent
8832f6327c
commit
30977bdea9
@@ -1,6 +1,6 @@
|
||||
# 3.21.2 (2025-XX-XX)
|
||||
# 3.22.0 (2025-XX-XX)
|
||||
|
||||
* n/a
|
||||
* Add support for two words test in guard tag
|
||||
|
||||
# 3.21.1 (2025-05-03)
|
||||
|
||||
|
||||
@@ -32,9 +32,15 @@ final class GuardTokenParser extends AbstractTokenParser
|
||||
$method = 'get'.$typeToken->getValue();
|
||||
|
||||
$nameToken = $stream->expect(Token::NAME_TYPE);
|
||||
$name = $nameToken->getValue();
|
||||
if ('test' === $typeToken->getValue() && $stream->test(Token::NAME_TYPE)) {
|
||||
// try 2-words tests
|
||||
$name .= ' '.$stream->getCurrent()->getValue();
|
||||
$stream->next();
|
||||
}
|
||||
|
||||
try {
|
||||
$exists = null !== $this->parser->getEnvironment()->$method($nameToken->getValue());
|
||||
$exists = null !== $this->parser->getEnvironment()->$method($name);
|
||||
} catch (SyntaxError) {
|
||||
$exists = false;
|
||||
}
|
||||
|
||||
@@ -13,9 +13,26 @@
|
||||
{% else %}
|
||||
NEVER
|
||||
{% endguard %}
|
||||
|
||||
{% guard test foobar %}
|
||||
NEVER
|
||||
{{ 'a'|foobar }}
|
||||
{% else -%}
|
||||
The foobar test doesn't exist
|
||||
{% endguard %}
|
||||
|
||||
{% guard test divisible by -%}
|
||||
The divisible by function does exist
|
||||
{% else %}
|
||||
NEVER
|
||||
{% endguard %}
|
||||
--DATA--
|
||||
return []
|
||||
--EXPECT--
|
||||
The foobar filter doesn't exist
|
||||
|
||||
The constant function does exist
|
||||
|
||||
The foobar test doesn't exist
|
||||
|
||||
The divisible by function does exist
|
||||
|
||||
Reference in New Issue
Block a user