src/Viserio/Component/Parser/Parser.php
protected function getFormat(string $payload): string
    {
        $format = '';

        if (\is_file($file = $payload)) {
            $format = \pathinfo($file, \PATHINFO_EXTENSION);
        } elseif (\is_string($payload)) {
            // try if content is json
            \json_decode($payload);

            if (\json_last_error() === \JSON_ERROR_NONE) {
                return 'json';
            }

            $format = (new finfo(\FILEINFO_MIME_TYPE))->buffer($payload);
        }

        return self::$supportedMimeTypes[$format] ?? $format;
    }
protected function getFormat(string $payload): string
    {
        $format = '';

        if (\is_file($file = $payload)) {
            $format = \pathinfo($file, \PATHINFO_EXTENSION);
        } elseif (\is_string($payload)) {
            // try if content is json
            \json_decode($payload);

            if (\json_last_error() === \JSON_ERROR_NONE) {
                return 'json';
            }

            $format = (new finfo(\FILEINFO_MIME_TYPE))->buffer($payload);
        }

        return self::$supportedMimeTypes[$format] ?? $format;
    }
Auto detect the payload data type using finfo and pathinfo.

@param string $payload

@return string Tries to return the short format code (xml, json, ...) else the mime type