class FileinfoMimeTypeGuesser in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/symfony/http-foundation/File/MimeType/FileinfoMimeTypeGuesser.php \Symfony\Component\HttpFoundation\File\MimeType\FileinfoMimeTypeGuesser
Guesses the mime type using the PECL extension FileInfo.
@author Bernhard Schussek <bschussek@gmail.com>
Hierarchy
- class \Symfony\Component\HttpFoundation\File\MimeType\FileinfoMimeTypeGuesser implements MimeTypeGuesserInterface
Expanded class hierarchy of FileinfoMimeTypeGuesser
File
- vendor/
symfony/ http-foundation/ File/ MimeType/ FileinfoMimeTypeGuesser.php, line 22
Namespace
Symfony\Component\HttpFoundation\File\MimeTypeView source
class FileinfoMimeTypeGuesser implements MimeTypeGuesserInterface {
private $magicFile;
/**
* Constructor.
*
* @param string $magicFile A magic file to use with the finfo instance
*
* @link http://www.php.net/manual/en/function.finfo-open.php
*/
public function __construct($magicFile = null) {
$this->magicFile = $magicFile;
}
/**
* Returns whether this guesser is supported on the current OS/PHP setup.
*
* @return bool
*/
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;
}
if (!($finfo = new \finfo(FILEINFO_MIME_TYPE, $this->magicFile))) {
return;
}
return $finfo
->file($path);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FileinfoMimeTypeGuesser:: |
private | property | ||
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. | |
FileinfoMimeTypeGuesser:: |
public | function | Constructor. |