@@ -86,7 +86,14 @@ configure the locations of these files::
86
86
The AnnotationLoader
87
87
--------------------
88
88
89
- At last, the component provides an
89
+ .. deprecated :: 6.4
90
+
91
+ The :class: `Symfony\\ Component\\ Validator\\ Mapping\\ Loader\\ AnnotationLoader `
92
+ is deprecated since Symfony 6.4, use the
93
+ :class: `Symfony\\ Component\\ Validator\\ Mapping\\ Loader\\ AttributeLoader `
94
+ instead.
95
+
96
+ The component provides an
90
97
:class: `Symfony\\ Component\\ Validator\\ Mapping\\ Loader\\ AnnotationLoader ` to get
91
98
the metadata from the annotations of the class. Annotations are defined as ``@ ``
92
99
prefixed classes included in doc block comments (``/** ... */ ``). For example::
@@ -121,8 +128,44 @@ If you use annotations instead of attributes, it's also required to call
121
128
To disable the annotation loader after it was enabled, call
122
129
:method: `Symfony\\ Component\\ Validator\\ ValidatorBuilder::disableAnnotationMapping `.
123
130
131
+ .. deprecated :: 6.4
132
+
133
+ The :method: `Symfony\\ Component\\ Validator\\ ValidatorBuilder::enableAnnotationMapping `
134
+ and :method: `Symfony\\ Component\\ Validator\\ ValidatorBuilder::disableAnnotationMapping `
135
+ methods are deprecated since Symfony 6.4, use the
136
+ :method: `Symfony\\ Component\\ Validator\\ ValidatorBuilder::enableAttributeMapping `
137
+ and :method: `Symfony\\ Component\\ Validator\\ ValidatorBuilder::disableAttributeMapping `
138
+ methods instead.
139
+
124
140
.. include :: /_includes/_annotation_loader_tip.rst.inc
125
141
142
+ The AttributeLoader
143
+ -------------------
144
+
145
+ .. versionadded :: 6.4
146
+
147
+ The :class: `Symfony\\ Component\\ Validator\\ Mapping\\ Loader\\ AttributeLoader `
148
+ was introduced in Symfony 6.4.
149
+
150
+ The component provides an
151
+ :class: `Symfony\\ Component\\ Validator\\ Mapping\\ Loader\\ AttributeLoader ` to get
152
+ the metadata from the attributes of the class. For example::
153
+
154
+ use Symfony\Component\Validator\Constraints as Assert;
155
+ // ...
156
+
157
+ class User
158
+ {
159
+ #[Assert\NotBlank]
160
+ protected string $name;
161
+ }
162
+
163
+ To enable the attribute loader, call the
164
+ :method: `Symfony\\ Component\\ Validator\\ ValidatorBuilder::enableAttributeMapping ` method.
165
+
166
+ To disable the annotation loader after it was enabled, call
167
+ :method: `Symfony\\ Component\\ Validator\\ ValidatorBuilder::disableAttributeMapping `.
168
+
126
169
Using Multiple Loaders
127
170
----------------------
128
171
@@ -136,8 +179,7 @@ multiple mappings::
136
179
use Symfony\Component\Validator\Validation;
137
180
138
181
$validator = Validation::createValidatorBuilder()
139
- ->enableAnnotationMapping(true)
140
- ->addDefaultDoctrineAnnotationReader()
182
+ ->enableAttributeMapping()
141
183
->addMethodMapping('loadValidatorMetadata')
142
184
->addXmlMapping('validator/validation.xml')
143
185
->getValidator();
0 commit comments