File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -102,6 +102,50 @@ You can now use it anywhere you need it:
102
102
}
103
103
}
104
104
105
+ Validation groups and payload can be passed via constructor:
106
+
107
+ .. configuration-block ::
108
+
109
+ .. code-block :: php-attributes
110
+
111
+ // src/Entity/User.php
112
+ namespace App\Entity\User;
113
+
114
+ use App\Validator\Constraints as Assert;
115
+
116
+ class User
117
+ {
118
+ #[Assert\PasswordRequirements(
119
+ groups: ['registration'],
120
+ payload: ['severity' => 'error'],
121
+ )]
122
+ public string $plainPassword;
123
+ }
124
+
125
+ .. code-block :: php
126
+
127
+ // src/Entity/User.php
128
+ namespace App\Entity\User;
129
+
130
+ use App\Validator\Constraints as Assert;
131
+ use Symfony\Component\Validator\Mapping\ClassMetadata;
132
+
133
+ class User
134
+ {
135
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
136
+ {
137
+ $metadata->addPropertyConstraint('plainPassword', new Assert\PasswordRequirements(
138
+ groups: ['registration'],
139
+ payload: ['severity' => 'error'],
140
+ ));
141
+ }
142
+ }
143
+
144
+ .. versionadded :: 7.2
145
+
146
+ Support for passing validation groups and the payload to the constructor
147
+ of the ``Compound `` class was introduced in Symfony 7.2.
148
+
105
149
Options
106
150
-------
107
151
You can’t perform that action at this time.
0 commit comments