Skip to content

Commit 44eed7c

Browse files
committed
minor #18781 [Validator] Deprecate annotations (alexandre-daubois)
This PR was merged into the 6.4 branch. Discussion ---------- [Validator] Deprecate annotations Fix #18780 Commits ------- 597644a [Validator] Deprecate annotations
2 parents bd1a546 + 597644a commit 44eed7c

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::
@@ -121,8 +128,44 @@ If you use annotations instead of attributes, it's also required to call
121128
To disable the annotation loader after it was enabled, call
122129
:method:`Symfony\\Component\\Validator\\ValidatorBuilder::disableAnnotationMapping`.
123130

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

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+
126169
Using Multiple Loaders
127170
----------------------
128171

@@ -136,8 +179,7 @@ multiple mappings::
136179
use Symfony\Component\Validator\Validation;
137180

138181
$validator = Validation::createValidatorBuilder()
139-
->enableAnnotationMapping(true)
140-
->addDefaultDoctrineAnnotationReader()
182+
->enableAttributeMapping()
141183
->addMethodMapping('loadValidatorMetadata')
142184
->addXmlMapping('validator/validation.xml')
143185
->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
->getValidator();
221221

222222
return [

reference/configuration/framework.rst

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

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

2674+
.. deprecated:: 6.4
2675+
2676+
This option is deprecated since Symfony 6.4, use the ``enable_attributes``
2677+
option instead.
2678+
2679+
enable_attributes
2680+
.................
2681+
2682+
**type**: ``boolean`` **default**: ``true``
2683+
2684+
If this option is enabled, validation constraints can be defined using attributes.
2685+
26742686
translation_domain
26752687
..................
26762688

@@ -2862,6 +2874,18 @@ enable_annotations
28622874

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

2877+
.. deprecated:: 6.4
2878+
2879+
This option is deprecated since Symfony 6.4, use the ``enable_attributes``
2880+
option instead.
2881+
2882+
enable_attributes
2883+
.................
2884+
2885+
**type**: ``boolean`` **default**: ``true``
2886+
2887+
If this option is enabled, serialization groups can be defined using attributes.
2888+
28652889
.. seealso::
28662890

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

0 commit comments

Comments
 (0)