8000 [Validator] Validate from within Expression · Issue #11940 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Validator] Validate from within Expression #11940

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

Closed
webmozart opened this issue Sep 16, 2014 · 13 comments · Fixed by #50438
Closed

[Validator] Validate from within Expression #11940

webmozart opened this issue Sep 16, 2014 · 13 comments · Fixed by #50438
Labels
Feature Good first issue Ideal for your first contribution! (some Symfony experience may be required) Help wanted Issues and PRs which are looking for volunteers to complete them. Keep open Validator

Comments

@webmozart
Copy link
Contributor

The issue #11586 could be solved by providing a valid() method in the Expression constraint (as alias for $context->getValidator()->validate(), but returning a boolean):

/**
 * @Expression("valid(this.author) or valid(this.creator)", message="Author or creator must be valid!")
 */

Additionally, a "constraints" option could be added which allows to pass constraints that can be used within the expression:

/**
 * @Expression(
 *     "valid(value, regex) or valid(value, threeOrMore)",
 *     message="Value must match regex or be greater than 3!",
 *     constraints={
 *         "regex" = @Regex("/here-is-my-regex/"),
 *         "threeOrMore" = @GreaterThan(3),
 *     }
 * )
 */

Opinions?

@linaori
Copy link
Contributor
linaori commented Sep 17, 2014

I have no experience with that validator, but the example provided looks like a good example for DX. 👍

@javiereguiluz
Copy link
Member

The only thing that doesn't convince me is the method name valid() instead of using isValid()

/**
 * @Expression("valid(this.author) or valid(this.creator)", message="...")
 */

/**
 * @Expression("isValid(this.author) or isValid(this.creator)", message="...")
 */

@webmozart
Copy link
Contributor Author

@javiereguiluz Yes, this would go along nicely with what is proposed in #11939.

@stof
Copy link
Member
stof commented Sep 17, 2014

Adding such a function is a good idea. 👍

@fabpot
Copy link
Member
fabpot commented Sep 17, 2014

is_valid sounds like the best option to me.

@linaori
Copy link
Contributor
linaori commented Sep 17, 2014

Would be consistent with is_granted, has_role etc. used in other Expressions/Twig

@webmozart
Copy link
Contributor Author

@fabpot @iltar good points!

@carsonbot
Copy link
8000

Thank you for this suggestion.
There has not been a lot of activity here for a while. Would you still like to see this feature?

@xabbuh xabbuh added Keep open and removed Stalled labels Feb 21, 2021
@nicolas-grekas nicolas-grekas added Help wanted Issues and PRs which are looking for volunteers to complete them. Good first issue Ideal for your first contribution! (some Symfony experience may be required) labels Feb 26, 2022
@nicolas-grekas
Copy link
Member

Putting labels "Help wanted" and "Good first issue" on this one. Anyone willing to give it a try?

@yahya09
Copy link
yahya09 commented Feb 28, 2022

Putting labels "Help wanted" and "Good first issue" on this one. Anyone willing to give it a try?

I was surprised there's an open issue from 7 years ago. May I try to handle it?

@nicolas-grekas
Copy link
Member

@yahya09 sure! I'd be happy to help during review!

@HotScottPtII
Copy link

Is this still Open? Anyone on it, otherwise I'd like to make a crack at it!

@xabbuh
Copy link
Member
xabbuh commented Apr 23, 2023

@HotScottPtII There already is #47153 which tries to implement this feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Good first issue Ideal for your first contribution! (some Symfony experience may be required) Help wanted Issues and PRs which are looking for volunteers to complete them. Keep open Validator
Projects
None yet
10 participants
0