You are here

public function MimeTypeGuesser::guess in Zircon Profile 8.0

Same name in this branch
  1. 8.0 vendor/symfony/http-foundation/File/MimeType/MimeTypeGuesser.php \Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser::guess()
  2. 8.0 core/lib/Drupal/Core/File/MimeType/MimeTypeGuesser.php \Drupal\Core\File\MimeType\MimeTypeGuesser::guess()
  3. 8.0 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 core/lib/Drupal/Core/File/MimeType/MimeTypeGuesser.php \Drupal\Core\File\MimeType\MimeTypeGuesser::guess()

Guesses the mime type of the file with the given path.

Parameters

string $path The path to the file:

Return value

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

Throws

FileNotFoundException If the file does not exist

AccessDeniedException If the file could not be read

Overrides MimeTypeGuesserInterface::guess

File

core/lib/Drupal/Core/File/MimeType/MimeTypeGuesser.php, line 59
Contains \Drupal\Core\File\MimeType\MimeTypeGuesser.

Class

MimeTypeGuesser
Defines a MIME type guesser that also supports stream wrapper paths.

Namespace

Drupal\Core\File\MimeType

Code

public function guess($path) {
  if ($wrapper = $this->streamWrapperManager
    ->getViaUri($path)) {

    // Get the real path from the stream wrapper.
    $path = $wrapper
      ->realpath();
  }
  if ($this->sortedGuessers === NULL) {

    // Sort is not triggered yet.
    $this->sortedGuessers = $this
      ->sortGuessers();
  }
  foreach ($this->sortedGuessers as $guesser) {
    $mime_type = $guesser
      ->guess($path);
    if ($mime_type !== NULL) {
      return $mime_type;
    }
  }
}