Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

MimeTypeGuesser.php

Zuletzt modifiziert: 09.10.2024, 12:59 - Dateigröße: 3.72 KiB


 001  <?php
 002   
 003  /*
 004   * This file is part of the Symfony package.
 005   *
 006   * (c) Fabien Potencier <fabien@symfony.com>
 007   *
 008   * For the full copyright and license information, please view the LICENSE
 009   * file that was distributed with this source code.
 010   */
 011   
 012  namespace Symfony\Component\HttpFoundation\File\MimeType;
 013   
 014  use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException;
 015  use Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException;
 016   
 017  /**
 018   * A singleton mime type guesser.
 019   *
 020   * By default, all mime type guessers provided by the framework are installed
 021   * (if available on the current OS/PHP setup).
 022   *
 023   * You can register custom guessers by calling the register() method on the
 024   * singleton instance. Custom guessers are always called before any default ones.
 025   *
 026   *     $guesser = MimeTypeGuesser::getInstance();
 027   *     $guesser->register(new MyCustomMimeTypeGuesser());
 028   *
 029   * If you want to change the order of the default guessers, just re-register your
 030   * preferred one as a custom one. The last registered guesser is preferred over
 031   * previously registered ones.
 032   *
 033   * Re-registering a built-in guesser also allows you to configure it:
 034   *
 035   *     $guesser = MimeTypeGuesser::getInstance();
 036   *     $guesser->register(new FileinfoMimeTypeGuesser('/path/to/magic/file'));
 037   *
 038   * @author Bernhard Schussek <bschussek@gmail.com>
 039   */
 040  class MimeTypeGuesser implements MimeTypeGuesserInterface
 041  {
 042      /**
 043       * The singleton instance
 044       *
 045       * @var MimeTypeGuesser
 046       */
 047      private static $instance = null;
 048   
 049      /**
 050       * All registered MimeTypeGuesserInterface instances
 051       *
 052       * @var array
 053       */
 054      protected $guessers = array();
 055   
 056      /**
 057       * Returns the singleton instance
 058       *
 059       * @return MimeTypeGuesser
 060       */
 061      public static function getInstance()
 062      {
 063          if (null === self::$instance) {
 064              self::$instance = new self();
 065          }
 066   
 067          return self::$instance;
 068      }
 069   
 070      /**
 071       * Registers all natively provided mime type guessers
 072       */
 073      private function __construct()
 074      {
 075          if (FileBinaryMimeTypeGuesser::isSupported()) {
 076              $this->register(new FileBinaryMimeTypeGuesser());
 077          }
 078   
 079          if (FileinfoMimeTypeGuesser::isSupported()) {
 080              $this->register(new FileinfoMimeTypeGuesser());
 081          }
 082      }
 083   
 084      /**
 085       * Registers a new mime type guesser
 086       *
 087       * When guessing, this guesser is preferred over previously registered ones.
 088       *
 089       * @param MimeTypeGuesserInterface $guesser
 090       */
 091      public function register(MimeTypeGuesserInterface $guesser)
 092      {
 093          array_unshift($this->guessers, $guesser);
 094      }
 095   
 096      /**
 097       * Tries to guess the mime type of the given file
 098       *
 099       * The file is passed to each registered mime type guesser in reverse order
 100       * of their registration (last registered is queried first). Once a guesser
 101       * returns a value that is not NULL, this method terminates and returns the
 102       * value.
 103       *
 104       * @param string $path The path to the file
 105       *
 106       * @return string         The mime type or NULL, if none could be guessed
 107       *
 108       * @throws \LogicException
 109       * @throws FileNotFoundException
 110       * @throws AccessDeniedException
 111       */
 112      public function guess($path)
 113      {
 114          if (!is_file($path)) {
 115              throw new FileNotFoundException($path);
 116          }
 117   
 118          if (!is_readable($path)) {
 119              throw new AccessDeniedException($path);
 120          }
 121   
 122          if (!$this->guessers) {
 123              throw new \LogicException('Unable to guess the mime type as no guessers are available (Did you enable the php_fileinfo extension?)');
 124          }
 125   
 126          foreach ($this->guessers as $guesser) {
 127              if (null !== $mimeType = $guesser->guess($path)) {
 128                  return $mimeType;
 129              }
 130          }
 131      }
 132  }
 133