10000 GroupSequence class description with example extend · kzorluoglu/symfony@3a19f10 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3a19f10

Browse files
author
Koray Zorluoglu
committed
GroupSequence class description with example extend
1 parent 260168e commit 3a19f10

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/Symfony/Component/Validator/Constraints/GroupSequence.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,30 @@
1919
* previous groups in the sequence succeeded. This approach is beneficial for scenarios where certain validation
2020
* groups are more resource-intensive or rely on the success of prior validations.
2121
*
22-
* Group sequences can also be used to override the "Default" validation group for a class. When a class has an
23-
* associated group sequence and is validated in the "Default" group, the group sequence is applied instead.
22+
* For example, when validating an address:
23+
*
24+
* $validator->validate($address, null, new GroupSequence(['Basic', 'Strict']));
25+
*
26+
* In this case, all constraints in the "Basic" group are validated first. If none of the "Basic" constraints fail,
27+
* the "Strict" group constraints are then validated. This is useful if, for instance, the "Strict" group contains
28+
* more resource-intensive checks.
29+
*
30+
* Group sequences can also be used to override the "Default" validation group for a class:
31+
*
32+
* #[GroupSequence(['Address', 'Strict'])]
33+
* class Address
34+
* {
35+
* // ...
36+
* }
37+
*
38+
* When you validate the `Address` object in the "Default" group, the specified group sequence is applied:
39+
*
40+
* $validator->validate($address);
41+
*
42+
* To validate the constraints of the "Default" group for a class with an overridden default group,
43+
* pass the class name as the group name:
44+
*
45+
* $validator->validate($address, null, "Address")
2446
*
2547
* This feature allows for fine-grained control over the validation process, ensuring efficient and effective
2648
* validation flows.

0 commit comments

Comments
 (0)
0