Skip to content

Commit 1ac5815

Browse files
[ExpressionLanguage] Add enum expression function
1 parent 7a79bc7 commit 1ac5815

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

components/expression_language/syntax.rst

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,16 @@ Working with Functions
127127
----------------------
128128

129129
You can also use registered functions in the expression by using the same
130-
syntax as PHP and JavaScript. The ExpressionLanguage component comes with one
131-
function by default: ``constant()``, which will return the value of the PHP
132-
constant::
130+
syntax as PHP and JavaScript. The ExpressionLanguage component comes with the
131+
following functions by default:
132+
133+
* ``constant()``
134+
* ``enum()``
135+
136+
Constant function
137+
~~~~~~~~~~~~~~~~~
138+
139+
This function will return the value of the PHP constant::
133140

134141
define('DB_USER', 'root');
135142

@@ -139,6 +146,26 @@ constant::
139146

140147
This will print out ``root``.
141148

149+
Enum function
150+
~~~~~~~~~~~~~
151+
152+
This function will return the case of an enumeration::
153+
154+
enum Foo
155+
{
156+
case Bar;
157+
}
158+
159+
var_dump(App\Enum\Foo::Bar === $expressionLanguage->evaluate(
160+
'enum("App\\\Enum\\\Foo::Bar")'
161+
));
162+
163+
This will print out ``true``.
164+
165+
.. versionadded:: 6.3
166+
167+
The ``enum()`` function was introduced in Symfony 6.3.
168+
142169
.. tip::
143170

144171
To read how to register your own functions to use in an expression, see

0 commit comments

Comments
 (0)