4

I have a Profile entity with an email field and I'm trying to validate it using Symfony Validator. I'm trying this using the GroupSequence feature because one of my constraints is fairly expensive from a computation point-of-view.

Basically, I want a valid email address and the domain should not be blacklisted (a custom constraint that uses an internal list of domains). The last constraint I want to be applied only if the email is valid, so I'm using the group sequence, but it's not working as expected.

I'm using Symfony 2.8.2 and I have the following validation.yml file:

Namespace\Entities\Profile:
    group_sequence:
        - Profile
        - common
        - email.strict
    properties:
        email:
            - Email: { groups: [common, email.strict] }
            - Namespace\ProfileBundle\Validators\Constraints\EmailNotBlacklisted: { groups: [email.strict] }

The validation is done like this:

$profile = new Profile();
$profile->setEmail('blacklisted.com');
$errors = $this->validator->validate($profile, array('common', 'email.strict'));

Given that blacklisted.com is an invalid value, I'm expecting the Email constraint to fail and therefore it should never reach the EmailNotBlacklisted constraint.

However, $errors contains errors from both constraints.

What am I doing wrong in this usage of group_sequence feature?

Catalin
  • 41
  • 4
  • Possible duplicate of [Stop validation on first error flag in Symfony2?](http://stackoverflow.com/questions/16359928/stop-validation-on-first-error-flag-in-symfony2) – NDM Aug 01 '16 at 09:51
  • 1
    @NDM I want to use the **GroupSequence** feature from Symfony and I don't want to implement something custom since they said in documentation that this should work – Catalin Aug 03 '16 at 14:56

0 Answers0