File tree Expand file tree Collapse file tree 1 file changed +40
-3
lines changed
components/expression_language Expand file tree Collapse file tree 1 file changed +40
-3
lines changed Original file line number Diff line number Diff line change @@ -127,18 +127,55 @@ Working with Functions
127
127
----------------------
128
128
129
129
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 a PHP constant::
133
140
134
141
define('DB_USER', 'root');
135
142
136
143
var_dump($expressionLanguage->evaluate(
137
144
'constant("DB_USER")'
138
145
));
139
146
147
+ // This also works with class constants
148
+ class Foo
149
+ {
150
+ public const DB_USER = 'root';
151
+ }
152
+
153
+ var_dump($expressionLanguage->evaluate(
154
+ 'constant("App\\\SomeNamespace\\\Foo::DB_USER")'
155
+ ));
156
+
140
157
This will print out ``root ``.
141
158
159
+ Enum function
160
+ ~~~~~~~~~~~~~
161
+
162
+ This function will return the case of an enumeration::
163
+
164
+ enum Foo
165
+ {
166
+ case Bar;
167
+ }
168
+
169
+ var_dump(App\Enum\Foo::Bar === $expressionLanguage->evaluate(
170
+ 'enum("App\\\Enum\\\Foo::Bar")'
171
+ ));
172
+
173
+ This will print out ``true ``.
174
+
175
+ .. versionadded :: 6.3
176
+
177
+ The ``enum() `` function was introduced in Symfony 6.3.
178
+
142
179
.. tip ::
143
180
144
181
To read how to register your own functions to use in an expression, see
You can’t perform that action at this time.
0 commit comments