diff --git a/components/validator/resources.rst b/components/validator/resources.rst index 5dfacd3e48f..3d10c28518d 100644 --- a/components/validator/resources.rst +++ b/components/validator/resources.rst @@ -86,7 +86,14 @@ configure the locations of these files:: The AnnotationLoader -------------------- -At last, the component provides an +.. deprecated:: 6.4 + + The :class:`Symfony\\Component\\Validator\\Mapping\\Loader\\AnnotationLoader` + is deprecated since Symfony 6.4, use the + :class:`Symfony\\Component\\Validator\\Mapping\\Loader\\AttributeLoader` + instead. + +The component provides an :class:`Symfony\\Component\\Validator\\Mapping\\Loader\\AnnotationLoader` to get the metadata from the annotations of the class. Annotations are defined as ``@`` 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 To disable the annotation loader after it was enabled, call :method:`Symfony\\Component\\Validator\\ValidatorBuilder::disableAnnotationMapping`. +.. deprecated:: 6.4 + + The :method:`Symfony\\Component\\Validator\\ValidatorBuilder::enableAnnotationMapping` + and :method:`Symfony\\Component\\Validator\\ValidatorBuilder::disableAnnotationMapping` + methods are deprecated since Symfony 6.4, use the + :method:`Symfony\\Component\\Validator\\ValidatorBuilder::enableAttributeMapping` + and :method:`Symfony\\Component\\Validator\\ValidatorBuilder::disableAttributeMapping` + methods instead. + .. include:: /_includes/_annotation_loader_tip.rst.inc +The AttributeLoader +------------------- + +.. versionadded:: 6.4 + + The :class:`Symfony\\Component\\Validator\\Mapping\\Loader\\AttributeLoader` + was introduced in Symfony 6.4. + +The component provides an +:class:`Symfony\\Component\\Validator\\Mapping\\Loader\\AttributeLoader` to get +the metadata from the attributes of the class. For example:: + + use Symfony\Component\Validator\Constraints as Assert; + // ... + + class User + { + #[Assert\NotBlank] + protected string $name; + } + +To enable the attribute loader, call the +:method:`Symfony\\Component\\Validator\\ValidatorBuilder::enableAttributeMapping` method. + +To disable the annotation loader after it was enabled, call +:method:`Symfony\\Component\\Validator\\ValidatorBuilder::disableAttributeMapping`. + Using Multiple Loaders ---------------------- @@ -136,8 +179,7 @@ multiple mappings:: use Symfony\Component\Validator\Validation; $validator = Validation::createValidatorBuilder() - ->enableAnnotationMapping(true) - ->addDefaultDoctrineAnnotationReader() + ->enableAttributeMapping() ->addMethodMapping('loadValidatorMetadata') ->addXmlMapping('validator/validation.xml') ->getValidator(); diff --git a/form/unit_testing.rst b/form/unit_testing.rst index f6a44cc3346..0cff565be00 100644 --- a/form/unit_testing.rst +++ b/form/unit_testing.rst @@ -216,7 +216,7 @@ allows you to return a list of extensions to register:: // or if you also need to read constraints from annotations $validator = Validation::createValidatorBuilder() - ->enableAnnotationMapping(true) + ->enableAttributeMapping() ->getValidator(); return [ diff --git a/reference/configuration/framework.rst b/reference/configuration/framework.rst index cfbef6f46aa..ae1e43ef1e1 100644 --- a/reference/configuration/framework.rst +++ b/reference/configuration/framework.rst @@ -2671,6 +2671,18 @@ enable_annotations If this option is enabled, validation constraints can be defined using annotations or attributes. +.. deprecated:: 6.4 + + This option is deprecated since Symfony 6.4, use the ``enable_attributes`` + option instead. + +enable_attributes +................. + +**type**: ``boolean`` **default**: ``true`` + +If this option is enabled, validation constraints can be defined using attributes. + translation_domain .................. @@ -2862,6 +2874,18 @@ enable_annotations If this option is enabled, serialization groups can be defined using annotations or attributes. +.. deprecated:: 6.4 + + This option is deprecated since Symfony 6.4, use the ``enable_attributes`` + option instead. + +enable_attributes +................. + +**type**: ``boolean`` **default**: ``true`` + +If this option is enabled, serialization groups can be defined using attributes. + .. seealso:: For more information, see :ref:`serializer-using-serialization-groups-attributes`.