Skip to content

Commit 234c3f0

Browse files
[Validator] Deprecate annotations
1 parent e4799d5 commit 234c3f0

File tree

3 files changed

+70
-4
lines changed

3 files changed

+70
-4
lines changed

components/validator/resources.rst

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,14 @@ configure the locations of these files::
8686
The AnnotationLoader
8787
--------------------
8888

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
9097
:class:`Symfony\\Component\\Validator\\Mapping\\Loader\\AnnotationLoader` to get
9198
the metadata from the annotations of the class. Annotations are defined as ``@``
9299
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
117124
To disable the annotation loader after it was enabled, call
118125
:method:`Symfony\\Component\\Validator\\ValidatorBuilder::disableAnnotationMapping`.
119126

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+
120136
.. include:: /_includes/_annotation_loader_tip.rst.inc
121137

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+
122165
Using Multiple Loaders
123166
----------------------
124167

@@ -132,8 +175,7 @@ multiple mappings::
132175
use Symfony\Component\Validator\Validation;
133176

134177
$validator = Validation::createValidatorBuilder()
135-
->enableAnnotationMapping(true)
136-
->addDefaultDoctrineAnnotationReader()
178+
->enableAttributeMapping()
137179
->addMethodMapping('loadValidatorMetadata')
138180
->addXmlMapping('validator/validation.xml')
139181
->getValidator();

form/unit_testing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ allows you to return a list of extensions to register::
216216

217217
// or if you also need to read constraints from annotations
218218
$validator = Validation::createValidatorBuilder()
219-
->enableAnnotationMapping(true)
219+
->enableAttributeMapping()
220220
->addDefaultDoctrineAnnotationReader()
221221
->getValidator();
222222

reference/configuration/framework.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2628,6 +2628,18 @@ enable_annotations
26282628

26292629
If this option is enabled, validation constraints can be defined using annotations or attributes.
26302630

2631+
.. deprecated:: 6.4
2632+
2633+
This option is deprecated since Symfony 6.4, use the ``enable_attributes``
2634+
option instead.
2635+
2636+
enable_attributes
2637+
.................
2638+
2639+
**type**: ``boolean`` **default**: ``true``
2640+
2641+
If this option is enabled, validation constraints can be defined using attributes.
2642+
26312643
translation_domain
26322644
..................
26332645

@@ -2844,6 +2856,18 @@ enable_annotations
28442856

28452857
If this option is enabled, serialization groups can be defined using annotations or attributes.
28462858

2859+
.. deprecated:: 6.4
2860+
2861+
This option is deprecated since Symfony 6.4, use the ``enable_attributes``
2862+
option instead.
2863+
2864+
enable_attributes
2865+
.................
2866+
2867+
**type**: ``boolean`` **default**: ``true``
2868+
2869+
If this option is enabled, serialization groups can be defined using attributes.
2870+
28472871
.. seealso::
28482872

28492873
For more information, see :ref:`serializer-using-serialization-groups-attributes`.

0 commit comments

Comments
 (0)