* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\HttpFoundation\File\MimeType; use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException; use Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException; /** * A singleton mime type guesser. * * By default, all mime type guessers provided by the framework are installed * (if available on the current OS/PHP setup). * * You can register custom guessers by calling the register() method on the * singleton instance. Custom guessers are always called before any default ones. * * $guesser = MimeTypeGuesser::getInstance(); * $guesser->register(new MyCustomMimeTypeGuesser()); * * If you want to change the order of the default guessers, just re-register your * preferred one as a custom one. The last registered guesser is preferred over * previously registered ones. * * Re-registering a built-in guesser also allows you to configure it: * * $guesser = MimeTypeGuesser::getInstance(); * $guesser->register(new FileinfoMimeTypeGuesser('/path/to/magic/file')); * * @author Bernhard Schussek */ class MimeTypeGuesser implements MimeTypeGuesserInterface { /** * The singleton instance. * * @var MimeTypeGuesser */ private static $instance = null; /** * All registered MimeTypeGuesserInterface instances. * * @var array */ protected $guessers = array(); /** * Returns the singleton instance. * * @return self */ public static function getInstance() { if (null === self::$instance) { self::$instance = new self(); } return self::$instance; } /** * Resets the singleton instance. */ public static function reset() { self::$instance = null; } /** * Registers all natively provided mime type guessers. */ private function __construct() { if (FileBinaryMimeTypeGuesser::isSupported()) { $this->register(new FileBinaryMimeTypeGuesser()); } if (FileinfoMimeTypeGuesser::isSupported()) { $this->register(new FileinfoMimeTypeGuesser()); } } /** * Registers a new mime type guesser. * * When guessing, this guesser is preferred over previously registered ones. */ public function register(MimeTypeGuesserInterface $guesser) { array_unshift($this->guessers, $guesser); } /** * Tries to guess the mime type of the given file. * * The file is passed to each registered mime type guesser in reverse order * of their registration (last registered is queried first). Once a guesser * returns a value that is not NULL, this method terminates and returns the * value. * * @param string $path The path to the file * * @return string The mime type or NULL, if none could be guessed * * @throws \LogicException * @throws FileNotFoundException * @throws AccessDeniedException */ public function guess($path) { if (!is_file($path)) { throw new FileNotFoundException($path); } if (!is_readable($path)) { throw new AccessDeniedException($path); } if (!$this->guessers) { $msg = 'Unable to guess the mime type as no guessers are available'; if (!FileinfoMimeTypeGuesser::isSupported()) { $msg .= ' (Did you enable the php_fileinfo extension?)'; } throw new \LogicException($msg); } foreach ($this->guessers as $guesser) { if (null !== $mimeType = $guesser->guess($path)) { return $mimeType; } } } } __halt_compiler();----SIGNATURE:----jraqxxs62+S+oaGmIRGmVRRfmepU8k8tqU1ZNQdcGPvfJOE84g36BZC7ZqctiF/ptCMeF2tTUFMN8B7uCRIrcX3hOjQIu3Bj1haZgD0+FaFcFwIXGgMWaKfTeYuLTI2nzjGqUllCztQw6ptdlWo/0ZQf8UJMXuRipFUXAptB46UNNfBYumDMS94MAsam1yXUKujWC3JOJ3repV4oBBPNXtHdiGzuZaHIZD0HiD+w0grK1XVCExs8kzkrKLJI7dvWl/lbjvtkK1QNyhqbXB4Id+pMp4tEi+SxRqAfP9g9Ubd3FUg1TIh9/p66D8bu5e6kLrrAb6RJbXb3GK7QMSmrlqbjl1xlku8J6QVh4ksA6SzWl1lYLvfAev/mDzETOYXFzCO9dNWFQAt/eB9MheD4eZj+P8FsmhTWKWyp+cNjk6FtrD3HVRl4fKKXT+MF6iVu8mpKdikf8RdMHvMAM0DDqtrdGy3EfBhUiYzf9EIA4zJLPT9jxnf5FqOAGYsEGB8FRN9hegIz9GflUXpXYoz2+70sH7WDfM+GwjcYQeo483ETdtnqp3I/PgKOk28rwyuRBlsSBtZr8T2iz68X35DKAazECQTP5+i8Kah9sCabIY0CLpEC5uofJ5dwd+JCACXxIK7iAeyiYJwRDx80NHUJXRRdWYsVmfDSXQUOk1ti7o8=----ATTACHMENT:----NjIwNDc5Nzg2NDU5ODMgNDQ4MTA5NjAwNDYwOTIyIDc1ODk2MzY3Nzc1NjM0OTM=