4

I'm using Symfony 2.5 and my Model class is the following:

/**
 * @UserAssert\UserPasswordReset
*/
class ResetPassword {

/**
 * @var string
 * @Assert\NotBlank()
 */
public $username;

/**
 * @var string
 * @Assert\NotBlank()
 * @Assert\Date
 */
public $birthday;

/**
 * @var string
 * @Assert\NotBlank()
 */
public $plainSecurityAnswer;


function __toString()
{
    return $this->username . $this->birthday->format('Y-m-d H:i:s') . $this->plainSecurityAnswer;
}

}

This Model is mapped to a ResetFormType. Now my intention: How can i say / configure, that i first want the property constraints to be passed. And if all property constraints are passed (e.g. no field is blank), i want the @UserAssert\UserPasswordReset to be called.

At the moment, it always validates the property AND the class constraints.

Regards ++

1 Answer 1

5

I think you can do it using a GroupSequence Validator like this:

/**
 * @UserAssert\UserPasswordReset(groups={"PasswordReset"})
 * @Assert\GroupSequence({"Default", "PasswordReset"})
 */
class ResetPassword
{
    //----
}

In this mode UserPasswordReset will be validated only after the Defaults Asserts.

In the docs you will find some implementations example to use groups sequences..

Sign up to request clarification or add additional context in comments.

3 Comments

thanks alot! That's what i was looking for. Damn i looked up the documentation but overread GroupSequences .. -.- Accepted your answer.
glad to be helpful :-)
Default group is no longer allowed to be used in GroupSequence. Use the class name (in this case ResetPassword) instead of Default to get the same result.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.