namespace Symfony\Component\HttpFoundation\File\MimeType;
-use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException;
use Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException;
+use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException;
/**
* A singleton mime type guesser.
*/
private function __construct()
{
- if (FileBinaryMimeTypeGuesser::isSupported()) {
- $this->register(new FileBinaryMimeTypeGuesser());
- }
-
- if (FileinfoMimeTypeGuesser::isSupported()) {
- $this->register(new FileinfoMimeTypeGuesser());
- }
+ $this->register(new FileBinaryMimeTypeGuesser());
+ $this->register(new FileinfoMimeTypeGuesser());
}
/**
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;
}
}
+
+ if (2 === \count($this->guessers) && !FileBinaryMimeTypeGuesser::isSupported() && !FileinfoMimeTypeGuesser::isSupported()) {
+ throw new \LogicException('Unable to guess the mime type as no guessers are available (Did you enable the php_fileinfo extension?)');
+ }
}
}