You are here

class CoreExtensionMimeTypeGuesserExtended in Sophron 8

Extends the class that Drupal core uses to guess the MIME type of a file.

This class is used only to access the protected properities in the parent class, so to make it possible to compare Sophron's supported MIME types with Drupal core ones.

Hierarchy

Expanded class hierarchy of CoreExtensionMimeTypeGuesserExtended

1 file declares its use of CoreExtensionMimeTypeGuesserExtended
SettingsForm.php in src/Form/SettingsForm.php

File

src/CoreExtensionMimeTypeGuesserExtended.php, line 14

Namespace

Drupal\sophron
View source
class CoreExtensionMimeTypeGuesserExtended extends ExtensionMimeTypeGuesser {

  /**
   * Constructs a new CoreExtensionMimeTypeGuesserExtended.
   */
  public function __construct() {
    $this->moduleHandler = \Drupal::service('module_handler');
  }

  /**
   * Returns a list of MIME types supported by Drupal's core guesser.
   *
   * @return string[]
   *   A list of MIME types.
   */
  public function listTypes() {
    return $this
      ->getMapping()['mimetypes'];
  }

  /**
   * Returns a list of file extensions supported by Drupal's core guesser.
   *
   * @return string[]
   *   A list of file extensions.
   */
  public function listExtensions() {
    return array_keys($this
      ->getMapping()['extensions']);
  }

  /**
   * Ensures Drupal's core MIME type mapping is altered by modules.
   */
  protected function getMapping() {
    if ($this->mapping === NULL) {
      $mapping = $this->defaultMapping;

      // Allow modules to alter the default mapping.
      $this->moduleHandler
        ->alter('file_mimetype_mapping', $mapping);
      $this->mapping = $mapping;
    }
    return $this->mapping;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CoreExtensionMimeTypeGuesserExtended::getMapping protected function Ensures Drupal's core MIME type mapping is altered by modules.
CoreExtensionMimeTypeGuesserExtended::listExtensions public function Returns a list of file extensions supported by Drupal's core guesser.
CoreExtensionMimeTypeGuesserExtended::listTypes public function Returns a list of MIME types supported by Drupal's core guesser.
CoreExtensionMimeTypeGuesserExtended::__construct public function Constructs a new CoreExtensionMimeTypeGuesserExtended. Overrides ExtensionMimeTypeGuesser::__construct
ExtensionMimeTypeGuesser::$defaultMapping protected property Default MIME extension mapping.
ExtensionMimeTypeGuesser::$mapping protected property The MIME types mapping array after going through the module handler.
ExtensionMimeTypeGuesser::$moduleHandler protected property The module handler.
ExtensionMimeTypeGuesser::guess public function Guesses the mime type of the file with the given path.
ExtensionMimeTypeGuesser::setMapping public function Sets the mimetypes/extension mapping to use when guessing mimetype.