public function createValidator($validatorType, array $validatorOptions = [])
{
$validatorObjectName = $this->resolveValidatorObjectName($validatorType);
if ($validatorObjectName === false) {
return null;
}
switch ($this->objectManager->getScope($validatorObjectName)) {
case Configuration::SCOPE_PROTOTYPE:
$validator = new $validatorObjectName($validatorOptions);
break;
case Configuration::SCOPE_SINGLETON:
if (count($validatorOptions) > 0) {
throw new Exception\InvalidValidationConfigurationException('The validator "' . $validatorObjectName . '" is of scope singleton, but configured to be used with options. A validator with options must be of scope prototype.', 1358958575);
}
$validator = $this->objectManager->get($validatorObjectName);
break;
default:
throw new Exception\NoSuchValidatorException('The validator "' . $validatorObjectName . '" is not of scope singleton or prototype!', 1300694835);
}
if (!$validator instanceof ValidatorInterface) {
throw new Exception\NoSuchValidatorException(sprintf('The validator "%s" does not implement %s!', $validatorObjectName, ValidatorInterface::class), 1300694875);
}
return $validator;
}