Using Expressions in Validation Constraints #21476

Open
Seb33300 opened this Issue Jan 31, 2017 · 3 comments

Projects

None yet

5 participants

@Seb33300

Hi,

It seems to not be possible at this time.

Instead of using the @Assert\Expression constraint, sometimes, it could be great to support expressions directly in others constraints like:

/**
 * @Assert\Range(
 *      min = "this.startDate",
 *      max = "this.startDate + 10 days"
 * )
 */
 protected $endDate;

/**
 * @Assert\GreaterThan("this.startDate")
 */
protected $endDate;

// etc...
@stof
Member
stof commented Jan 31, 2017

supporting expressions directly like than would be hard to handle it in a BC way (I see lots of weird edge cases coming).

IIRC, there was already some discussion around this before, but I cannot find the right issue anymore right now.

@xabbuh xabbuh added this to the 3.x milestone Jan 31, 2017
@sstok
Contributor
sstok commented Feb 2, 2017

What about in-lined annotations?

/**
 * @Assert\Range(
 *      min = @Assert\ExpressionValue("this.startDate"),
 *      max = @Assert\ExpressionValue("this.startDate + 10 days")
 * )
 */

And technically in these cases it's properly a good idea to create a custom Constraint/Validator then doing everything with expressions.

@iltar
Contributor
iltar commented Feb 3, 2017

I think this would simplify constraints quite a bit tbh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment