Files
Christophe Coevoet ff4d01f940 Implement the enum_cases function
The implementation contains an optimized implementation of the function
for the common case of using a string literal as the argument. It will
validate the enum existence during compilation and compile the code to
use `MyEnum::cases()` directly.
2024-08-09 21:21:58 +02:00

25 lines
463 B
Plaintext

--TEST--
"enum_cases" function
--CONDITION--
\PHP_VERSION_ID >= 80100
--TEMPLATE--
{% for c in enum_cases('Twig\\Tests\\DummyBackedEnum') %}
{{~ c.name }}: {{ c.value }}
{% endfor %}
{% for c in enum_cases('Twig\\Tests\\DummyUnitEnum') %}
{{~ c.name }}
{% endfor %}
{% set from_variable='Twig\\Tests\\DummyUnitEnum' %}
{% for c in enum_cases(from_variable) %}
{{~ c.name }}
{% endfor %}
--DATA--
return []
--EXPECT--
FOO: foo
BAR: bar
BAR
BAZ
BAR
BAZ