use SilverStripe\Core\Validation\ConstraintValidator;
use Symfony\Component\Validator\Constraints\Url;
$isValid = ConstraintValidator::validate($url, new Url())->isValid();
Any which require symfony/doctrine or anything which assumes we're using symfony/validate in the context of setting constraints on metadata objects:
Symfony\Component\Validator\Constraints\Cascade
Symfony\Component\Validator\Constraints\Traverse
Symfony\Component\Validator\Constraints\Valid
With exception of those last three (which I've mentioned in the docs are explicitly not supported, because it relies on extra wiring up of things that we just aren't gonna do), I'd expect the others to all work - I just haven't included tests for them because we don't have those dependencies.
[x] All commits are relevant to the purpose of the PR (e.g. no debug statements, unrelated refactoring, or arbitrary linting)
Small amounts of additional linting are usually okay, but if it makes it hard to concentrate on the relevant changes, ask for the unrelated changes to be reverted, and submitted as a separate PR.
Description
Wires up
symfony/validator
so we can use it for robust and potentially complex validation logic.Usage is:
e.g. for testing if a URL is valid:
Most of the constraints in https://symfony.com/doc/current/reference/constraints.html are explicitly supported, except for the following:
Any which require
symfony/expression-language
:Symfony\Component\Validator\Constraints\Expression
Symfony\Component\Validator\Constraints\ExpressionSyntax
Symfony\Component\Validator\Constraints\When
Any which require
symfony/http-client
:Symfony\Component\Validator\Constraints\NotCompromisedPassword
Any which require
symfony/intl
:Symfony\Component\Validator\Constraints\Bic
Symfony\Component\Validator\Constraints\Country
Symfony\Component\Validator\Constraints\Currency
Symfony\Component\Validator\Constraints\Language
Symfony\Component\Validator\Constraints\Locale
Any which require
symfony/doctrine
or anything which assumes we're using symfony/validate in the context of setting constraints on metadata objects:Symfony\Component\Validator\Constraints\Cascade
Symfony\Component\Validator\Constraints\Traverse
Symfony\Component\Validator\Constraints\Valid
With exception of those last three (which I've mentioned in the docs are explicitly not supported, because it relies on extra wiring up of things that we just aren't gonna do), I'd expect the others to all work - I just haven't included tests for them because we don't have those dependencies.
Issues
Pull request checklist