diff --git a/components/validator/metadata.rst b/components/validator/metadata.rst index 15b3cd56658..2b68d535b40 100755 --- a/components/validator/metadata.rst +++ b/components/validator/metadata.rst @@ -70,3 +70,28 @@ Classes Some constraints allow to validate the entire object. For example, the :doc:`Callback ` constraint is a generic constraint that's applied to the class itself. + +Suppose that the class defines a ``validate()`` method to hold its custom +validation logic:: + + // ... + use Symfony\Component\Validator\Context\ExecutionContextInterface; + + public function validate(ExecutionContextInterface $context) + { + // ... + } + +Then, add the Validator component configuration to the class:: + + // ... + use Symfony\Component\Validator\Mapping\ClassMetadata; + use Symfony\Component\Validator\Constraints as Assert; + + class Author + { + public static function loadValidatorMetadata(ClassMetadata $metadata) + { + $metadata->addConstraint(new Assert\Callback('validate')); + } + }