From dc91480c9e2fb086653e3b7fd0189a60639a3916 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Andrieu?= Date: Mon, 27 Jul 2015 12:34:14 +0200 Subject: [PATCH] Added a note about Symfony Validator use --- book/validation.rst | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/book/validation.rst b/book/validation.rst index d5f8744b8b5..0fc6cce4b65 100644 --- a/book/validation.rst +++ b/book/validation.rst @@ -1285,6 +1285,20 @@ object, which acts just like an array of errors. Each error in the collection is a :class:`Symfony\\Component\\Validator\\ConstraintViolation` object, which holds the error message on its ``getMessage`` method. +Using the Validator outside the Symfony framework context +--------------------------------------------------------- + +The Symfony ``validator`` can be used outside Symfony framework thanks to the :class: `Symfony\Component\Validator\ValidatorBuilder`: + + use Symfony\Component\Validator\ValidatorBuilder; + + $validator = (new ValidatorBuilder()) + ->addMethodMapping('loadValidatorMetadata') + ->getValidator(); + +The ValidatorBuilder accept also Yaml or Xml mappings, you only need to set up the ``addXmlMapping/addYamlMapping`` methods with the correct path to the file. To enable the annotations, the method ``enableAnnotationMapping`` is available. + + Final Thoughts --------------