public function validate($value, Constraint $constraint)
{
if ($value === null || $value === '') {
return;
}
if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
throw new UnexpectedTypeException($value, 'string');
}
$countries = $this->countryRepository->getList();
$value = (string) $value;
if (!isset($countries[$value])) {
if ($this->context instanceof \Symfony\Component\Validator\Context\ExecutionContextInterface) {
$this->context->buildViolation($constraint->message)->setParameter('{{ value }}', $this->formatValue($value))->addViolation();
} else {
$this->buildViolation($constraint->message)->setParameter('{{ value }}', $this->formatValue($value))->addViolation();
}
}
}