Guesses the mime type using the PECL extension FileInfo
@author Bernhard Schussek <bschussek@gmail.com>
Expanded class hierarchy of FileinfoMimeTypeGuesser
class FileinfoMimeTypeGuesser implements MimeTypeGuesserInterface {
/**
* Returns whether this guesser is supported on the current OS/PHP setup
*
* @return Boolean
*/
public static function isSupported() {
return function_exists('finfo_open');
}
/**
* {@inheritdoc}
*/
public function guess($path) {
if (!is_file($path)) {
throw new FileNotFoundException($path);
}
if (!is_readable($path)) {
throw new AccessDeniedException($path);
}
if (!self::isSupported()) {
return null;
}
if (!($finfo = new \finfo(FILEINFO_MIME_TYPE))) {
return null;
}
return $finfo
->file($path);
}
}
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FileinfoMimeTypeGuesser:: |
public | function |
Guesses the mime type of the file with the given path. Overrides MimeTypeGuesserInterface:: |
|
FileinfoMimeTypeGuesser:: |
public static | function | Returns whether this guesser is supported on the current OS/PHP setup |