You are here

class FileExtensionGuesser in Gutenberg 8

Same name and namespace in other branches
  1. 8.2 src/FileExtensionGuesser.php \Drupal\gutenberg\FileExtensionGuesser

Guesses all possible extensions .

@package Drupal\gutenberg

Hierarchy

Expanded class hierarchy of FileExtensionGuesser

1 string reference to 'FileExtensionGuesser'
gutenberg.services.yml in ./gutenberg.services.yml
gutenberg.services.yml
1 service uses FileExtensionGuesser
gutenberg.file_extension_guesser in ./gutenberg.services.yml
Drupal\gutenberg\FileExtensionGuesser

File

src/FileExtensionGuesser.php, line 12

Namespace

Drupal\gutenberg
View source
class FileExtensionGuesser extends ExtensionMimeTypeGuesser implements FileExtensionGuesserInterface {

  /**
   * {@inheritDoc}
   */
  public function guessByGeneralMimeType(string $general_mime_type) {
    $mime_types = array_filter($this->defaultMapping['mimetypes'], function ($mime_type) use ($general_mime_type) {
      $pieces = explode('/', $mime_type);
      return $pieces[0] === $general_mime_type;
    });
    $mime_type_ids = array_keys($mime_types);
    $filtered_extensions = array_filter($this->defaultMapping['extensions'], function ($mime_type_id) use ($mime_type_ids) {
      return in_array($mime_type_id, $mime_type_ids);
    });
    return array_keys($filtered_extensions);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
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.
ExtensionMimeTypeGuesser::__construct public function Constructs a new ExtensionMimeTypeGuesser.
FileExtensionGuesser::guessByGeneralMimeType public function Guesses all possible file extensions by general mime type. Overrides FileExtensionGuesserInterface::guessByGeneralMimeType