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;
    }
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;
    }
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 ; }
Get a validator for a given data type. Returns a validator implementing
the ValidatorInterface or NULL if no validator
could be resolved.

@param string $validatorType Either one of the built-in data types or fully qualified validator class name
@param array $validatorOptions Options to be passed to the validator
@return ValidatorInterface
@throws Exception\NoSuchValidatorException
@throws Exception\InvalidValidationConfigurationException
@api
Get a validator for a given data type . Returns a validator implementing the ValidatorInterface or NULL if no validator could be resolved .