@@ -88,30 +88,24 @@ The AnnotationLoader
88
88
89
89
At last, the component provides an
90
90
:class: `Symfony\\ Component\\ Validator\\ Mapping\\ Loader\\ AnnotationLoader ` to get
91
- the metadata from the annotations of the class. Annotations are defined as ``@ ``
92
- prefixed classes included in doc block comments (``/** ... */ ``). For example::
91
+ the metadata from the attributes of the class::
93
92
94
93
use Symfony\Component\Validator\Constraints as Assert;
95
94
// ...
96
95
97
96
class User
98
97
{
99
- /**
100
- * @Assert\NotBlank
101
- */
98
+ #[Assert\NotBlank]
102
99
protected string $name;
103
100
}
104
101
105
102
To enable the annotation loader, call the
106
- :method: `Symfony\\ Component\\ Validator\\ ValidatorBuilder::enableAnnotationMapping ` method.
107
- If you use annotations instead of attributes, it's also required to call
108
- ``addDefaultDoctrineAnnotationReader() `` to use Doctrine's annotation reader::
103
+ :method: `Symfony\\ Component\\ Validator\\ ValidatorBuilder::enableAnnotationMapping ` method::
109
104
110
105
use Symfony\Component\Validator\Validation;
111
106
112
107
$validator = Validation::createValidatorBuilder()
113
108
->enableAnnotationMapping()
114
- ->addDefaultDoctrineAnnotationReader() // add this only when using annotations
115
109
->getValidator();
116
110
117
111
To disable the annotation loader after it was enabled, call
@@ -133,7 +127,6 @@ multiple mappings::
133
127
134
128
$validator = Validation::createValidatorBuilder()
135
129
->enableAnnotationMapping(true)
136
- ->addDefaultDoctrineAnnotationReader()
137
130
->addMethodMapping('loadValidatorMetadata')
138
131
->addXmlMapping('validator/validation.xml')
139
132
->getValidator();
0 commit comments