MimeResolver::getExtension()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 4
nc 4
nop 1
1
<?php
2
namespace AssetManager\Core\Service;
3
4
/**
5
 * File extension based MIME detector.
6
 */
7
class MimeResolver
8
{
9
    /**
10
     * Map for multiple extensions per mime-type, setting a main extension for the mime types.
11
     *
12
     * @var array
13
     */
14
    protected $mainMimeTypes = array(
15
        'css'       => 'text/css',
16
        'js'        => 'application/javascript',
17
    );
18
19
    /**
20
     * Map between file extensions and mime types.
21
     *
22
     * @var array
23
     */
24
    protected $mimeTypes = array(
25
        '%'        => 'application/x-trash',
26
        '3gp'      => 'video/3gpp',
27
        '7z'       => 'application/x-7z-compressed',
28
        'abw'      => 'application/x-abiword',
29
        'ai'       => 'application/postscript',
30
        'aif'      => 'audio/x-aiff',
31
        'aifc'     => 'audio/x-aiff',
32
        'aiff'     => 'audio/x-aiff',
33
        'alc'      => 'chemical/x-alchemy',
34
        'amr'      => 'audio/amr',
35
        'anx'      => 'application/annodex',
36
        'apk'      => 'application/vnd.android.package-archive',
37
        'art'      => 'image/x-jg',
38
        'asc'      => 'text/plain',
39
        'asf'      => 'video/x-ms-asf',
40
        'asn'      => 'chemical/x-ncbi-asn1-spec',
41
        'aso'      => 'chemical/x-ncbi-asn1-binary',
42
        'asx'      => 'video/x-ms-asf',
43
        'atom'     => 'application/atom+xml',
44
        'atomcat'  => 'application/atomcat+xml',
45
        'atomsrv'  => 'application/atomserv+xml',
46
        'au'       => 'audio/basic',
47
        'avi'      => 'video/x-msvideo',
48
        'awb'      => 'audio/amr-wb',
49
        'axa'      => 'audio/annodex',
50
        'axv'      => 'video/annodex',
51
        'b'        => 'chemical/x-molconn-Z',
52
        'bak'      => 'application/x-trash',
53
        'bat'      => 'application/x-msdos-program',
54
        'bcpio'    => 'application/x-bcpio',
55
        'bib'      => 'text/x-bibtex',
56
        'bin'      => 'application/octet-stream',
57
        'bmp'      => 'image/x-ms-bmp',
58
        'boo'      => 'text/x-boo',
59
        'book'     => 'application/x-maker',
60
        'brf'      => 'text/plain',
61
        'bsd'      => 'chemical/x-crossfire',
62
        'c'        => 'text/x-csrc',
63
        'c++'      => 'text/x-c++src',
64
        'c3d'      => 'chemical/x-chem3d',
65
        'cab'      => 'application/x-cab',
66
        'cac'      => 'chemical/x-cache',
67
        'cache'    => 'chemical/x-cache',
68
        'cap'      => 'application/cap',
69
        'cascii'   => 'chemical/x-cactvs-binary',
70
        'cat'      => 'application/vnd.ms-pki.seccat',
71
        'cbin'     => 'chemical/x-cactvs-binary',
72
        'cbr'      => 'application/x-cbr',
73
        'cbz'      => 'application/x-cbz',
74
        'cc'       => 'text/x-c++src',
75
        'cda'      => 'application/x-cdf',
76
        'cdf'      => 'application/x-cdf',
77
        'cdr'      => 'image/x-coreldraw',
78
        'cdt'      => 'image/x-coreldrawtemplate',
79
        'cdx'      => 'chemical/x-cdx',
80
        'cdy'      => 'application/vnd.cinderella',
81
        'cef'      => 'chemical/x-cxf',
82
        'cer'      => 'chemical/x-cerius',
83
        'chm'      => 'chemical/x-chemdraw',
84
        'chrt'     => 'application/x-kchart',
85
        'cif'      => 'chemical/x-cif',
86
        'class'    => 'application/java-vm',
87
        'cls'      => 'text/x-tex',
88
        'cmdf'     => 'chemical/x-cmdf',
89
        'cml'      => 'chemical/x-cml',
90
        'cod'      => 'application/vnd.rim.cod',
91
        'coffee'   => 'application/vnd.coffeescript',
92
        'com'      => 'application/x-msdos-program',
93
        'cpa'      => 'chemical/x-compass',
94
        'cpio'     => 'application/x-cpio',
95
        'cpp'      => 'text/x-c++src',
96
        'cpt'      => 'image/x-corelphotopaint',
97
        'cr2'      => 'image/x-canon-cr2',
98
        'crl'      => 'application/x-pkcs7-crl',
99
        'crt'      => 'application/x-x509-ca-cert',
100
        'crw'      => 'image/x-canon-crw',
101
        'csd'      => 'audio/csound',
102
        'csf'      => 'chemical/x-cache-csf',
103
        'csh'      => 'text/x-csh',
104
        'csm'      => 'chemical/x-csml',
105
        'csml'     => 'chemical/x-csml',
106
        'css'      => 'text/css',
107
        'csv'      => 'text/csv',
108
        'ctab'     => 'chemical/x-cactvs-binary',
109
        'ctx'      => 'chemical/x-ctx',
110
        'cu'       => 'application/cu-seeme',
111
        'cub'      => 'chemical/x-gaussian-cube',
112
        'cxf'      => 'chemical/x-cxf',
113
        'cxx'      => 'text/x-c++src',
114
        'd'        => 'text/x-dsrc',
115
        'dat'      => 'application/x-ns-proxy-autoconfig',
116
        'davmount' => 'application/davmount+xml',
117
        'dcr'      => 'application/x-director',
118
        'deb'      => 'application/x-debian-package',
119
        'dif'      => 'video/dv',
120
        'diff'     => 'text/x-diff',
121
        'dir'      => 'application/x-director',
122
        'djv'      => 'image/vnd.djvu',
123
        'djvu'     => 'image/vnd.djvu',
124
        'dl'       => 'video/dl',
125
        'dll'      => 'application/x-msdos-program',
126
        'dmg'      => 'application/x-apple-diskimage',
127
        'dms'      => 'application/x-dms',
128
        'doc'      => 'application/msword',
129
        'docm'     => 'application/vnd.ms-word.document.macroEnabled.12',
130
        'docx'     => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
131
        'dot'      => 'application/msword',
132
        'dotm'     => 'application/vnd.ms-word.template.macroEnabled.12',
133
        'dotx'     => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
134
        'dv'       => 'video/dv',
135
        'dvi'      => 'application/x-dvi',
136
        'dx'       => 'chemical/x-jcamp-dx',
137
        'dxr'      => 'application/x-director',
138
        'emb'      => 'chemical/x-embl-dl-nucleotide',
139
        'embl'     => 'chemical/x-embl-dl-nucleotide',
140
        'eml'      => 'message/rfc822',
141
        'ent'      => 'chemical/x-pdb',
142
        'eot'      => 'application/vnd.ms-fontobject',
143
        'eps'      => 'application/postscript',
144
        'eps2'     => 'application/postscript',
145
        'eps3'     => 'application/postscript',
146
        'epsf'     => 'application/postscript',
147
        'epsi'     => 'application/postscript',
148
        'erf'      => 'image/x-epson-erf',
149
        'es'       => 'application/ecmascript',
150
        'etx'      => 'text/x-setext',
151
        'exe'      => 'application/x-msdos-program',
152
        'ez'       => 'application/andrew-inset',
153
        'f4a'      => 'audio/mp4',
154
        'f4b'      => 'audio/mp4',
155
        'f4v'      => 'video/mp4',
156
        'f4p'      => 'video/mp4',
157
        'fb'       => 'application/x-maker',
158
        'fbdoc'    => 'application/x-maker',
159
        'fch'      => 'chemical/x-gaussian-checkpoint',
160
        'fchk'     => 'chemical/x-gaussian-checkpoint',
161
        'fig'      => 'application/x-xfig',
162
        'flac'     => 'audio/flac',
163
        'fli'      => 'video/fli',
164
        'flv'      => 'video/x-flv',
165
        'fm'       => 'application/x-maker',
166
        'frame'    => 'application/x-maker',
167
        'frm'      => 'application/x-maker',
168
        'gal'      => 'chemical/x-gaussian-log',
169
        'gam'      => 'chemical/x-gamess-input',
170
        'gamin'    => 'chemical/x-gamess-input',
171
        'gan'      => 'application/x-ganttproject',
172
        'gau'      => 'chemical/x-gaussian-input',
173
        'gcd'      => 'text/x-pcs-gcd',
174
        'gcf'      => 'application/x-graphing-calculator',
175
        'gcg'      => 'chemical/x-gcg8-sequence',
176
        'gen'      => 'chemical/x-genbank',
177
        'gf'       => 'application/x-tex-gf',
178
        'gif'      => 'image/gif',
179
        'gjc'      => 'chemical/x-gaussian-input',
180
        'gjf'      => 'chemical/x-gaussian-input',
181
        'gl'       => 'video/gl',
182
        'gnumeric' => 'application/x-gnumeric',
183
        'gpt'      => 'chemical/x-mopac-graph',
184
        'gsf'      => 'application/x-font',
185
        'gsm'      => 'audio/x-gsm',
186
        'gtar'     => 'application/x-gtar',
187
        'h'        => 'text/x-chdr',
188
        'h++'      => 'text/x-c++hdr',
189
        'hdf'      => 'application/x-hdf',
190
        'hh'       => 'text/x-c++hdr',
191
        'hin'      => 'chemical/x-hin',
192
        'hpp'      => 'text/x-c++hdr',
193
        'hqx'      => 'application/mac-binhex40',
194
        'hs'       => 'text/x-haskell',
195
        'hta'      => 'application/hta',
196
        'htc'      => 'text/x-component',
197
        'htm'      => 'text/html',
198
        'html'     => 'text/html',
199
        'hxx'      => 'text/x-c++hdr',
200
        'ica'      => 'application/x-ica',
201
        'ice'      => 'x-conference/x-cooltalk',
202
        'ico'      => 'image/x-icon',
203
        'ics'      => 'text/calendar',
204
        'icz'      => 'text/calendar',
205
        'ief'      => 'image/ief',
206
        'iges'     => 'model/iges',
207
        'igs'      => 'model/iges',
208
        'iii'      => 'application/x-iphone',
209
        'info'     => 'application/x-info',
210
        'inp'      => 'chemical/x-gamess-input',
211
        'ins'      => 'application/x-internet-signup',
212
        'iso'      => 'application/x-iso9660-image',
213
        'isp'      => 'application/x-internet-signup',
214
        'ist'      => 'chemical/x-isostar',
215
        'istr'     => 'chemical/x-isostar',
216
        'jad'      => 'text/vnd.sun.j2me.app-descriptor',
217
        'jam'      => 'application/x-jam',
218
        'jar'      => 'application/java-archive',
219
        'java'     => 'text/x-java',
220
        'jdx'      => 'chemical/x-jcamp-dx',
221
        'jmz'      => 'application/x-jmol',
222
        'jng'      => 'image/x-jng',
223
        'jnlp'     => 'application/x-java-jnlp-file',
224
        'jpe'      => 'image/jpeg',
225
        'jpeg'     => 'image/jpeg',
226
        'jpg'      => 'image/jpeg',
227
        'js'       => 'application/javascript',
228
        'json'     => 'application/json',
229
        'kar'      => 'audio/midi',
230
        'key'      => 'application/pgp-keys',
231
        'kil'      => 'application/x-killustrator',
232
        'kin'      => 'chemical/x-kinemage',
233
        'kml'      => 'application/vnd.google-earth.kml+xml',
234
        'kmz'      => 'application/vnd.google-earth.kmz',
235
        'kpr'      => 'application/x-kpresenter',
236
        'kpt'      => 'application/x-kpresenter',
237
        'ksp'      => 'application/x-kspread',
238
        'kwd'      => 'application/x-kword',
239
        'kwt'      => 'application/x-kword',
240
        'latex'    => 'application/x-latex',
241
        'less'     => 'text/less',
242
        'lha'      => 'application/x-lha',
243
        'lhs'      => 'text/x-literate-haskell',
244
        'lin'      => 'application/bbolin',
245
        'lsf'      => 'video/x-la-asf',
246
        'lsx'      => 'video/x-la-asf',
247
        'ltx'      => 'text/x-tex',
248
        'lyx'      => 'application/x-lyx',
249
        'lzh'      => 'application/x-lzh',
250
        'lzx'      => 'application/x-lzx',
251
        'm3g'      => 'application/m3g',
252
        'm3u'      => 'audio/x-mpegurl',
253
        'm3u8'     => 'application/x-mpegURL',
254
        'm4a'      => 'audio/mpeg',
255
        'maker'    => 'application/x-maker',
256
        'man'      => 'application/x-troff-man',
257
        'manifest' => 'text/cache-manifest',
258
        'mcif'     => 'chemical/x-mmcif',
259
        'mcm'      => 'chemical/x-macmolecule',
260
        'mdb'      => 'application/msaccess',
261
        'me'       => 'application/x-troff-me',
262
        'mesh'     => 'model/mesh',
263
        'mid'      => 'audio/midi',
264
        'midi'     => 'audio/midi',
265
        'mif'      => 'application/x-mif',
266
        'mkv'      => 'video/x-matroska',
267
        'mm'       => 'application/x-freemind',
268
        'mmd'      => 'chemical/x-macromodel-input',
269
        'mmf'      => 'application/vnd.smaf',
270
        'mml'      => 'text/mathml',
271
        'mmod'     => 'chemical/x-macromodel-input',
272
        'mng'      => 'video/x-mng',
273
        'moc'      => 'text/x-moc',
274
        'mol'      => 'chemical/x-mdl-molfile',
275
        'mol2'     => 'chemical/x-mol2',
276
        'moo'      => 'chemical/x-mopac-out',
277
        'mop'      => 'chemical/x-mopac-input',
278
        'mopcrt'   => 'chemical/x-mopac-input',
279
        'mov'      => 'video/quicktime',
280
        'movie'    => 'video/x-sgi-movie',
281
        'mp2'      => 'audio/mpeg',
282
        'mp3'      => 'audio/mpeg',
283
        'mp4'      => 'video/mp4',
284
        'mpc'      => 'chemical/x-mopac-input',
285
        'mpe'      => 'video/mpeg',
286
        'mpeg'     => 'video/mpeg',
287
        'mpega'    => 'audio/mpeg',
288
        'mpg'      => 'video/mpeg',
289
        'mpga'     => 'audio/mpeg',
290
        'mph'      => 'application/x-comsol',
291
        'mpv'      => 'video/x-matroska',
292
        'ms'       => 'application/x-troff-ms',
293
        'msh'      => 'model/mesh',
294
        'msi'      => 'application/x-msi',
295
        'mvb'      => 'chemical/x-mopac-vib',
296
        'mxf'      => 'application/mxf',
297
        'mxu'      => 'video/vnd.mpegurl',
298
        'nb'       => 'application/mathematica',
299
        'nbp'      => 'application/mathematica',
300
        'nc'       => 'application/x-netcdf',
301
        'nef'      => 'image/x-nikon-nef',
302
        'nwc'      => 'application/x-nwc',
303
        'o'        => 'application/x-object',
304
        'oda'      => 'application/oda',
305
        'odb'      => 'application/vnd.oasis.opendocument.database',
306
        'odc'      => 'application/vnd.oasis.opendocument.chart',
307
        'odf'      => 'application/vnd.oasis.opendocument.formula',
308
        'odg'      => 'application/vnd.oasis.opendocument.graphics',
309
        'odi'      => 'application/vnd.oasis.opendocument.image',
310
        'odm'      => 'application/vnd.oasis.opendocument.text-master',
311
        'odp'      => 'application/vnd.oasis.opendocument.presentation',
312
        'ods'      => 'application/vnd.oasis.opendocument.spreadsheet',
313
        'odt'      => 'application/vnd.oasis.opendocument.text',
314
        'oga'      => 'audio/ogg',
315
        'ogg'      => 'audio/ogg',
316
        'ogv'      => 'video/ogg',
317
        'ogx'      => 'application/ogg',
318
        'old'      => 'application/x-trash',
319
        'one'      => 'application/onenote',
320
        'onepkg'   => 'application/onenote',
321
        'onetmp'   => 'application/onenote',
322
        'onetoc2'  => 'application/onenote',
323
        'orc'      => 'audio/csound',
324
        'orf'      => 'image/x-olympus-orf',
325
        'otf'      => 'application/x-font-opentype',
326
        'otg'      => 'application/vnd.oasis.opendocument.graphics-template',
327
        'oth'      => 'application/vnd.oasis.opendocument.text-web',
328
        'otp'      => 'application/vnd.oasis.opendocument.presentation-template',
329
        'ots'      => 'application/vnd.oasis.opendocument.spreadsheet-template',
330
        'ott'      => 'application/vnd.oasis.opendocument.text-template',
331
        'oza'      => 'application/x-oz-application',
332
        'p'        => 'text/x-pascal',
333
        'p7r'      => 'application/x-pkcs7-certreqresp',
334
        'pac'      => 'application/x-ns-proxy-autoconfig',
335
        'pas'      => 'text/x-pascal',
336
        'pat'      => 'image/x-coreldrawpattern',
337
        'patch'    => 'text/x-diff',
338
        'pbm'      => 'image/x-portable-bitmap',
339
        'pcap'     => 'application/cap',
340
        'pcf'      => 'application/x-font',
341
        'pcf.Z'    => 'application/x-font',
342
        'pcx'      => 'image/pcx',
343
        'pdb'      => 'chemical/x-pdb',
344
        'pdf'      => 'application/pdf',
345
        'pfa'      => 'application/x-font',
346
        'pfb'      => 'application/x-font',
347
        'pgm'      => 'image/x-portable-graymap',
348
        'pgn'      => 'application/x-chess-pgn',
349
        'pgp'      => 'application/pgp-signature',
350
        'php'      => 'application/x-httpd-php',
351
        'php3'     => 'application/x-httpd-php3',
352
        'php3p'    => 'application/x-httpd-php3-preprocessed',
353
        'php4'     => 'application/x-httpd-php4',
354
        'php5'     => 'application/x-httpd-php5',
355
        'phps'     => 'application/x-httpd-php-source',
356
        'pht'      => 'application/x-httpd-php',
357
        'phtml'    => 'application/x-httpd-php',
358
        'pk'       => 'application/x-tex-pk',
359
        'pl'       => 'text/x-perl',
360
        'pls'      => 'audio/x-scpls',
361
        'pm'       => 'text/x-perl',
362
        'png'      => 'image/png',
363
        'pnm'      => 'image/x-portable-anymap',
364
        'pot'      => 'text/plain',
365
        'potm'     => 'application/vnd.ms-powerpoint.template.macroEnabled.12',
366
        'potx'     => 'application/vnd.openxmlformats-officedocument.presentationml.template',
367
        'ppam'     => 'application/vnd.ms-powerpoint.addin.macroEnabled.12',
368
        'ppm'      => 'image/x-portable-pixmap',
369
        'pps'      => 'application/vnd.ms-powerpoint',
370
        'ppsm'     => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12',
371
        'ppsx'     => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
372
        'ppt'      => 'application/vnd.ms-powerpoint',
373
        'pptm'     => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
374
        'pptx'     => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
375
        'prf'      => 'application/pics-rules',
376
        'prt'      => 'chemical/x-ncbi-asn1-ascii',
377
        'ps'       => 'application/postscript',
378
        'psd'      => 'image/x-photoshop',
379
        'py'       => 'text/x-python',
380
        'pyc'      => 'application/x-python-code',
381
        'pyo'      => 'application/x-python-code',
382
        'qgs'      => 'application/x-qgis',
383
        'qt'       => 'video/quicktime',
384
        'qtl'      => 'application/x-quicktimeplayer',
385
        'ra'       => 'audio/x-realaudio',
386
        'ram'      => 'audio/x-pn-realaudio',
387
        'rar'      => 'application/rar',
388
        'ras'      => 'image/x-cmu-raster',
389
        'rb'       => 'application/x-ruby',
390
        'rd'       => 'chemical/x-mdl-rdfile',
391
        'rdf'      => 'application/rdf+xml',
392
        'rdp'      => 'application/x-rdp',
393
        'rgb'      => 'image/x-rgb',
394
        'rhtml'    => 'application/x-httpd-eruby',
395
        'rm'       => 'audio/x-pn-realaudio',
396
        'roff'     => 'application/x-troff',
397
        'ros'      => 'chemical/x-rosdal',
398
        'rpm'      => 'application/x-redhat-package-manager',
399
        'rss'      => 'application/rss+xml',
400
        'rtf'      => 'application/rtf',
401
        'rtx'      => 'text/richtext',
402
        'rxn'      => 'chemical/x-mdl-rxnfile',
403
        'sass'     => 'text/css',
404
        'scala'    => 'text/x-scala',
405
        'sce'      => 'application/x-scilab',
406
        'sci'      => 'application/x-scilab',
407
        'sco'      => 'audio/csound',
408
        'scr'      => 'application/x-silverlight',
409
        'scss'     => 'text/scss',
410
        'sct'      => 'text/scriptlet',
411
        'sd'       => 'chemical/x-mdl-sdfile',
412
        'sd2'      => 'audio/x-sd2',
413
        'sda'      => 'application/vnd.stardivision.draw',
414
        'sdc'      => 'application/vnd.stardivision.calc',
415
        'sdd'      => 'application/vnd.stardivision.impress',
416
        'sdf'      => 'chemical/x-mdl-sdfile',
417
        'sds'      => 'application/vnd.stardivision.chart',
418
        'sdw'      => 'application/vnd.stardivision.writer',
419
        'ser'      => 'application/java-serialized-object',
420
        'sfv'      => 'text/x-sfv',
421
        'sgf'      => 'application/x-go-sgf',
422
        'sgl'      => 'application/vnd.stardivision.writer-global',
423
        'sh'       => 'text/x-sh',
424
        'shar'     => 'application/x-shar',
425
        'shp'      => 'application/x-qgis',
426
        'shtml'    => 'text/html',
427
        'shx'      => 'application/x-qgis',
428
        'sid'      => 'audio/prs.sid',
429
        'sik'      => 'application/x-trash',
430
        'silo'     => 'model/mesh',
431
        'sis'      => 'application/vnd.symbian.install',
432
        'sisx'     => 'x-epoc/x-sisx-app',
433
        'sit'      => 'application/x-stuffit',
434
        'sitx'     => 'application/x-stuffit',
435
        'skd'      => 'application/x-koan',
436
        'skm'      => 'application/x-koan',
437
        'skp'      => 'application/x-koan',
438
        'skt'      => 'application/x-koan',
439
        'sldm'     => 'application/vnd.ms-powerpoint.slide.macroEnabled.12',
440
        'sldx'     => 'application/vnd.openxmlformats-officedocument.presentationml.slide',
441
        'smi'      => 'application/smil',
442
        'smil'     => 'application/smil',
443
        'snd'      => 'audio/basic',
444
        'spc'      => 'chemical/x-galactic-spc',
445
        'spl'      => 'application/x-futuresplash',
446
        'spx'      => 'audio/ogg',
447
        'sql'      => 'application/x-sql',
448
        'src'      => 'application/x-wais-source',
449
        'stc'      => 'application/vnd.sun.xml.calc.template',
450
        'std'      => 'application/vnd.sun.xml.draw.template',
451
        'sti'      => 'application/vnd.sun.xml.impress.template',
452
        'stl'      => 'application/sla',
453
        'stw'      => 'application/vnd.sun.xml.writer.template',
454
        'sty'      => 'text/x-tex',
455
        'sv4cpio'  => 'application/x-sv4cpio',
456
        'sv4crc'   => 'application/x-sv4crc',
457
        'svg'      => 'image/svg+xml',
458
        'svgz'     => 'image/svg+xml',
459
        'sw'       => 'chemical/x-swissprot',
460
        'swf'      => 'application/x-shockwave-flash',
461
        'swfl'     => 'application/x-shockwave-flash',
462
        'sxc'      => 'application/vnd.sun.xml.calc',
463
        'sxd'      => 'application/vnd.sun.xml.draw',
464
        'sxg'      => 'application/vnd.sun.xml.writer.global',
465
        'sxi'      => 'application/vnd.sun.xml.impress',
466
        'sxm'      => 'application/vnd.sun.xml.math',
467
        'sxw'      => 'application/vnd.sun.xml.writer',
468
        't'        => 'application/x-troff',
469
        'tar'      => 'application/x-tar',
470
        'taz'      => 'application/x-gtar-compressed',
471
        'tcl'      => 'text/x-tcl',
472
        'tex'      => 'text/x-tex',
473
        'texi'     => 'application/x-texinfo',
474
        'texinfo'  => 'application/x-texinfo',
475
        'text'     => 'text/plain',
476
        'tgf'      => 'chemical/x-mdl-tgf',
477
        'tgz'      => 'application/x-gtar-compressed',
478
        'thmx'     => 'application/vnd.ms-officetheme',
479
        'tif'      => 'image/tiff',
480
        'tiff'     => 'image/tiff',
481
        'tk'       => 'text/x-tcl',
482
        'tm'       => 'text/texmacs',
483
        'torrent'  => 'application/x-bittorrent',
484
        'tr'       => 'application/x-troff',
485
        'ts'       => 'video/MP2T',
486
        'tsp'      => 'application/dsptype',
487
        'tsv'      => 'text/tab-separated-values',
488
        'ttf'      => 'application/x-font-ttf',
489
        'txt'      => 'text/plain',
490
        'udeb'     => 'application/x-debian-package',
491
        'uls'      => 'text/iuls',
492
        'ustar'    => 'application/x-ustar',
493
        'val'      => 'chemical/x-ncbi-asn1-binary',
494
        'vcd'      => 'application/x-cdlink',
495
        'vcf'      => 'text/x-vcard',
496
        'vcs'      => 'text/x-vcalendar',
497
        'vmd'      => 'chemical/x-vmd',
498
        'vms'      => 'chemical/x-vamas-iso14976',
499
        'vrm'      => 'x-world/x-vrml',
500
        'vrml'     => 'x-world/x-vrml',
501
        'vsd'      => 'application/vnd.visio',
502
        'wad'      => 'application/x-doom',
503
        'wav'      => 'audio/x-wav',
504
        'wax'      => 'audio/x-ms-wax',
505
        'wbmp'     => 'image/vnd.wap.wbmp',
506
        'wbxml'    => 'application/vnd.wap.wbxml',
507
        'webm'     => 'video/webm',
508
        'wk'       => 'application/x-123',
509
        'wm'       => 'video/x-ms-wm',
510
        'wma'      => 'audio/x-ms-wma',
511
        'wmd'      => 'application/x-ms-wmd',
512
        'wml'      => 'text/vnd.wap.wml',
513
        'wmlc'     => 'application/vnd.wap.wmlc',
514
        'wmls'     => 'text/vnd.wap.wmlscript',
515
        'wmlsc'    => 'application/vnd.wap.wmlscriptc',
516
        'wmv'      => 'video/x-ms-wmv',
517
        'wmx'      => 'video/x-ms-wmx',
518
        'wmz'      => 'application/x-ms-wmz',
519
        'woff'     => 'application/x-font-woff',
520
        'wp5'      => 'application/vnd.wordperfect5.1',
521
        'wpd'      => 'application/vnd.wordperfect',
522
        'wrl'      => 'x-world/x-vrml',
523
        'wsc'      => 'text/scriptlet',
524
        'wvx'      => 'video/x-ms-wvx',
525
        'wz'       => 'application/x-wingz',
526
        'x3d'      => 'model/x3d+xml',
527
        'x3db'     => 'model/x3d+binary',
528
        'x3dv'     => 'model/x3d+vrml',
529
        'xbm'      => 'image/x-xbitmap',
530
        'xcf'      => 'application/x-xcf',
531
        'xht'      => 'application/xhtml+xml',
532
        'xhtml'    => 'application/xhtml+xml',
533
        'xlam'     => 'application/vnd.ms-excel.addin.macroEnabled.12',
534
        'xlb'      => 'application/vnd.ms-excel',
535
        'xls'      => 'application/vnd.ms-excel',
536
        'xlsb'     => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
537
        'xlsm'     => 'application/vnd.ms-excel.sheet.macroEnabled.12',
538
        'xlsx'     => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
539
        'xlt'      => 'application/vnd.ms-excel',
540
        'xltm'     => 'application/vnd.ms-excel.template.macroEnabled.12',
541
        'xltx'     => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
542
        'xml'      => 'application/xml',
543
        'xpi'      => 'application/x-xpinstall',
544
        'xpm'      => 'image/x-xpixmap',
545
        'xsd'      => 'application/xml',
546
        'xsl'      => 'application/xml',
547
        'xspf'     => 'application/xspf+xml',
548
        'xtel'     => 'chemical/x-xtel',
549
        'xul'      => 'application/vnd.mozilla.xul+xml',
550
        'xwd'      => 'image/x-xwindowdump',
551
        'xyz'      => 'chemical/x-xyz',
552
        'zip'      => 'application/zip',
553
        'zmt'      => 'chemical/x-mopac-input',
554
        '~'        => 'application/x-trash',
555
        '323'      => 'text/h323',
556
    );
557
558
    /**
559
     * Get the mime type from a file extension.
560
     *
561
     * @param  string $filename
562
     * @return string The mime type found. Falls back to text/plain.
563
     */
564
    public function getMimeType($filename)
565
    {
566
        $extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
567
568
        if (isset($this->mimeTypes[$extension])) {
569
            return $this->mimeTypes[$extension];
570
        }
571
572
        return 'text/plain';
573
    }
574
575
    /**
576
     * Get the extension that matches given mimetype.
577
     *
578
     * @param  string $mimetype
579
     * @return mixed  null when not found, extension (string) when found.
580
     */
581
    public function getExtension($mimetype)
582
    {
583
        if (!($extension = array_search($mimetype, $this->mainMimeTypes))) {
584
            $extension = array_search($mimetype, $this->mimeTypes);
585
        }
586
587
        return !$extension ? null : $extension;
588
    }
589
}
590