Skip to content

Added a note about Symfony Validator use outside framework context #5563

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions book/validation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------------

Expand Down