Skip to content

Commit ec3d995

Browse files
committed
Minor tweaks
1 parent 1d8ebd3 commit ec3d995

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

reference/constraints/When.rst

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -176,16 +176,13 @@ Options
176176

177177
**type**: ``string|Closure``
178178

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.
183184

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:
189186

190187
``this``
191188
The object being validated (e.g. an instance of Discount).
@@ -201,16 +198,13 @@ in your expression:
201198

202199
The ``context`` variable in expressions was introduced in Symfony 7.2.
203200

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.
205202

206203
.. versionadded:: 7.3
207204

208205
The support for closure in the ``expression`` option was introduced in Symfony 7.3
209206
and requires PHP 8.5.
210207

211-
The ``value`` variable can be used when you want to execute more complex
212-
validation based on its value:
213-
214208
.. configuration-block::
215209

216210
.. code-block:: php-attributes
@@ -228,6 +222,7 @@ validation based on its value:
228222
expression: 'value == "percent"',
229223
constraints: [new Assert\Callback('doComplexValidation')],
230224
)]
225+
231226
// ... or using a closure
232227
#[Assert\When(
233228
expression: static function (Discount $discount) {

0 commit comments

Comments
 (0)