Is there a way to access the entity of the property currently being validated in a custom constraint validator, and if so, how? As far as i can see, I only have access to the value (and any services I might choose to inject, of course).
In case if you have property validator, you can also access validated object in Validator through ExecutionContext:
http://api.symfony.com/2.8/Symfony/Component/Validator/Context/ExecutionContextInterface.html#method_getObject
class SomeValidator extends ConstraintValidator
{
public function validate($value, Constraint $constraint)
{
$object = $this->context->getObject();
}
}
Yes, there is a way. Class constraint validator has an entire entity in scope.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With