@@ -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::
@@ -117,8 +124,44 @@ If you use annotations instead of attributes, it's also required to call
117
124
To disable the annotation loader after it was enabled, call
118
125
:method: `Symfony\\ Component\\ Validator\\ ValidatorBuilder::disableAnnotationMapping `.
119
126
127
+ .. deprecated :: 6.4
128
+
129
+ The :method: `Symfony\\ Component\\ Validator\\ ValidatorBuilder::enableAnnotationMapping `
130
+ and :method: `Symfony\\ Component\\ Validator\\ ValidatorBuilder::disableAnnotationMapping `
131
+ methods are deprecated since Symfony 6.4, use the
132
+ :method: `Symfony\\ Component\\ Validator\\ ValidatorBuilder::enableAttributeMapping `
133
+ and :method: `Symfony\\ Component\\ Validator\\ ValidatorBuilder::disableAttributeMapping `
134
+ methods instead.
135
+
120
136
.. include :: /_includes/_annotation_loader_tip.rst.inc
121
137
138
+ The AttributeLoader
139
+ -------------------
140
+
141
+ .. versionadded :: 6.4
142
+
143
+ The :class: `Symfony\\ Component\\ Validator\\ Mapping\\ Loader\\ AttributeLoader `
144
+ was introduced in Symfony 6.4.
145
+
146
+ The component provides an
147
+ :class: `Symfony\\ Component\\ Validator\\ Mapping\\ Loader\\ AttributeLoader ` to get
148
+ the metadata from the attributes of the class. For example::
149
+
150
+ use Symfony\Component\Validator\Constraints as Assert;
151
+ // ...
152
+
153
+ class User
154
+ {
155
+ #[Assert\NotBlank]
156
+ protected string $name;
157
+ }
158
+
159
+ To enable the attribute loader, call the
160
+ :method: `Symfony\\ Component\\ Validator\\ ValidatorBuilder::enableAttributeMapping ` method.
161
+
162
+ To disable the annotation loader after it was enabled, call
163
+ :method: `Symfony\\ Component\\ Validator\\ ValidatorBuilder::disableAttributeMapping `.
164
+
122
165
Using Multiple Loaders
123
166
----------------------
124
167
@@ -132,8 +175,7 @@ multiple mappings::
132
175
use Symfony\Component\Validator\Validation;
133
176
134
177
$validator = Validation::createValidatorBuilder()
135
- ->enableAnnotationMapping(true)
136
- ->addDefaultDoctrineAnnotationReader()
178
+ ->enableAttributeMapping()
137
179
->addMethodMapping('loadValidatorMetadata')
138
180
->addXmlMapping('validator/validation.xml')
139
181
->getValidator();
0 commit comments