Skip to content

Commit

Permalink
bug #376 [make:validator] Custom constraints should ignore null and e…
Browse files Browse the repository at this point in the history
…mpty values (voronkovich)

This PR was squashed before being merged into the 1.0-dev branch (closes #376).

Discussion
----------

[make:validator] Custom constraints should ignore null and empty values

See https://symfony.com/doc/current/validation/custom_constraint.html#creating-the-validator-itself

Commits
-------

c959791 [make:validator] Custom constraints should ignore null and empty values
  • Loading branch information
weaverryan committed Apr 19, 2019
2 parents d5d142e + c959791 commit d262c2c
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Resources/skeleton/validator/Validator.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ public function validate($value, Constraint $constraint)
{
/* @var $constraint \<?= $constraint_class_name ?> */

if (null === $value || '' === $value) {
return;
}

// TODO: implement the validation here
$this->context->buildViolation($constraint->message)
->setParameter('{{ value }}', $value)
->addViolation();
Expand Down

0 comments on commit d262c2c

Please sign in to comment.