File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -70,3 +70,28 @@ Classes
70
70
Some constraints allow to validate the entire object. For example, the
71
71
:doc: `Callback </reference/constraints/Callback >` constraint is a generic
72
72
constraint that's applied to the class itself.
73
+
74
+ Suppose that the class defines a ``validate() `` method to hold its custom
75
+ validation logic::
76
+
77
+ // ...
78
+ use Symfony\Component\Validator\Context\ExecutionContextInterface;
79
+
80
+ public function validate(ExecutionContextInterface $context)
81
+ {
82
+ // ...
83
+ }
84
+
85
+ Then, add the Validator component configuration to the class::
86
+
87
+ // ...
88
+ use Symfony\Component\Validator\Mapping\ClassMetadata;
89
+ use Symfony\Component\Validator\Constraints as Assert;
90
+
91
+ class Author
92
+ {
93
+ public static function loadValidatorMetadata(ClassMetadata $metadata)
94
+ {
95
+ $metadata->addConstraint(new Assert\Callback('validate'));
96
+ }
97
+ }
You can’t perform that action at this time.
0 commit comments