interface MimeTypeMapInterface

Provides an interface for MIME type to file extension mapping.

Hierarchy

Expanded class hierarchy of MimeTypeMapInterface

All classes that implement MimeTypeMapInterface

2 files declare their use of MimeTypeMapInterface
LegacyMimeTypeTest.php in core/tests/Drupal/KernelTests/Core/File/MimeType/LegacyMimeTypeTest.php
MimeTypeMapLoadedEvent.php in core/lib/Drupal/Core/File/Event/MimeTypeMapLoadedEvent.php

File

core/lib/Drupal/Core/File/MimeType/MimeTypeMapInterface.php, line 10

Namespace

Drupal\Core\File\MimeType
View source
interface MimeTypeMapInterface {
  
  /**
   * Adds a mapping between a MIME type and an extension.
   *
   * @param string $mimetype
   *   The MIME type the passed extension should map.
   * @param string $extension
   *   The extension(s) that should map to the passed MIME type.
   *
   * @return $this
   */
  public function addMapping(string $mimetype, string $extension) : self;
  
  /**
   * Removes the mapping between a MIME type and an extension.
   *
   * @param string $mimetype
   *   The MIME type to be removed from the mapping.
   * @param string $extension
   *   The extension to be removed from the mapping.
   *
   * @return bool
   *   TRUE if the extension was present, FALSE otherwise.
   */
  public function removeMapping(string $mimetype, string $extension) : bool;
  
  /**
   * Removes a MIME type and all its mapped extensions from the mapping.
   *
   * @param string $mimetype
   *   The MIME type to be removed from the mapping.
   *
   * @return bool
   *   TRUE if the MIME type was present, FALSE otherwise.
   */
  public function removeMimeType(string $mimetype) : bool;
  
  /**
   * Returns known MIME types.
   *
   * @return string[]
   *   An array of MIME types.
   */
  public function listMimeTypes() : array;
  
  /**
   * Returns known file extensions.
   *
   * @return string[]
   *   An array of file extensions.
   */
  public function listExtensions() : array;
  
  /**
   * Determines if a MIME type exists.
   *
   * @param string $mimetype
   *   The mime type.
   *
   * @return bool
   *   TRUE if the MIME type exists, FALSE otherwise.
   */
  public function hasMimeType(string $mimetype) : bool;
  
  /**
   * Determines if a file extension exists.
   *
   * @param string $extension
   *   The file extension.
   *
   * @return bool
   *   TRUE if the file extension exists, FALSE otherwise.
   */
  public function hasExtension(string $extension) : bool;
  
  /**
   * Returns the appropriate MIME type for a given file extension.
   *
   * @param string $extension
   *   A file extension, without leading dot.
   *
   * @return string|null
   *   A matching MIME type, or NULL if no MIME type matches the extension.
   */
  public function getMimeTypeForExtension(string $extension) : ?string;
  
  /**
   * Returns the appropriate extensions for a given MIME type.
   *
   * @param string $mimetype
   *   A MIME type.
   *
   * @return string[]
   *   An array of file extensions matching the MIME type, without leading dot.
   */
  public function getExtensionsForMimeType(string $mimetype) : array;

}

Members

Title Sort descending Modifiers Object type Summary
MimeTypeMapInterface::addMapping public function Adds a mapping between a MIME type and an extension.
MimeTypeMapInterface::getExtensionsForMimeType public function Returns the appropriate extensions for a given MIME type.
MimeTypeMapInterface::getMimeTypeForExtension public function Returns the appropriate MIME type for a given file extension.
MimeTypeMapInterface::hasExtension public function Determines if a file extension exists.
MimeTypeMapInterface::hasMimeType public function Determines if a MIME type exists.
MimeTypeMapInterface::listExtensions public function Returns known file extensions.
MimeTypeMapInterface::listMimeTypes public function Returns known MIME types.
MimeTypeMapInterface::removeMapping public function Removes the mapping between a MIME type and an extension.
MimeTypeMapInterface::removeMimeType public function Removes a MIME type and all its mapped extensions from the mapping.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.