@@ -47,6 +47,33 @@ username and the password are different only if all other validation passes
4747 }
4848 }
4949
50+ .. code-block :: php-attributes
51+
52+ // src/Entity/User.php
53+ namespace App\Entity;
54+
55+ use Symfony\Component\Security\Core\User\UserInterface;
56+ use Symfony\Component\Validator\Constraints as Assert;
57+
58+ #[Assert\GroupSequence(['User', 'Strict'])]
59+ class User implements UserInterface
60+ {
61+ #[Assert\NotBlank]
62+ private $username;
63+
64+ #[Assert\NotBlank]
65+ private $password;
66+
67+ #[Assert\IsTrue(
68+ message: 'The password cannot match your username',
69+ groups: ['Strict'],
70+ )]
71+ public function isPasswordSafe()
72+ {
73+ return ($this->username !== $this->password);
74+ }
75+ }
76+
5077 .. code-block :: yaml
5178
5279 # config/validator/validation.yaml
@@ -151,7 +178,7 @@ You can also define a group sequence in the ``validation_groups`` form option::
151178
152179 // src/Form/MyType.php
153180 namespace App\Form;
154-
181+
155182 use Symfony\Component\Form\AbstractType;
156183 use Symfony\Component\OptionsResolver\OptionsResolver;
157184 use Symfony\Component\Validator\Constraints\GroupSequence;
@@ -204,6 +231,27 @@ entity and a new constraint group called ``Premium``:
204231 // ...
205232 }
206233
234+ .. code-block :: php-attributes
235+
236+ // src/Entity/User.php
237+ namespace App\Entity;
238+
239+ use Symfony\Component\Validator\Constraints as Assert;
240+
241+ class User
242+ {
243+ #[Assert\NotBlank]
244+ private $name;
245+
246+ #[Assert\CardScheme(
247+ schemes: [Assert\CardScheme::VISA],
248+ groups: ['Premium'],
249+ )]
250+ private $creditCard;
251+
252+ // ...
253+ }
254+
207255 .. code-block :: yaml
208256
209257 # config/validator/validation.yaml
@@ -263,7 +311,7 @@ entity and a new constraint group called ``Premium``:
263311 {
264312 $metadata->addPropertyConstraint('name', new Assert\NotBlank());
265313 $metadata->addPropertyConstraint('creditCard', new Assert\CardScheme([
266- 'schemes' => [' VISA' ],
314+ 'schemes' => [Assert\CardScheme:: VISA],
267315 'groups' => ['Premium'],
268316 ]));
269317 }
@@ -319,6 +367,19 @@ provides a sequence of groups to be validated:
319367 // ...
320368 }
321369
370+ .. code-block :: php-attributes
371+
372+ // src/Entity/User.php
373+ namespace App\Entity;
374+
375+ // ...
376+
377+ #[Assert\GroupSequenceProvider]
378+ class User implements GroupSequenceProviderInterface
379+ {
380+ // ...
381+ }
382+
322383 .. code-block :: yaml
323384
324385 # config/validator/validation.yaml
0 commit comments