Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

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?

share|improve this question
    
Possible duplicate of Stop validation on first error flag in Symfony2? – NDM Aug 1 at 9:51
    
@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 3 at 14:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.