protected function validateTypeArray($value, array $schema, array $types = []): ErrorResult
    {
        $result = new ErrorResult();
        $isValid = false;
        foreach ($schema['type'] as $type) {
            $partResult = $this->validate($value, $type, $types);
            if ($partResult->hasErrors() === false) {
                $isValid = true;
            }
        }
        if ($isValid === false) {
            $possibleTypes = [];
            foreach ($schema['type'] as $type) {
                if (is_scalar($type)) {
                    $possibleTypes[] = $type;
                } elseif (is_array($type) && array_key_exists('type', $type)) {
                    $possibleTypes[] = $type['type'];
                }
            }
            $error = $this->createError(sprintf('None of the given schemas %s matched %s',
                implode(',', $possibleTypes),
                is_scalar($value) ? (string)$value : gettype($value)
            ));
            $result->addError($error);
        }

        return $result;
    }
protected function validateTypeArray($value, array $schema, array $types = []): ErrorResult
    {
        $result = new ErrorResult();
        $isValid = false;
        foreach ($schema['type'] as $type) {
            $partResult = $this->validate($value, $type, $types);
            if ($partResult->hasErrors() === false) {
                $isValid = true;
            }
        }
        if ($isValid === false) {
            $possibleTypes = [];
            foreach ($schema['type'] as $type) {
                if (is_scalar($type)) {
                    $possibleTypes[] = $type;
                } elseif (is_array($type) && array_key_exists('type', $type)) {
                    $possibleTypes[] = $type['type'];
                }
            }
            $error = $this->createError(sprintf('None of the given schemas %s matched %s',
                implode(',', $possibleTypes),
                is_scalar($value) ? (string)$value : gettype($value)
            ));
            $result->addError($error);
        }

        return $result;
    }
protected function validateTypeArray ( $ value , array $ schema , array $ types = [ ] ) : ErrorResult { $ result = new ErrorResult ( ) ; $ isValid = false ; foreach ( $ schema [ 'type' ] as $ type ) { $ partResult = $ this -> validate ( $ value , $ type , $ types ) ; if ( $ partResult -> hasErrors ( ) === false ) { $ isValid = true ; } } if ( $ isValid === false ) { $ possibleTypes = [ ] ; foreach ( $ schema [ 'type' ] as $ type ) { if ( is_scalar ( $ type ) ) { $ possibleTypes [ ] = $ type ; } elseif ( is_array ( $ type ) && array_key_exists ( 'type' , $ type ) ) { $ possibleTypes [ ] = $ type [ 'type' ] ; } } $ error = $ this -> createError ( sprintf ( 'None of the given schemas %s matched %s' , implode ( ',' , $ possibleTypes ) , is_scalar ( $ value ) ? ( string ) $ value : gettype ( $ value ) ) ) ; $ result -> addError ( $ error ) ; } return $ result ; }
Validate a value with a given list of allowed types

@param mixed $value
@param array $schema
@param array $types
@return ErrorResult
Validate a value with a given list of allowed types