Skip to content

[Validator] Add a constraint condition option #32877

Closed
@Seb33300

Description

@Seb33300

Description

I would like to request a new way to handle when a constraint should be applied or not by adding a new condition option on all constraints.

The new condition option should accept an expression in the same way as the Expression constraint.

Thanks to this option, we should be able to use a more appropriated constraint than the Expression constraint when possible.

Example

For example, it's easier to understand what a NotNull constraint is intended to.

Instead of doing:

/**
 * @Assert\Expression("value or this.isNullable()", message="This value should be null.")
 */
protected $nullableOnCondition;

We will be able to do:

/**
 * @Assert\NotNull(condition="!this.isNullable()")
 */
protected $nullableOnCondition;

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions