<?php/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/namespaceSymfony\Component\HttpFoundation\File\MimeType;
useSymfony\Component\HttpFoundation\File\Exception\FileNotFoundException;
useSymfony\Component\HttpFoundation\File\Exception\AccessDeniedException;
/**
* Guesses the mime type using the PECL extension FileInfo
*
* @author Bernhard Schussek <bschussek@gmail.com>
*/class FileinfoMimeTypeGuesserimplements MimeTypeGuesserInterface {
/**
* Returns whether this guesser is supported on the current OS/PHP setup
*
* @return Boolean
*/
public static functionisSupported() {
returnfunction_exists('finfo_open');
}
/**
* {@inheritdoc}
*/
public functionguess($path) {
if (!is_file($path)) {
thrownewFileNotFoundException($path);
}
if (!is_readable($path)) {
thrownewAccessDeniedException($path);
}
if (!self::isSupported()) {
returnnull;
}
if (!($finfo = new\finfo(FILEINFO_MIME_TYPE))) {
returnnull;
}
return$finfo
->file($path);
}
}