Version 1
[yaffs-website] / web / core / lib / Drupal / Core / File / MimeType / ExtensionMimeTypeGuesser.php
1 <?php
2
3 namespace Drupal\Core\File\MimeType;
4
5 use Drupal\Core\Extension\ModuleHandlerInterface;
6 use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface;
7
8 /**
9  * Makes possible to guess the MIME type of a file using its extension.
10  */
11 class ExtensionMimeTypeGuesser implements MimeTypeGuesserInterface {
12
13   /**
14    * Default MIME extension mapping.
15    *
16    * @var array
17    *   Array of mimetypes correlated to the extensions that relate to them.
18    */
19   protected $defaultMapping = [
20     'mimetypes' => [
21       0 => 'application/andrew-inset',
22       1 => 'application/atom',
23       2 => 'application/atomcat+xml',
24       3 => 'application/atomserv+xml',
25       4 => 'application/cap',
26       5 => 'application/cu-seeme',
27       6 => 'application/dsptype',
28       350 => 'application/epub+zip',
29       7 => 'application/hta',
30       8 => 'application/java-archive',
31       9 => 'application/java-serialized-object',
32       10 => 'application/java-vm',
33       11 => 'application/mac-binhex40',
34       12 => 'application/mathematica',
35       13 => 'application/msaccess',
36       14 => 'application/msword',
37       15 => 'application/octet-stream',
38       16 => 'application/oda',
39       17 => 'application/ogg',
40       18 => 'application/pdf',
41       19 => 'application/pgp-keys',
42       20 => 'application/pgp-signature',
43       21 => 'application/pics-rules',
44       22 => 'application/postscript',
45       23 => 'application/rar',
46       24 => 'application/rdf+xml',
47       25 => 'application/rss+xml',
48       26 => 'application/rtf',
49       27 => 'application/smil',
50       349 => 'application/vnd.amazon.ebook',
51       28 => 'application/vnd.cinderella',
52       29 => 'application/vnd.google-earth.kml+xml',
53       30 => 'application/vnd.google-earth.kmz',
54       31 => 'application/vnd.mozilla.xul+xml',
55       32 => 'application/vnd.ms-excel',
56       33 => 'application/vnd.ms-excel.addin.macroEnabled.12',
57       34 => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
58       35 => 'application/vnd.ms-excel.sheet.macroEnabled.12',
59       36 => 'application/vnd.ms-excel.template.macroEnabled.12',
60       37 => 'application/vnd.ms-pki.seccat',
61       38 => 'application/vnd.ms-pki.stl',
62       39 => 'application/vnd.ms-powerpoint',
63       40 => 'application/vnd.ms-powerpoint.addin.macroEnabled.12',
64       41 => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
65       42 => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12',
66       43 => 'application/vnd.ms-powerpoint.template.macroEnabled.12',
67       44 => 'application/vnd.ms-word.document.macroEnabled.12',
68       45 => 'application/vnd.ms-word.template.macroEnabled.12',
69       46 => 'application/vnd.ms-xpsdocument',
70       47 => 'application/vnd.oasis.opendocument.chart',
71       48 => 'application/vnd.oasis.opendocument.database',
72       49 => 'application/vnd.oasis.opendocument.formula',
73       50 => 'application/vnd.oasis.opendocument.graphics',
74       51 => 'application/vnd.oasis.opendocument.graphics-template',
75       52 => 'application/vnd.oasis.opendocument.image',
76       53 => 'application/vnd.oasis.opendocument.presentation',
77       54 => 'application/vnd.oasis.opendocument.presentation-template',
78       55 => 'application/vnd.oasis.opendocument.spreadsheet',
79       56 => 'application/vnd.oasis.opendocument.spreadsheet-template',
80       57 => 'application/vnd.oasis.opendocument.text',
81       58 => 'application/vnd.oasis.opendocument.text-master',
82       59 => 'application/vnd.oasis.opendocument.text-template',
83       60 => 'application/vnd.oasis.opendocument.text-web',
84       61 => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
85       62 => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
86       63 => 'application/vnd.openxmlformats-officedocument.presentationml.template',
87       64 => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
88       65 => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
89       66 => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
90       67 => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
91       68 => 'application/vnd.rim.cod',
92       69 => 'application/vnd.smaf',
93       70 => 'application/vnd.stardivision.calc',
94       71 => 'application/vnd.stardivision.chart',
95       72 => 'application/vnd.stardivision.draw',
96       73 => 'application/vnd.stardivision.impress',
97       74 => 'application/vnd.stardivision.math',
98       75 => 'application/vnd.stardivision.writer',
99       76 => 'application/vnd.stardivision.writer-global',
100       77 => 'application/vnd.sun.xml.calc',
101       78 => 'application/vnd.sun.xml.calc.template',
102       79 => 'application/vnd.sun.xml.draw',
103       80 => 'application/vnd.sun.xml.draw.template',
104       81 => 'application/vnd.sun.xml.impress',
105       82 => 'application/vnd.sun.xml.impress.template',
106       83 => 'application/vnd.sun.xml.math',
107       84 => 'application/vnd.sun.xml.writer',
108       85 => 'application/vnd.sun.xml.writer.global',
109       86 => 'application/vnd.sun.xml.writer.template',
110       87 => 'application/vnd.symbian.install',
111       88 => 'application/vnd.visio',
112       89 => 'application/vnd.wap.wbxml',
113       90 => 'application/vnd.wap.wmlc',
114       91 => 'application/vnd.wap.wmlscriptc',
115       92 => 'application/wordperfect',
116       93 => 'application/wordperfect5.1',
117       94 => 'application/x-123',
118       95 => 'application/x-7z-compressed',
119       96 => 'application/x-abiword',
120       97 => 'application/x-apple-diskimage',
121       98 => 'application/x-bcpio',
122       99 => 'application/x-bittorrent',
123       100 => 'application/x-cab',
124       101 => 'application/x-cbr',
125       102 => 'application/x-cbz',
126       103 => 'application/x-cdf',
127       104 => 'application/x-cdlink',
128       105 => 'application/x-chess-pgn',
129       106 => 'application/x-cpio',
130       107 => 'application/x-debian-package',
131       108 => 'application/x-director',
132       109 => 'application/x-dms',
133       110 => 'application/x-doom',
134       111 => 'application/x-dvi',
135       112 => 'application/x-flac',
136       113 => 'application/x-font',
137       114 => 'application/x-freemind',
138       115 => 'application/x-futuresplash',
139       116 => 'application/x-gnumeric',
140       117 => 'application/x-go-sgf',
141       118 => 'application/x-graphing-calculator',
142       119 => 'application/x-gtar',
143       120 => 'application/x-hdf',
144       121 => 'application/x-httpd-eruby',
145       122 => 'application/x-httpd-php',
146       123 => 'application/x-httpd-php-source',
147       124 => 'application/x-httpd-php3',
148       125 => 'application/x-httpd-php3-preprocessed',
149       126 => 'application/x-httpd-php4',
150       127 => 'application/x-ica',
151       128 => 'application/x-internet-signup',
152       129 => 'application/x-iphone',
153       130 => 'application/x-iso9660-image',
154       131 => 'application/x-java-jnlp-file',
155       132 => 'application/javascript',
156       133 => 'application/x-jmol',
157       134 => 'application/x-kchart',
158       135 => 'application/x-killustrator',
159       136 => 'application/x-koan',
160       137 => 'application/x-kpresenter',
161       138 => 'application/x-kspread',
162       139 => 'application/x-kword',
163       140 => 'application/x-latex',
164       141 => 'application/x-lha',
165       142 => 'application/x-lyx',
166       143 => 'application/x-lzh',
167       144 => 'application/x-lzx',
168       145 => 'application/x-maker',
169       146 => 'application/x-mif',
170       351 => 'application/x-mobipocket-ebook',
171       352 => 'application/x-mobipocket-ebook',
172       147 => 'application/x-ms-wmd',
173       148 => 'application/x-ms-wmz',
174       149 => 'application/x-msdos-program',
175       150 => 'application/x-msi',
176       151 => 'application/x-netcdf',
177       152 => 'application/x-ns-proxy-autoconfig',
178       153 => 'application/x-nwc',
179       154 => 'application/x-object',
180       155 => 'application/x-oz-application',
181       156 => 'application/x-pkcs7-certreqresp',
182       157 => 'application/x-pkcs7-crl',
183       158 => 'application/x-python-code',
184       159 => 'application/x-quicktimeplayer',
185       160 => 'application/x-redhat-package-manager',
186       161 => 'application/x-shar',
187       162 => 'application/x-shockwave-flash',
188       163 => 'application/x-stuffit',
189       164 => 'application/x-sv4cpio',
190       165 => 'application/x-sv4crc',
191       166 => 'application/x-tar',
192       167 => 'application/x-tcl',
193       168 => 'application/x-tex-gf',
194       169 => 'application/x-tex-pk',
195       170 => 'application/x-texinfo',
196       171 => 'application/x-trash',
197       172 => 'application/x-troff',
198       173 => 'application/x-troff-man',
199       174 => 'application/x-troff-me',
200       175 => 'application/x-troff-ms',
201       176 => 'application/x-ustar',
202       177 => 'application/x-wais-source',
203       178 => 'application/x-wingz',
204       179 => 'application/x-x509-ca-cert',
205       180 => 'application/x-xcf',
206       181 => 'application/x-xfig',
207       182 => 'application/x-xpinstall',
208       183 => 'application/xhtml+xml',
209       184 => 'application/xml',
210       185 => 'application/zip',
211       186 => 'audio/basic',
212       187 => 'audio/midi',
213       346 => 'audio/mp4',
214       188 => 'audio/mpeg',
215       189 => 'audio/ogg',
216       190 => 'audio/prs.sid',
217       356 => 'audio/webm',
218       191 => 'audio/x-aiff',
219       192 => 'audio/x-gsm',
220       354 => 'audio/x-matroska',
221       193 => 'audio/x-mpegurl',
222       194 => 'audio/x-ms-wax',
223       195 => 'audio/x-ms-wma',
224       196 => 'audio/x-pn-realaudio',
225       197 => 'audio/x-realaudio',
226       198 => 'audio/x-scpls',
227       199 => 'audio/x-sd2',
228       200 => 'audio/x-wav',
229       201 => 'chemical/x-alchemy',
230       202 => 'chemical/x-cache',
231       203 => 'chemical/x-cache-csf',
232       204 => 'chemical/x-cactvs-binary',
233       205 => 'chemical/x-cdx',
234       206 => 'chemical/x-cerius',
235       207 => 'chemical/x-chem3d',
236       208 => 'chemical/x-chemdraw',
237       209 => 'chemical/x-cif',
238       210 => 'chemical/x-cmdf',
239       211 => 'chemical/x-cml',
240       212 => 'chemical/x-compass',
241       213 => 'chemical/x-crossfire',
242       214 => 'chemical/x-csml',
243       215 => 'chemical/x-ctx',
244       216 => 'chemical/x-cxf',
245       217 => 'chemical/x-embl-dl-nucleotide',
246       218 => 'chemical/x-galactic-spc',
247       219 => 'chemical/x-gamess-input',
248       220 => 'chemical/x-gaussian-checkpoint',
249       221 => 'chemical/x-gaussian-cube',
250       222 => 'chemical/x-gaussian-input',
251       223 => 'chemical/x-gaussian-log',
252       224 => 'chemical/x-gcg8-sequence',
253       225 => 'chemical/x-genbank',
254       226 => 'chemical/x-hin',
255       227 => 'chemical/x-isostar',
256       228 => 'chemical/x-jcamp-dx',
257       229 => 'chemical/x-kinemage',
258       230 => 'chemical/x-macmolecule',
259       231 => 'chemical/x-macromodel-input',
260       232 => 'chemical/x-mdl-molfile',
261       233 => 'chemical/x-mdl-rdfile',
262       234 => 'chemical/x-mdl-rxnfile',
263       235 => 'chemical/x-mdl-sdfile',
264       236 => 'chemical/x-mdl-tgf',
265       237 => 'chemical/x-mmcif',
266       238 => 'chemical/x-mol2',
267       239 => 'chemical/x-molconn-Z',
268       240 => 'chemical/x-mopac-graph',
269       241 => 'chemical/x-mopac-input',
270       242 => 'chemical/x-mopac-out',
271       243 => 'chemical/x-mopac-vib',
272       244 => 'chemical/x-ncbi-asn1-ascii',
273       245 => 'chemical/x-ncbi-asn1-binary',
274       246 => 'chemical/x-ncbi-asn1-spec',
275       247 => 'chemical/x-pdb',
276       248 => 'chemical/x-rosdal',
277       249 => 'chemical/x-swissprot',
278       250 => 'chemical/x-vamas-iso14976',
279       251 => 'chemical/x-vmd',
280       252 => 'chemical/x-xtel',
281       253 => 'chemical/x-xyz',
282       254 => 'image/gif',
283       255 => 'image/ief',
284       256 => 'image/jpeg',
285       257 => 'image/pcx',
286       258 => 'image/png',
287       259 => 'image/svg+xml',
288       260 => 'image/tiff',
289       261 => 'image/vnd.djvu',
290       262 => 'image/vnd.microsoft.icon',
291       263 => 'image/vnd.wap.wbmp',
292       355 => 'image/webp',
293       264 => 'image/x-cmu-raster',
294       265 => 'image/x-coreldraw',
295       266 => 'image/x-coreldrawpattern',
296       267 => 'image/x-coreldrawtemplate',
297       268 => 'image/x-corelphotopaint',
298       269 => 'image/x-jg',
299       270 => 'image/x-jng',
300       271 => 'image/x-ms-bmp',
301       272 => 'image/x-photoshop',
302       273 => 'image/x-portable-anymap',
303       274 => 'image/x-portable-bitmap',
304       275 => 'image/x-portable-graymap',
305       276 => 'image/x-portable-pixmap',
306       277 => 'image/x-rgb',
307       278 => 'image/x-xbitmap',
308       279 => 'image/x-xpixmap',
309       280 => 'image/x-xwindowdump',
310       281 => 'message/rfc822',
311       282 => 'model/iges',
312       283 => 'model/mesh',
313       284 => 'model/vrml',
314       285 => 'text/calendar',
315       286 => 'text/css',
316       287 => 'text/csv',
317       288 => 'text/h323',
318       289 => 'text/html',
319       290 => 'text/iuls',
320       291 => 'text/mathml',
321       292 => 'text/plain',
322       293 => 'text/richtext',
323       294 => 'text/scriptlet',
324       295 => 'text/tab-separated-values',
325       296 => 'text/texmacs',
326       297 => 'text/vnd.sun.j2me.app-descriptor',
327       298 => 'text/vnd.wap.wml',
328       299 => 'text/vnd.wap.wmlscript',
329       358 => 'text/vtt',
330       300 => 'text/x-bibtex',
331       301 => 'text/x-boo',
332       302 => 'text/x-c++hdr',
333       303 => 'text/x-c++src',
334       304 => 'text/x-chdr',
335       305 => 'text/x-component',
336       306 => 'text/x-csh',
337       307 => 'text/x-csrc',
338       308 => 'text/x-diff',
339       309 => 'text/x-dsrc',
340       310 => 'text/x-haskell',
341       311 => 'text/x-java',
342       312 => 'text/x-literate-haskell',
343       313 => 'text/x-moc',
344       314 => 'text/x-pascal',
345       315 => 'text/x-pcs-gcd',
346       316 => 'text/x-perl',
347       317 => 'text/x-python',
348       318 => 'text/x-setext',
349       319 => 'text/x-sh',
350       320 => 'text/x-tcl',
351       321 => 'text/x-tex',
352       322 => 'text/x-vcalendar',
353       323 => 'text/x-vcard',
354       324 => 'video/3gpp',
355       325 => 'video/dl',
356       326 => 'video/dv',
357       327 => 'video/fli',
358       328 => 'video/gl',
359       329 => 'video/mp4',
360       330 => 'video/mpeg',
361       331 => 'video/ogg',
362       332 => 'video/quicktime',
363       333 => 'video/vnd.mpegurl',
364       357 => 'video/webm',
365       347 => 'video/x-flv',
366       334 => 'video/x-la-asf',
367       348 => 'video/x-m4v',
368       353 => 'video/x-matroska',
369       335 => 'video/x-mng',
370       336 => 'video/x-ms-asf',
371       337 => 'video/x-ms-wm',
372       338 => 'video/x-ms-wmv',
373       339 => 'video/x-ms-wmx',
374       340 => 'video/x-ms-wvx',
375       341 => 'video/x-msvideo',
376       342 => 'video/x-sgi-movie',
377       343 => 'x-conference/x-cooltalk',
378       344 => 'x-epoc/x-sisx-app',
379       345 => 'x-world/x-vrml',
380     ],
381
382     // Extensions added to this list MUST be lower-case.
383     'extensions' => [
384       'ez' => 0,
385       'atom' => 1,
386       'atomcat' => 2,
387       'atomsrv' => 3,
388       'cap' => 4,
389       'pcap' => 4,
390       'cu' => 5,
391       'tsp' => 6,
392       'hta' => 7,
393       'jar' => 8,
394       'ser' => 9,
395       'class' => 10,
396       'hqx' => 11,
397       'nb' => 12,
398       'mdb' => 13,
399       'dot' => 14,
400       'doc' => 14,
401       'bin' => 15,
402       'oda' => 16,
403       'ogx' => 17,
404       'pdf' => 18,
405       'key' => 19,
406       'pgp' => 20,
407       'prf' => 21,
408       'eps' => 22,
409       'ai' => 22,
410       'ps' => 22,
411       'rar' => 23,
412       'rdf' => 24,
413       'rss' => 25,
414       'rtf' => 26,
415       'smi' => 27,
416       'smil' => 27,
417       'cdy' => 28,
418       'kml' => 29,
419       'kmz' => 30,
420       'xul' => 31,
421       'xlb' => 32,
422       'xlt' => 32,
423       'xls' => 32,
424       'xlam' => 33,
425       'xlsb' => 34,
426       'xlsm' => 35,
427       'xltm' => 36,
428       'cat' => 37,
429       'stl' => 38,
430       'pps' => 39,
431       'ppt' => 39,
432       'ppam' => 40,
433       'pptm' => 41,
434       'ppsm' => 42,
435       'potm' => 43,
436       'docm' => 44,
437       'dotm' => 45,
438       'xps' => 46,
439       'odc' => 47,
440       'odb' => 48,
441       'odf' => 49,
442       'odg' => 50,
443       'otg' => 51,
444       'odi' => 52,
445       'odp' => 53,
446       'otp' => 54,
447       'ods' => 55,
448       'ots' => 56,
449       'odt' => 57,
450       'odm' => 58,
451       'ott' => 59,
452       'oth' => 60,
453       'pptx' => 61,
454       'ppsx' => 62,
455       'potx' => 63,
456       'xlsx' => 64,
457       'xltx' => 65,
458       'docx' => 66,
459       'dotx' => 67,
460       'cod' => 68,
461       'mmf' => 69,
462       'sdc' => 70,
463       'sds' => 71,
464       'sda' => 72,
465       'sdd' => 73,
466       'sdw' => 75,
467       'sgl' => 76,
468       'sxc' => 77,
469       'stc' => 78,
470       'sxd' => 79,
471       'std' => 80,
472       'sxi' => 81,
473       'sti' => 82,
474       'sxm' => 83,
475       'sxw' => 84,
476       'sxg' => 85,
477       'stw' => 86,
478       'sis' => 87,
479       'vsd' => 88,
480       'wbxml' => 89,
481       'wmlc' => 90,
482       'wmlsc' => 91,
483       'wpd' => 92,
484       'wp5' => 93,
485       'wk' => 94,
486       '7z' => 95,
487       'abw' => 96,
488       'dmg' => 97,
489       'bcpio' => 98,
490       'torrent' => 99,
491       'cab' => 100,
492       'cbr' => 101,
493       'cbz' => 102,
494       'cdf' => 103,
495       'vcd' => 104,
496       'pgn' => 105,
497       'cpio' => 106,
498       'udeb' => 107,
499       'deb' => 107,
500       'dir' => 108,
501       'dxr' => 108,
502       'dcr' => 108,
503       'dms' => 109,
504       'wad' => 110,
505       'dvi' => 111,
506       'flac' => 112,
507       'pfa' => 113,
508       'pfb' => 113,
509       'pcf' => 113,
510       'gsf' => 113,
511       'pcf.z' => 113,
512       'mm' => 114,
513       'spl' => 115,
514       'gnumeric' => 116,
515       'sgf' => 117,
516       'gcf' => 118,
517       'taz' => 119,
518       'gtar' => 119,
519       'tgz' => 119,
520       'hdf' => 120,
521       'rhtml' => 121,
522       'phtml' => 122,
523       'pht' => 122,
524       'php' => 122,
525       'phps' => 123,
526       'php3' => 124,
527       'php3p' => 125,
528       'php4' => 126,
529       'ica' => 127,
530       'ins' => 128,
531       'isp' => 128,
532       'iii' => 129,
533       'iso' => 130,
534       'jnlp' => 131,
535       'js' => 132,
536       'jmz' => 133,
537       'chrt' => 134,
538       'kil' => 135,
539       'skp' => 136,
540       'skd' => 136,
541       'skm' => 136,
542       'skt' => 136,
543       'kpr' => 137,
544       'kpt' => 137,
545       'ksp' => 138,
546       'kwd' => 139,
547       'kwt' => 139,
548       'latex' => 140,
549       'lha' => 141,
550       'lyx' => 142,
551       'lzh' => 143,
552       'lzx' => 144,
553       'maker' => 145,
554       'frm' => 145,
555       'frame' => 145,
556       'fm' => 145,
557       'book' => 145,
558       'fb' => 145,
559       'fbdoc' => 145,
560       'mif' => 146,
561       'wmd' => 147,
562       'wmz' => 148,
563       'dll' => 149,
564       'bat' => 149,
565       'exe' => 149,
566       'com' => 149,
567       'msi' => 150,
568       'nc' => 151,
569       'pac' => 152,
570       'nwc' => 153,
571       'o' => 154,
572       'oza' => 155,
573       'p7r' => 156,
574       'crl' => 157,
575       'pyo' => 158,
576       'pyc' => 158,
577       'qtl' => 159,
578       'rpm' => 160,
579       'shar' => 161,
580       'swf' => 162,
581       'swfl' => 162,
582       'sitx' => 163,
583       'sit' => 163,
584       'sv4cpio' => 164,
585       'sv4crc' => 165,
586       'tar' => 166,
587       'gf' => 168,
588       'pk' => 169,
589       'texi' => 170,
590       'texinfo' => 170,
591       'sik' => 171,
592       '~' => 171,
593       'bak' => 171,
594       '%' => 171,
595       'old' => 171,
596       't' => 172,
597       'roff' => 172,
598       'tr' => 172,
599       'man' => 173,
600       'me' => 174,
601       'ms' => 175,
602       'ustar' => 176,
603       'src' => 177,
604       'wz' => 178,
605       'crt' => 179,
606       'xcf' => 180,
607       'fig' => 181,
608       'xpi' => 182,
609       'xht' => 183,
610       'xhtml' => 183,
611       'xml' => 184,
612       'xsl' => 184,
613       'zip' => 185,
614       'au' => 186,
615       'snd' => 186,
616       'mid' => 187,
617       'midi' => 187,
618       'kar' => 187,
619       'mpega' => 188,
620       'mpga' => 188,
621       'm4a' => 188,
622       'mp3' => 188,
623       'mp2' => 188,
624       'ogg' => 189,
625       'oga' => 189,
626       'spx' => 189,
627       'sid' => 190,
628       'aif' => 191,
629       'aiff' => 191,
630       'aifc' => 191,
631       'gsm' => 192,
632       'm3u' => 193,
633       'wax' => 194,
634       'wma' => 195,
635       'rm' => 196,
636       'ram' => 196,
637       'ra' => 197,
638       'pls' => 198,
639       'sd2' => 199,
640       'wav' => 200,
641       'alc' => 201,
642       'cac' => 202,
643       'cache' => 202,
644       'csf' => 203,
645       'cascii' => 204,
646       'cbin' => 204,
647       'ctab' => 204,
648       'cdx' => 205,
649       'cer' => 206,
650       'c3d' => 207,
651       'chm' => 208,
652       'cif' => 209,
653       'cmdf' => 210,
654       'cml' => 211,
655       'cpa' => 212,
656       'bsd' => 213,
657       'csml' => 214,
658       'csm' => 214,
659       'ctx' => 215,
660       'cxf' => 216,
661       'cef' => 216,
662       'emb' => 217,
663       'embl' => 217,
664       'spc' => 218,
665       'gam' => 219,
666       'inp' => 219,
667       'gamin' => 219,
668       'fchk' => 220,
669       'fch' => 220,
670       'cub' => 221,
671       'gau' => 222,
672       'gjf' => 222,
673       'gjc' => 222,
674       'gal' => 223,
675       'gcg' => 224,
676       'gen' => 225,
677       'hin' => 226,
678       'istr' => 227,
679       'ist' => 227,
680       'dx' => 228,
681       'jdx' => 228,
682       'kin' => 229,
683       'mcm' => 230,
684       'mmd' => 231,
685       'mmod' => 231,
686       'mol' => 232,
687       'rd' => 233,
688       'rxn' => 234,
689       'sdf' => 235,
690       'sd' => 235,
691       'tgf' => 236,
692       'mcif' => 237,
693       'mol2' => 238,
694       'b' => 239,
695       'gpt' => 240,
696       'mopcrt' => 241,
697       'zmt' => 241,
698       'mpc' => 241,
699       'dat' => 241,
700       'mop' => 241,
701       'moo' => 242,
702       'mvb' => 243,
703       'prt' => 244,
704       'aso' => 245,
705       'val' => 245,
706       'asn' => 246,
707       'ent' => 247,
708       'pdb' => 247,
709       'ros' => 248,
710       'sw' => 249,
711       'vms' => 250,
712       'vmd' => 251,
713       'xtel' => 252,
714       'xyz' => 253,
715       'gif' => 254,
716       'ief' => 255,
717       'jpeg' => 256,
718       'jpe' => 256,
719       'jpg' => 256,
720       'pcx' => 257,
721       'png' => 258,
722       'svgz' => 259,
723       'svg' => 259,
724       'tif' => 260,
725       'tiff' => 260,
726       'djvu' => 261,
727       'djv' => 261,
728       'ico' => 262,
729       'wbmp' => 263,
730       'ras' => 264,
731       'cdr' => 265,
732       'pat' => 266,
733       'cdt' => 267,
734       'cpt' => 268,
735       'art' => 269,
736       'jng' => 270,
737       'bmp' => 271,
738       'psd' => 272,
739       'pnm' => 273,
740       'pbm' => 274,
741       'pgm' => 275,
742       'ppm' => 276,
743       'rgb' => 277,
744       'xbm' => 278,
745       'xpm' => 279,
746       'xwd' => 280,
747       'eml' => 281,
748       'igs' => 282,
749       'iges' => 282,
750       'silo' => 283,
751       'msh' => 283,
752       'mesh' => 283,
753       'icz' => 285,
754       'ics' => 285,
755       'css' => 286,
756       'csv' => 287,
757       '323' => 288,
758       'html' => 289,
759       'htm' => 289,
760       'shtml' => 289,
761       'uls' => 290,
762       'mml' => 291,
763       'txt' => 292,
764       'pot' => 292,
765       'text' => 292,
766       'asc' => 292,
767       'rtx' => 293,
768       'wsc' => 294,
769       'sct' => 294,
770       'tsv' => 295,
771       'ts' => 296,
772       'tm' => 296,
773       'jad' => 297,
774       'wml' => 298,
775       'wmls' => 299,
776       'bib' => 300,
777       'boo' => 301,
778       'hpp' => 302,
779       'hh' => 302,
780       'h++' => 302,
781       'hxx' => 302,
782       'cxx' => 303,
783       'cc' => 303,
784       'cpp' => 303,
785       'c++' => 303,
786       'h' => 304,
787       'htc' => 305,
788       'csh' => 306,
789       'c' => 307,
790       'patch' => 308,
791       'diff' => 308,
792       'd' => 309,
793       'hs' => 310,
794       'java' => 311,
795       'lhs' => 312,
796       'moc' => 313,
797       'pas' => 314,
798       'p' => 314,
799       'gcd' => 315,
800       'pm' => 316,
801       'pl' => 316,
802       'py' => 317,
803       'etx' => 318,
804       'sh' => 319,
805       'tk' => 320,
806       'tcl' => 320,
807       'cls' => 321,
808       'ltx' => 321,
809       'sty' => 321,
810       'tex' => 321,
811       'vcs' => 322,
812       'vcf' => 323,
813       '3gp' => 324,
814       'dl' => 325,
815       'dif' => 326,
816       'dv' => 326,
817       'fli' => 327,
818       'gl' => 328,
819       'mp4' => 329,
820       'f4v' => 329,
821       'f4p' => 329,
822       'mpe' => 330,
823       'mpeg' => 330,
824       'mpg' => 330,
825       'ogv' => 331,
826       'qt' => 332,
827       'mov' => 332,
828       'mxu' => 333,
829       'lsf' => 334,
830       'lsx' => 334,
831       'mng' => 335,
832       'asx' => 336,
833       'asf' => 336,
834       'wm' => 337,
835       'wmv' => 338,
836       'wmx' => 339,
837       'wvx' => 340,
838       'avi' => 341,
839       'movie' => 342,
840       'ice' => 343,
841       'sisx' => 344,
842       'wrl' => 345,
843       'vrm' => 345,
844       'vrml' => 345,
845       'f4a' => 346,
846       'f4b' => 346,
847       'flv' => 347,
848       'm4v' => 348,
849       'azw' => 349,
850       'epub' => 350,
851       'mobi' => 351,
852       'prc' => 352,
853       'mkv' => 353,
854       'mka' => 354,
855       'webp' => 355,
856       'weba' => 356,
857       'webm' => 357,
858       'vtt' => 358,
859     ],
860   ];
861
862   /**
863    * The MIME types mapping array after going through the module handler.
864    *
865    * @var array
866    */
867   protected $mapping;
868
869   /**
870    * The module handler.
871    *
872    * @var \Drupal\Core\Extension\ModuleHandlerInterface
873    */
874   protected $moduleHandler;
875
876   /**
877    * Constructs a new ExtensionMimeTypeGuesser.
878    *
879    * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
880    *   The module handler.
881    */
882   public function __construct(ModuleHandlerInterface $module_handler) {
883     $this->moduleHandler = $module_handler;
884   }
885
886   /**
887    * {@inheritdoc}
888    */
889   public function guess($path) {
890     if ($this->mapping === NULL) {
891       $mapping = $this->defaultMapping;
892       // Allow modules to alter the default mapping.
893       $this->moduleHandler->alter('file_mimetype_mapping', $mapping);
894       $this->mapping = $mapping;
895     }
896
897     $extension = '';
898     $file_parts = explode('.', drupal_basename($path));
899
900     // Remove the first part: a full filename should not match an extension.
901     array_shift($file_parts);
902
903     // Iterate over the file parts, trying to find a match.
904     // For my.awesome.image.jpeg, we try:
905     //   - jpeg
906     //   - image.jpeg, and
907     //   - awesome.image.jpeg
908     while ($additional_part = array_pop($file_parts)) {
909       $extension = strtolower($additional_part . ($extension ? '.' . $extension : ''));
910       if (isset($this->mapping['extensions'][$extension])) {
911         return $this->mapping['mimetypes'][$this->mapping['extensions'][$extension]];
912       }
913     }
914
915     return 'application/octet-stream';
916   }
917
918   /**
919    * Sets the mimetypes/extension mapping to use when guessing mimetype.
920    *
921    * @param array|null $mapping
922    *   Passing a NULL mapping will cause guess() to use self::$defaultMapping.
923    */
924   public function setMapping(array $mapping = NULL) {
925     $this->mapping = $mapping;
926   }
927
928 }