class FileinfoMimeTypeGuesser

Guesses the mime type using the PECL extension FileInfo

@author Bernhard Schussek <bschussek@gmail.com>

Hierarchy

Expanded class hierarchy of FileinfoMimeTypeGuesser

File

drupal/core/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/File/MimeType/FileinfoMimeTypeGuesser.php, line 22

Namespace

Symfony\Component\HttpFoundation\File\MimeType
View source
class FileinfoMimeTypeGuesser implements MimeTypeGuesserInterface {

  /**
   * Returns whether this guesser is supported on the current OS/PHP setup
   *
   * @return Boolean
   */
  public static function isSupported() {
    return function_exists('finfo_open');
  }

  /**
   * {@inheritdoc}
   */
  public function guess($path) {
    if (!is_file($path)) {
      throw new FileNotFoundException($path);
    }
    if (!is_readable($path)) {
      throw new AccessDeniedException($path);
    }
    if (!self::isSupported()) {
      return null;
    }
    if (!($finfo = new \finfo(FILEINFO_MIME_TYPE))) {
      return null;
    }
    return $finfo
      ->file($path);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FileinfoMimeTypeGuesser::guess public function Guesses the mime type of the file with the given path. Overrides MimeTypeGuesserInterface::guess
FileinfoMimeTypeGuesser::isSupported public static function Returns whether this guesser is supported on the current OS/PHP setup