public static function guess(string $filename): ?string
    {
        if (! \is_file($filename)) {
            throw new FileNotFoundException($filename);
        }

        if (! \is_readable($filename)) {
            throw new AccessDeniedException($filename);
        }

        if (self::$magicFile !== null) {
            $finfo = \finfo_open(\FILEINFO_MIME_TYPE, self::$magicFile);
        } else {
            $finfo = \finfo_open(\FILEINFO_MIME_TYPE);
        }

        $type = \finfo_file($finfo, $filename);

        \finfo_close($finfo);

        return $type ?? null;
    }
public static function guess(string $filename): ?string
    {
        if (! \is_file($filename)) {
            throw new FileNotFoundException($filename);
        }

        if (! \is_readable($filename)) {
            throw new AccessDeniedException($filename);
        }

        if (self::$magicFile !== null) {
            $finfo = \finfo_open(\FILEINFO_MIME_TYPE, self::$magicFile);
        } else {
            $finfo = \finfo_open(\FILEINFO_MIME_TYPE);
        }

        $type = \finfo_file($finfo, $filename);

        \finfo_close($finfo);

        return $type ?? null;
    }
public static function guess ( string $ filename ) : ? string { if ( ! \ is_file ( $ filename ) ) { throw new FileNotFoundException ( $ filename ) ; } if ( ! \ is_readable ( $ filename ) ) { throw new AccessDeniedException ( $ filename ) ; } if ( self :: $ magicFile !== null ) { $ finfo = \ finfo_open ( \ FILEINFO_MIME_TYPE , self :: $ magicFile ) ; } else { $ finfo = \ finfo_open ( \ FILEINFO_MIME_TYPE ) ; } $ type = \ finfo_file ( $ finfo , $ filename ) ; \ finfo_close ( $ finfo ) ; return $ type ?? null ; }
Guesses the mime type using the PECL extension FileInfo.

@param string $filename The path to the file

@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

@see http://www.php.net/manual/en/function.finfo-open.php
Guesses the mime type using the PECL extension FileInfo .