private function resolveFilename($file)
    {
        if (empty($file)) {
            return null;
        }

        if (
            ($file instanceof UploadedFileInterface && $file->getError() === 0)
            || $file instanceof StreamableInterface
        ) {
            return StreamWrapper::getFilename($file->getStream());
        }

        if (is_array($file)) {
            if (!isset($file['tmp_name'])) {
                return null;
            }

            $file = $file['tmp_name'];
        }

        if (!is_string($file) || !$this->files->exists($file)) {
            return null;
        }

        return $file;
    }