public static function uploadedFile($file, array $options = [])
    {
        $options += [
            'minSize' => null,
            'maxSize' => null,
            'types' => null,
            'optional' => false,
        ];
        if (!is_array($file) && !($file instanceof UploadedFileInterface)) {
            return false;
        }
        $error = $isUploaded = false;
        if ($file instanceof UploadedFileInterface) {
            $error = $file->getError();
            $isUploaded = true;
        }
        if (is_array($file)) {
            $keys = ['error', 'name', 'size', 'tmp_name', 'type'];
            ksort($file);
            if (array_keys($file) != $keys) {
                return false;
            }
            $error = (int)$file['error'];
            $isUploaded = is_uploaded_file($file['tmp_name']);
        }

        if (!static::uploadError($file, $options['optional'])) {
            return false;
        }
        if ($options['optional'] && $error === UPLOAD_ERR_NO_FILE) {
            return true;
        }
        if (isset($options['minSize']) && !static::fileSize($file, static::COMPARE_GREATER_OR_EQUAL, $options['minSize'])) {
            return false;
        }
        if (isset($options['maxSize']) && !static::fileSize($file, static::COMPARE_LESS_OR_EQUAL, $options['maxSize'])) {
            return false;
        }
        if (isset($options['types']) && !static::mimeType($file, $options['types'])) {
            return false;
        }

        return $isUploaded;
    }