You are here

class FileinfoMimeTypeGuesser in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/symfony/http-foundation/File/MimeType/FileinfoMimeTypeGuesser.php \Symfony\Component\HttpFoundation\File\MimeType\FileinfoMimeTypeGuesser

Guesses the mime type using the PECL extension FileInfo.

@author Bernhard Schussek <bschussek@gmail.com>

Hierarchy

Expanded class hierarchy of FileinfoMimeTypeGuesser

File

vendor/symfony/http-foundation/File/MimeType/FileinfoMimeTypeGuesser.php, line 22

Namespace

Symfony\Component\HttpFoundation\File\MimeType
View source
class FileinfoMimeTypeGuesser implements MimeTypeGuesserInterface {
  private $magicFile;

  /**
   * Constructor.
   *
   * @param string $magicFile A magic file to use with the finfo instance
   *
   * @link http://www.php.net/manual/en/function.finfo-open.php
   */
  public function __construct($magicFile = null) {
    $this->magicFile = $magicFile;
  }

  /**
   * Returns whether this guesser is supported on the current OS/PHP setup.
   *
   * @return bool
   */
  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;
    }
    if (!($finfo = new \finfo(FILEINFO_MIME_TYPE, $this->magicFile))) {
      return;
    }
    return $finfo
      ->file($path);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FileinfoMimeTypeGuesser::$magicFile private property
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.
FileinfoMimeTypeGuesser::__construct public function Constructor.