/**
* Returns the validator for the supplied constraint.
*
* @param Constraint $constraint A constraint
*
* @return ConstraintValidatorInterface A validator for the supplied constraint
*
* @throws UnexpectedTypeException When the validator is not an instance of ConstraintValidatorInterface
*/
public function getInstance(Constraint $constraint)
{
$name = $constraint->validatedBy();
if (!isset($this->validators[$name])) {
switch (get_class($constraint)) {
case self::BASE_NAMESPACE . '\\All':
$name = self::BASE_NAMESPACE . '\\LegacyAllValidator';
break;
case self::BASE_NAMESPACE . '\\Choice':
$name = self::BASE_NAMESPACE . '\\LegacyChoiceValidator';
break;
case self::BASE_NAMESPACE . '\\Collection':
$name = self::BASE_NAMESPACE . '\\LegacyCollectionValidator';
break;
case self::BASE_NAMESPACE . '\\Count':
$name = self::BASE_NAMESPACE . '\\LegacyCountValidator';
break;
case self::BASE_NAMESPACE . '\\Length':
$name = self::BASE_NAMESPACE . '\\LegacyLengthValidator';
break;
case self::FORM_BASE_NAMESPACE . '\\Form':
$name = self::FORM_BASE_NAMESPACE . '\\LegacyFormValidator';
break;
}
$this->validators[$name] = new $name();
} elseif (is_string($this->validators[$name])) {
$this->validators[$name] = $this->container->get($this->validators[$name]);
}
if (!$this->validators[$name] instanceof ConstraintValidatorInterface) {
throw new UnexpectedTypeException($this->validators[$name], 'Symfony\\Component\\Validator\\ConstraintValidatorInterface');
}
return $this->validators[$name];
}