Skip to content

Commit

Permalink
[HttpFoundation] Fix perf issue during MimeTypeGuesser intialization
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed May 23, 2018
1 parent 84bba75 commit f8e7a18
Showing 1 changed file with 6 additions and 15 deletions.
Expand Up @@ -80,13 +80,8 @@ public static function reset()
*/
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());
}

/**
Expand Down Expand Up @@ -125,18 +120,14 @@ public function guess($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;
}
}

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?)');
}
}
}

0 comments on commit f8e7a18

Please sign in to comment.