I have a case for you. I have an entity that contains two integers. Both are between 0 and 100, but one is the minimum value and one is the maximum value. Therefore, the max value should be greater than or equal to the min value.
I have had a look at http://symfony.com/doc/current/book/validation.html and http://symfony.com/doc/current/cookbook/validation/custom_constraint.html
In the last of these links we have the following example:
// src/Acme/DemoBundle/Validator/Constraints/ContainsAlphanumericValidator.php
namespace Acme\DemoBundle\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
class ContainsAlphanumericValidator extends ConstraintValidator
{
public function validate($value, Constraint $constraint)
{
if (!preg_match('/^[a-zA-Za0-9]+$/', $value, $matches)) {
$this->context->addViolation($constraint->message, array('%string%' => $value));
}
}
}
But this takes the $value, and I need to compare the min and max to each other. How do I reference the "min" value inside the "max" validator?