fa536cba2620cd43d828f0202ad3fb37cec06642
[yaffs-website] / web / modules / contrib / imagemagick / src / Todo2311679.php
1 <?php
2
3 /**
4  * @todo #2311679, this is a stop-gap workaround
5  * remove this once core has a solution in place.
6  */
7
8 namespace Drupal\imagemagick;
9
10 use Drupal\Core\File\MimeType\ExtensionMimeTypeGuesser;
11
12 /**
13  * Makes possible to guess the MIME type of a file using its extension.
14  */
15 class Todo2311679 extends ExtensionMimeTypeGuesser {
16
17   public function getExtensionsForMimeType($mimetype) {
18     if ($this->mapping === NULL) {
19       $mapping = $this->defaultMapping;
20       // Allow modules to alter the default mapping.
21       $this->moduleHandler->alter('file_mimetype_mapping', $mapping);
22       $this->mapping = $mapping;
23     }
24     if (!in_array($mimetype, $this->mapping['mimetypes'])) {
25       return [];
26     }
27     $key = array_search($mimetype, $this->mapping['mimetypes']);
28     $extensions = array_keys($this->mapping['extensions'], $key, TRUE);
29     sort($extensions);
30     return $extensions;
31   }
32
33   public function getMimeTypes() {
34     if ($this->mapping === NULL) {
35       $mapping = $this->defaultMapping;
36       // Allow modules to alter the default mapping.
37       $this->moduleHandler->alter('file_mimetype_mapping', $mapping);
38       $this->mapping = $mapping;
39     }
40     return array_values($this->mapping['mimetypes']);
41   }
42
43 }