File tree 2 files changed +23
-2
lines changed
2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change 2
2
single: Validator; Built In validators
3
3
4
4
Built In validators
5
- ===================
5
+ ===================
6
+
7
+ For each validation rule, the component ships a Constraint class and its associated Validator class.
8
+ The Constraint object describes the rule to check and the Validator implementation runs the validation logic.
Original file line number Diff line number Diff line change @@ -34,7 +34,25 @@ method of the Validator builder::
34
34
->getValidator();
35
35
36
36
Now, the retrieved ``Validator `` tries to find the ``loadValidatorMetadata() ``
37
- method of the class to validate to load its metadata.
37
+ method of the class to validate to load its metadata::
38
+
39
+ use Symfony\Component\Validator\Mapping\ClassMetadata;
40
+ use Symfony\Component\Validator\Constraints\NotBlank;
41
+ use Symfony\Component\Validator\Constraints\Length;
42
+
43
+ class User
44
+ {
45
+ protected $name;
46
+
47
+ public static function loadValidatorMatadata(ClassMetadata $metadata)
48
+ {
49
+ $metadata->addPropertyConstraint('name', new NotBlank());
50
+ $metadata->addPropertyConstraint('name', new Length(array(
51
+ 'min' => 5,
52
+ 'max' => 20,
53
+ )));
54
+ }
55
+ }
38
56
39
57
.. tip ::
40
58
You can’t perform that action at this time.
0 commit comments