mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-16 12:26:30 +00:00
aed4990615a0664de71135ba1884588490b4fd34
This PR was merged into the 3.x branch.
Discussion
----------
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.
Closes #3872 (it replaces it)
Relates to #3681 (it solves the case of getting the list of cases)
Note that the strict compile time validation for string literals is especially beneficial as long as escaping `\` is mandatory in our string literals (where escaping non-special characters is the same than not putting the backslash) as by experience, this is a common mistake when trying to put a PHP FQCN in a Twig string. One of the tests I added is covering exactly this kind of mistake.
Commits
-------
ff4d01f9 Implement the enum_cases function
…
Twig, the flexible, fast, and secure template language for PHP
==============================================================
Twig is a template language for PHP.
Twig uses a syntax similar to the Django and Jinja template languages which
inspired the Twig runtime environment.
Sponsors
--------
.. raw:: html
<a href="https://docs.blackfire.io/introduction?utm_source=twig&utm_medium=github_readme&utm_campaign=logo">
<img src="https://static.blackfire.io/assets/intemporals/logo/png/blackfire-io_secondary_horizontal_transparent.png?1" width="255px" alt="Blackfire.io">
</a>
More Information
----------------
Read the `documentation`_ for more information.
.. _documentation: https://twig.symfony.com/documentation
Description
Languages
PHP
99.9%