protected function validateType($value, array $schema, array $types = []): ErrorResult
    {
        $result = new ErrorResult();
        if (isset($schema['type'])) {
            if (is_array($schema['type'])) {
                $type = $schema['type'][0];
                if (in_array(gettype($value), $schema['type'])) {
                    $type = gettype($value);
                }
            } else {
                $type = $schema['type'];
            }
            switch ($type) {
                case 'string':
                    $result->merge($this->validateStringType($value, $schema, $types));
                    break;
                case 'number':
                    $result->merge($this->validateNumberType($value, $schema));
                    break;
                case 'integer':
                    $result->merge($this->validateIntegerType($value, $schema));
                    break;
                case 'boolean':
                    $result->merge($this->validateBooleanType($value, $schema));
                    break;
                case 'array':
                    $result->merge($this->validateArrayType($value, $schema, $types));
                    break;
                case 'dictionary':
                    $result->merge($this->validateDictionaryType($value, $schema, $types));
                    break;
                case 'null':
                    $result->merge($this->validateNullType($value, $schema));
                    break;
                case 'any':
                    $result->merge($this->validateAnyType($value, $schema));
                    break;
                default:
                    if (is_string($type) && substr($type, 0, 1) === '@') {
                        if (array_key_exists($type, $types)) {
                            $result->merge($this->validate($value, $types[$type], $types));
                            break;
                        }
                    }
                    $result->addError($this->createError('Type "' . $type . '" is unknown'));
                    break;
            }
        } else {
            $result->addError($this->createError('Type constraint is required'));
        }

        return $result;
    }
protected function validateType($value, array $schema, array $types = []): ErrorResult
    {
        $result = new ErrorResult();
        if (isset($schema['type'])) {
            if (is_array($schema['type'])) {
                $type = $schema['type'][0];
                if (in_array(gettype($value), $schema['type'])) {
                    $type = gettype($value);
                }
            } else {
                $type = $schema['type'];
            }
            switch ($type) {
                case 'string':
                    $result->merge($this->validateStringType($value, $schema, $types));
                    break;
                case 'number':
                    $result->merge($this->validateNumberType($value, $schema));
                    break;
                case 'integer':
                    $result->merge($this->validateIntegerType($value, $schema));
                    break;
                case 'boolean':
                    $result->merge($this->validateBooleanType($value, $schema));
                    break;
                case 'array':
                    $result->merge($this->validateArrayType($value, $schema, $types));
                    break;
                case 'dictionary':
                    $result->merge($this->validateDictionaryType($value, $schema, $types));
                    break;
                case 'null':
                    $result->merge($this->validateNullType($value, $schema));
                    break;
                case 'any':
                    $result->merge($this->validateAnyType($value, $schema));
                    break;
                default:
                    if (is_string($type) && substr($type, 0, 1) === '@') {
                        if (array_key_exists($type, $types)) {
                            $result->merge($this->validate($value, $types[$type], $types));
                            break;
                        }
                    }
                    $result->addError($this->createError('Type "' . $type . '" is unknown'));
                    break;
            }
        } else {
            $result->addError($this->createError('Type constraint is required'));
        }

        return $result;
    }
protected function validateType ( $ value , array $ schema , array $ types = [ ] ) : ErrorResult { $ result = new ErrorResult ( ) ; if ( isset ( $ schema [ 'type' ] ) ) { if ( is_array ( $ schema [ 'type' ] ) ) { $ type = $ schema [ 'type' ] [ 0 ] ; if ( in_array ( gettype ( $ value ) , $ schema [ 'type' ] ) ) { $ type = gettype ( $ value ) ; } } else { $ type = $ schema [ 'type' ] ; } switch ( $ type ) { case 'string' : $ result -> merge ( $ this -> validateStringType ( $ value , $ schema , $ types ) ) ; break ; case 'number' : $ result -> merge ( $ this -> validateNumberType ( $ value , $ schema ) ) ; break ; case 'integer' : $ result -> merge ( $ this -> validateIntegerType ( $ value , $ schema ) ) ; break ; case 'boolean' : $ result -> merge ( $ this -> validateBooleanType ( $ value , $ schema ) ) ; break ; case 'array' : $ result -> merge ( $ this -> validateArrayType ( $ value , $ schema , $ types ) ) ; break ; case 'dictionary' : $ result -> merge ( $ this -> validateDictionaryType ( $ value , $ schema , $ types ) ) ; break ; case 'null' : $ result -> merge ( $ this -> validateNullType ( $ value , $ schema ) ) ; break ; case 'any' : $ result -> merge ( $ this -> validateAnyType ( $ value , $ schema ) ) ; break ; default : if ( is_string ( $ type ) && substr ( $ type , 0 , 1 ) === '@' ) { if ( array_key_exists ( $ type , $ types ) ) { $ result -> merge ( $ this -> validate ( $ value , $ types [ $ type ] , $ types ) ) ; break ; } } $ result -> addError ( $ this -> createError ( 'Type "' . $ type . '" is unknown' ) ) ; break ; } } else { $ result -> addError ( $ this -> createError ( 'Type constraint is required' ) ) ; } return $ result ; }
Validate a value for a given type

@param mixed $value
@param array $schema
@param array $types
@return ErrorResult
Validate a value for a given type