public static function guess(string $guess): ?string
    {
        $guessers = self::getGuessers();

        if (\count($guessers) === 0) {
            $msg = 'Unable to guess the mime type as no guessers are available';

            if (! MimeTypeFileInfoGuesser::isSupported()) {
                $msg .= ' (Did you enable the php_fileinfo extension?).';
            }

            throw new \LogicException($msg);
        }

        $exception = null;

        foreach ($guessers as $guesser) {
            try {
                $mimeType = $guesser::guess($guess);
            } catch (RuntimeException $e) {
                $exception = $e;

                continue;
            }

            if ($mimeType !== null) {
                return $mimeType;
            }
        }

        // Throw the last catched exception.
        if ($exception !== null) {
            throw $exception;
        }

        return null;
    }
public static function guess(string $guess): ?string
    {
        $guessers = self::getGuessers();

        if (\count($guessers) === 0) {
            $msg = 'Unable to guess the mime type as no guessers are available';

            if (! MimeTypeFileInfoGuesser::isSupported()) {
                $msg .= ' (Did you enable the php_fileinfo extension?).';
            }

            throw new \LogicException($msg);
        }

        $exception = null;

        foreach ($guessers as $guesser) {
            try {
                $mimeType = $guesser::guess($guess);
            } catch (RuntimeException $e) {
                $exception = $e;

                continue;
            }

            if ($mimeType !== null) {
                return $mimeType;
            }
        }

        // Throw the last catched exception.
        if ($exception !== null) {
            throw $exception;
        }

        return null;
    }
public static function guess ( string $ guess ) : ? string { $ guessers = self :: getGuessers ( ) ; if ( \ count ( $ guessers ) === 0 ) { $ msg = 'Unable to guess the mime type as no guessers are available' ; if ( ! MimeTypeFileInfoGuesser :: isSupported ( ) ) { $ msg .= ' (Did you enable the php_fileinfo extension?).' ; } throw new \ LogicException ( $ msg ) ; } $ exception = null ; foreach ( $ guessers as $ guesser ) { try { $ mimeType = $ guesser :: guess ( $ guess ) ; } catch ( RuntimeException $ e ) { $ exception = $ e ; continue ; } if ( $ mimeType !== null ) { return $ mimeType ; } } // Throw the last catched exception. if ( $ exception !== null ) { throw $ exception ; } return null ; }
Tries to guess the mime type.

@param string $guess The path to the file or the file extension

@throws \Narrowspark\MimeType\Exception\FileNotFoundException If the file does not exist
@throws \Narrowspark\MimeType\Exception\AccessDeniedException If the file could not be read

@return null|string The guessed extension or NULL, if none could be guessed
Tries to guess the mime type .