wiki/content/20201109150640-expressionlanguage_constraint.md

733 B

date id title
20201109 cafa5c65-3517-4e04-b724-a7e3b467142d ExpressionLanguage Constraint

Syntax

use Symfony\Component\Validator\Constraints as Assert;

class Event
{
    /** @Assert\DateTime() */
    private $startDate;

    /**
     * @Assert\DateTime()
     * @Assert\Expression("value > this.startDate")
     */
    private $endDate;

    // ...
}

In Symfony 4.0 a new propertyPath option was added:

use Symfony\Component\Validator\Constraints as Assert;

class Event
{
    /** @Assert\DateTime() */
    private $startDate;

    /**
     * @Assert\DateTime()
     * @Assert\GreaterThan(propertyPath="startDate")
     */
    private $endDate;

    // ...
}