Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Tweak validator configuration for attributes/annotations
  • Loading branch information
l-vo authored Sep 1, 2022
commit 0cc3844816a30face9c62a3381cd8a1935e2553d
10 changes: 5 additions & 5 deletions components/validator/resources.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ prefixed classes included in doc block comments (``/** ... */``). For example::
}

To enable the annotation loader, call the
:method:`Symfony\\Component\\Validator\\ValidatorBuilder::enableAnnotationMapping` method
and then call ``addDefaultDoctrineAnnotationReader()`` to use Doctrine's
annotation reader::
:method:`Symfony\\Component\\Validator\\ValidatorBuilder::enableAnnotationMapping` method.
If you use annotations instead of attributes, it's also required to call
``addDefaultDoctrineAnnotationReader()`` to use Doctrine's annotation reader::

use Symfony\Component\Validator\Validation;

$validator = Validation::createValidatorBuilder()
->enableAnnotationMapping(true)
->addDefaultDoctrineAnnotationReader()
->enableAnnotationMapping()
->addDefaultDoctrineAnnotationReader() // Only if annotations are used
->getValidator();

To disable the annotation loader after it was enabled, call
Expand Down