Skip to content

[Validator] Validate from within Expression #11940

Closed
@webmozart

Description

@webmozart

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureGood first issueIdeal for your first contribution! (some Symfony experience may be required)Help wantedIssues and PRs which are looking for volunteers to complete them.Keep openValidator

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions