Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop validation on constraint failure in Symfony2

If I have many validators against my entity, can I somehow specify one that it stops the rest if it fails? IE: there's no point checking Permissions if it fails NotBlank.

Alternatively, if its not built in, perhaps theres a way to signal the graph walker to stop, and I can put in a validator that checks for prior failures and stops propagation through the graph.

like image 706
jhogendorn Avatar asked Apr 13 '12 04:04

jhogendorn


1 Answers

Despite this being quite old, as of 5.1 there is a way to do this by using the Sequentially constraint.

This constraint allows you to apply a set of rules that should be validated step-by-step, allowing to interrupt the validation once the first violation is raised.

You would just pass an array of the constraints to validate:

/**
 * @Assert\Sequentially({ @Assert\NotBlank(), @Permissions() })
 */
like image 192
msg Avatar answered Sep 19 '22 17:09

msg