-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Validator] Add support for the otherwise
option in the When
constraint
#59634
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I'm not sure this is what the issue is about. From what I can read, they need a ternary style instead: when foo ? then-this : else-that.
(please take time to give example in PR descriptions for new feature so that it's easy to bootstrap the doc / write a blog post.) |
I did so to be consistent with the Expression constraint, taking the last issue comment example as reference which seemed more in line with what already exists. But if we don't care about this point, let's do as you say, works for me as well 👍
My bad indeed, will do! |
I don't see the point of a negate option here sorry. |
Hey! Given your proposal, the example from #57370 will become: #[Assert\When('this.getProduct()?.getNature()?.value === "SESSION"', new Assert\IsNull())]
#[Assert\When('this.getProduct()?.getNature()?.value === "SESSION"', new Assert\NotNull(), negate: true)] right? What about this syntax suggested in the issue and by Nicolas above? #[Assert\When(
'this.getProduct()?.getNature()?.value === "SESSION"',
new Assert\IsNull(),
otherwise: new Assert\NotNull()
)] or maybe a |
|
7dcfac3
to
5439efb
Compare
It's been more complicated than expected because of how composite constraints work. Their internals has to be updated to accept multiple fields that contains nested constraints (and propagate groups). For this, So here's a new implementation, tell me what you think 👍 |
negate
option in the When
constraintotherwise
option in the When
constraint
5439efb
to
d62d845
Compare
d62d845
to
4d3393f
Compare
All comments addressed, thanks! Should a PR be sent to update to |
get_debug_type is to be used in exception messages. that's better, but not critical either. |
Thank you @alexandre-daubois. |
This feature allows to give constraints to
When
when the evaluated expression returns false: