@@ -176,16 +176,13 @@ Options
176
176
177
177
**type **: ``string|Closure ``
178
178
179
- The condition as a closure or written with the expression language syntax
180
- that will be evaluated. If the closure return value or the evaluated expression
181
- is a falsey value (i.e. using ``== ``, not ``=== ``), validation of constraints won't
182
- be triggered, and constraints of the ``otherwise `` option will, if provided.
179
+ The condition evaluated to decide if the constraint is applied or not. It can be
180
+ defined as a closure or a string using the :doc: `expression language syntax </reference/formats/expression_language >`.
181
+ If the result is a falsey value (``false ``, ``null ``, ``0 ``, an empty string or
182
+ an empty array) the constraints defined in the ``constraints `` option won't be
183
+ applied but the constraints defined in ``otherwise `` option (if provided) will be applied.
183
184
184
- To learn more about the expression language syntax, see
185
- :doc: `/reference/formats/expression_language `.
186
-
187
- Depending on how you use the constraint, you have access to different variables
188
- in your expression:
185
+ **When using an expression **, you access to the following variables:
189
186
190
187
``this ``
191
188
The object being validated (e.g. an instance of Discount).
@@ -201,16 +198,13 @@ in your expression:
201
198
202
199
The ``context `` variable in expressions was introduced in Symfony 7.2.
203
200
204
- When using a closure, the first argument is the object being validated.
201
+ ** When using a closure ** , the first argument is the object being validated.
205
202
206
203
.. versionadded :: 7.3
207
204
208
205
The support for closure in the ``expression `` option was introduced in Symfony 7.3
209
206
and requires PHP 8.5.
210
207
211
- The ``value `` variable can be used when you want to execute more complex
212
- validation based on its value:
213
-
214
208
.. configuration-block ::
215
209
216
210
.. code-block :: php-attributes
@@ -228,6 +222,7 @@ validation based on its value:
228
222
expression: 'value == "percent"',
229
223
constraints: [new Assert\Callback('doComplexValidation')],
230
224
)]
225
+
231
226
// ... or using a closure
232
227
#[Assert\When(
233
228
expression: static function (Discount $discount) {
0 commit comments