You are here

public function MimeTypeGuesser::guess in Zircon Profile 8

Same name in this branch
  1. 8 vendor/symfony/http-foundation/File/MimeType/MimeTypeGuesser.php \Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser::guess()
  2. 8 core/lib/Drupal/Core/File/MimeType/MimeTypeGuesser.php \Drupal\Core\File\MimeType\MimeTypeGuesser::guess()
  3. 8 core/lib/Drupal/Core/ProxyClass/File/MimeType/MimeTypeGuesser.php \Drupal\Core\ProxyClass\File\MimeType\MimeTypeGuesser::guess()
Same name and namespace in other branches
  1. 8.0 vendor/symfony/http-foundation/File/MimeType/MimeTypeGuesser.php \Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser::guess()

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.

Parameters

string $path The path to the file:

Return value

string The mime type or NULL, if none could be guessed

Throws

\LogicException

FileNotFoundException

AccessDeniedException

Overrides MimeTypeGuesserInterface::guess

File

vendor/symfony/http-foundation/File/MimeType/MimeTypeGuesser.php, line 120

Class

MimeTypeGuesser
A singleton mime type guesser.

Namespace

Symfony\Component\HttpFoundation\File\MimeType

Code

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;
    }
  }
}