Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
extension_guesser
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
3 / 3
4
100.00% covered (success)
100.00%
1 / 1
 is_supported
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 guess
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 map_extension_to_type
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3*
4* This file is part of the phpBB Forum Software package.
5*
6* @copyright (c) phpBB Limited <https://www.phpbb.com>
7* @license GNU General Public License, version 2 (GPL-2.0)
8*
9* For full copyright and license information, please see
10* the docs/CREDITS.txt file.
11*
12*/
13
14namespace phpbb\mimetype;
15
16class extension_guesser extends guesser_base
17{
18    /**
19    * @var array file extension map
20    */
21    protected $extension_map = array(
22        '3dm'        => 'x-world/x-3dmf',
23        '3dmf'        => 'x-world/x-3dmf',
24        'a'        => 'application/octet-stream',
25        'aab'        => 'application/x-authorware-bin',
26        'aam'        => 'application/x-authorware-map',
27        'aas'        => 'application/x-authorware-seg',
28        'abc'        => 'text/vnd.abc',
29        'acgi'        => 'text/html',
30        'afl'        => 'video/animaflex',
31        'ai'        => 'application/postscript',
32        'aif'        => 'audio/aiff',
33        'aifc'        => 'audio/aiff',
34        'aiff'        => 'audio/aiff',
35        'aim'        => 'application/x-aim',
36        'aip'        => 'text/x-audiosoft-intra',
37        'ani'        => 'application/x-navi-animation',
38        'aos'        => 'application/x-nokia-9000-communicator-add-on-software',
39        'aps'        => 'application/mime',
40        'arc'        => 'application/octet-stream',
41        'arj'        => 'application/arj',
42        'art'        => 'image/x-jg',
43        'asf'        => 'video/x-ms-asf',
44        'asm'        => 'text/x-asm',
45        'asp'        => 'text/asp',
46        'asx'        => 'video/x-ms-asf',
47        'au'        => 'audio/x-au',
48        'avi'        => 'video/avi',
49        'avs'        => 'video/avs-video',
50        'bcpio'        => 'application/x-bcpio',
51        'bin'        => 'application/x-binary',
52        'bm'        => 'image/bmp',
53        'bmp'        => 'image/bmp',
54        'boo'        => 'application/book',
55        'book'        => 'application/book',
56        'boz'        => 'application/x-bzip2',
57        'bsh'        => 'application/x-bsh',
58        'bz'        => 'application/x-bzip',
59        'bz2'        => 'application/x-bzip2',
60        'c'        => 'text/x-c',
61        'c++'        => 'text/x-c',
62        'cat'        => 'application/vnd.ms-pki.seccat',
63        'cc'        => 'text/plain',
64        'ccad'        => 'application/clariscad',
65        'cco'        => 'application/x-cocoa',
66        'cdf'        => 'application/cdf',
67        'cer'        => 'application/x-x509-ca-cert',
68        'cha'        => 'application/x-chat',
69        'chat'        => 'application/x-chat',
70        'class'        => 'application/java',
71        'com'        => 'application/octet-stream',
72        'conf'        => 'text/plain',
73        'cpio'        => 'application/x-cpio',
74        'cpp'        => 'text/x-c',
75        'cpt'        => 'application/x-cpt',
76        'crl'        => 'application/pkix-crl',
77        'crt'        => 'application/x-x509-ca-cert',
78        'csh'        => 'application/x-csh',
79        'css'        => 'text/css',
80        'cxx'        => 'text/plain',
81        'dcr'        => 'application/x-director',
82        'deepv'        => 'application/x-deepv',
83        'def'        => 'text/plain',
84        'der'        => 'application/x-x509-ca-cert',
85        'dif'        => 'video/x-dv',
86        'dir'        => 'application/x-director',
87        'dl'        => 'video/dl',
88        'doc'        => 'application/msword',
89        'dot'        => 'application/msword',
90        'dp'        => 'application/commonground',
91        'drw'        => 'application/drafting',
92        'dump'        => 'application/octet-stream',
93        'dv'        => 'video/x-dv',
94        'dvi'        => 'application/x-dvi',
95        'dwf'        => 'model/vnd.dwf',
96        'dwg'        => 'image/x-dwg',
97        'dxf'        => 'image/x-dwg',
98        'dxr'        => 'application/x-director',
99        'el'        => 'text/x-script.elisp',
100        'elc'        => 'application/x-elc',
101        'env'        => 'application/x-envoy',
102        'eps'        => 'application/postscript',
103        'es'        => 'application/x-esrehber',
104        'etx'        => 'text/x-setext',
105        'evy'        => 'application/x-envoy',
106        'exe'        => 'application/octet-stream',
107        'f'        => 'text/x-fortran',
108        'f77'        => 'text/x-fortran',
109        'f90'        => 'text/x-fortran',
110        'fdf'        => 'application/vnd.fdf',
111        'fif'        => 'image/fif',
112        'fli'        => 'video/x-fli',
113        'flo'        => 'image/florian',
114        'flx'        => 'text/vnd.fmi.flexstor',
115        'fmf'        => 'video/x-atomic3d-feature',
116        'for'        => 'text/x-fortran',
117        'fpx'        => 'image/vnd.fpx',
118        'frl'        => 'application/freeloader',
119        'funk'        => 'audio/make',
120        'g'        => 'text/plain',
121        'g3'        => 'image/g3fax',
122        'gif'        => 'image/gif',
123        'gl'        => 'video/x-gl',
124        'gsd'        => 'audio/x-gsm',
125        'gsm'        => 'audio/x-gsm',
126        'gsp'        => 'application/x-gsp',
127        'gss'        => 'application/x-gss',
128        'gtar'        => 'application/x-gtar',
129        'gz'        => 'application/x-gzip',
130        'gzip'        => 'application/x-gzip',
131        'h'        => 'text/x-h',
132        'hdf'        => 'application/x-hdf',
133        'help'        => 'application/x-helpfile',
134        'hgl'        => 'application/vnd.hp-hpgl',
135        'hh'        => 'text/x-h',
136        'hlb'        => 'text/x-script',
137        'hlp'        => 'application/hlp',
138        'hpg'        => 'application/vnd.hp-hpgl',
139        'hpgl'        => 'application/vnd.hp-hpgl',
140        'hqx'        => 'application/x-binhex40',
141        'hta'        => 'application/hta',
142        'htc'        => 'text/x-component',
143        'htm'        => 'text/html',
144        'html'        => 'text/html',
145        'htmls'        => 'text/html',
146        'htt'        => 'text/webviewhtml',
147        'htx'        => 'text/html',
148        'ice'        => 'x-conference/x-cooltalk',
149        'ico'        => 'image/x-icon',
150        'idc'        => 'text/plain',
151        'ief'        => 'image/ief',
152        'iefs'        => 'image/ief',
153        'iges'        => 'application/iges',
154        'igs'        => 'application/iges',
155        'ima'        => 'application/x-ima',
156        'imap'        => 'application/x-httpd-imap',
157        'inf'        => 'application/inf',
158        'ins'        => 'application/x-internett-signup',
159        'ip'        => 'application/x-ip2',
160        'isu'        => 'video/x-isvideo',
161        'it'        => 'audio/it',
162        'iv'        => 'application/x-inventor',
163        'ivr'        => 'i-world/i-vrml',
164        'ivy'        => 'application/x-livescreen',
165        'jam'        => 'audio/x-jam',
166        'jav'        => 'text/x-java-source',
167        'java'        => 'text/x-java-source',
168        'jcm'        => 'application/x-java-commerce',
169        'jfif'        => 'image/jpeg',
170        'jfif-tbnl'    => 'image/jpeg',
171        'jpe'        => 'image/jpeg',
172        'jpeg'        => 'image/jpeg',
173        'jpg'        => 'image/jpeg',
174        'jps'        => 'image/x-jps',
175        'js'        => 'application/x-javascript',
176        'jut'        => 'image/jutvision',
177        'kar'        => 'audio/midi',
178        'ksh'        => 'text/x-script.ksh',
179        'la'        => 'audio/x-nspaudio',
180        'lam'        => 'audio/x-liveaudio',
181        'latex'        => 'application/x-latex',
182        'lha'        => 'application/x-lha',
183        'lhx'        => 'application/octet-stream',
184        'list'        => 'text/plain',
185        'lma'        => 'audio/x-nspaudio',
186        'log'        => 'text/plain',
187        'lsp'        => 'text/x-script.lisp',
188        'lst'        => 'text/plain',
189        'lsx'        => 'text/x-la-asf',
190        'ltx'        => 'application/x-latex',
191        'lzh'        => 'application/x-lzh',
192        'lzx'        => 'application/x-lzx',
193        'm'        => 'text/x-m',
194        'm1v'        => 'video/mpeg',
195        'm2a'        => 'audio/mpeg',
196        'm2v'        => 'video/mpeg',
197        'm3u'        => 'audio/x-mpequrl',
198        'm4a'        => 'audio/mp4',
199        'm4v'        => 'video/mp4',
200        'man'        => 'application/x-troff-man',
201        'map'        => 'application/x-navimap',
202        'mar'        => 'text/plain',
203        'mbd'        => 'application/mbedlet',
204        'mc$'        => 'application/x-magic-cap-package-1.0',
205        'mcd'        => 'application/x-mathcad',
206        'mcf'        => 'text/mcf',
207        'mcp'        => 'application/netmc',
208        'me'        => 'application/x-troff-me',
209        'mht'        => 'message/rfc822',
210        'mhtml'        => 'message/rfc822',
211        'mid'        => 'audio/x-midi',
212        'midi'        => 'audio/x-midi',
213        'mif'        => 'application/x-mif',
214        'mime'        => 'www/mime',
215        'mjf'        => 'audio/x-vnd.audioexplosion.mjuicemediafile',
216        'mjpg'        => 'video/x-motion-jpeg',
217        'mm'        => 'application/x-meme',
218        'mme'        => 'application/base64',
219        'mod'        => 'audio/x-mod',
220        'moov'        => 'video/quicktime',
221        'mov'        => 'video/quicktime',
222        'movie'        => 'video/x-sgi-movie',
223        'mp2'        => 'audio/x-mpeg',
224        'mp3'        => 'audio/mpeg',
225        'mp4'        => 'video/mp4',
226        'mpa'        => 'audio/mpeg',
227        'mpc'        => 'application/x-project',
228        'mpe'        => 'video/mpeg',
229        'mpeg'        => 'video/mpeg',
230        'mpg'        => 'video/mpeg',
231        'mpga'        => 'audio/mpeg',
232        'mpp'        => 'application/vnd.ms-project',
233        'mpt'        => 'application/x-project',
234        'mpv'        => 'application/x-project',
235        'mpx'        => 'application/x-project',
236        'mrc'        => 'application/marc',
237        'ms'        => 'application/x-troff-ms',
238        'mv'        => 'video/x-sgi-movie',
239        'my'        => 'audio/make',
240        'mzz'        => 'application/x-vnd.audioexplosion.mzz',
241        'nap'        => 'image/naplps',
242        'naplps'    => 'image/naplps',
243        'nc'        => 'application/x-netcdf',
244        'ncm'        => 'application/vnd.nokia.configuration-message',
245        'nif'        => 'image/x-niff',
246        'niff'        => 'image/x-niff',
247        'nix'        => 'application/x-mix-transfer',
248        'nsc'        => 'application/x-conference',
249        'nvd'        => 'application/x-navidoc',
250        'o'        => 'application/octet-stream',
251        'oda'        => 'application/oda',
252        'omc'        => 'application/x-omc',
253        'oga'        => 'audio/ogg',
254        'ogg'        => 'audio/ogg',
255        'ogv'        => 'video/ogg',
256        'ogm'        => 'video/ogg',
257        'omcd'        => 'application/x-omcdatamaker',
258        'omcr'        => 'application/x-omcregerator',
259        'p'        => 'text/x-pascal',
260        'p10'        => 'application/x-pkcs10',
261        'p12'        => 'application/x-pkcs12',
262        'p7a'        => 'application/x-pkcs7-signature',
263        'p7c'        => 'application/x-pkcs7-mime',
264        'p7m'        => 'application/x-pkcs7-mime',
265        'p7r'        => 'application/x-pkcs7-certreqresp',
266        'p7s'        => 'application/pkcs7-signature',
267        'part'        => 'application/pro_eng',
268        'pas'        => 'text/pascal',
269        'pbm'        => 'image/x-portable-bitmap',
270        'pcl'        => 'application/x-pcl',
271        'pct'        => 'image/x-pict',
272        'pcx'        => 'image/x-pcx',
273        'pdb'        => 'chemical/x-pdb',
274        'pdf'        => 'application/pdf',
275        'pfunk'        => 'audio/make.my.funk',
276        'pgm'        => 'image/x-portable-greymap',
277        'pic'        => 'image/pict',
278        'pict'        => 'image/pict',
279        'pkg'        => 'application/x-newton-compatible-pkg',
280        'pko'        => 'application/vnd.ms-pki.pko',
281        'pl'        => 'text/x-script.perl',
282        'plx'        => 'application/x-pixclscript',
283        'pm'        => 'text/x-script.perl-module',
284        'pm4'        => 'application/x-pagemaker',
285        'pm5'        => 'application/x-pagemaker',
286        'png'        => 'image/png',
287        'pnm'        => 'image/x-portable-anymap',
288        'pot'        => 'application/mspowerpoint',
289        'pov'        => 'model/x-pov',
290        'ppa'        => 'application/vnd.ms-powerpoint',
291        'ppm'        => 'image/x-portable-pixmap',
292        'pps'        => 'application/mspowerpoint',
293        'ppt'        => 'application/mspowerpoint',
294        'ppz'        => 'application/mspowerpoint',
295        'pre'        => 'application/x-freelance',
296        'prt'        => 'application/pro_eng',
297        'ps'        => 'application/postscript',
298        'psd'        => 'application/octet-stream',
299        'pvu'        => 'paleovu/x-pv',
300        'pwz'        => 'application/vnd.ms-powerpoint',
301        'py'        => 'text/x-script.phyton',
302        'pyc'        => 'applicaiton/x-bytecode.python',
303        'qcp'        => 'audio/vnd.qcelp',
304        'qd3'        => 'x-world/x-3dmf',
305        'qd3d'        => 'x-world/x-3dmf',
306        'qif'        => 'image/x-quicktime',
307        'qt'        => 'video/quicktime',
308        'qtc'        => 'video/x-qtc',
309        'qti'        => 'image/x-quicktime',
310        'qtif'        => 'image/x-quicktime',
311        'ra'        => 'audio/x-realaudio',
312        'ram'        => 'audio/x-pn-realaudio',
313        'ras'        => 'image/x-cmu-raster',
314        'rast'        => 'image/cmu-raster',
315        'rexx'        => 'text/x-script.rexx',
316        'rf'        => 'image/vnd.rn-realflash',
317        'rgb'        => 'image/x-rgb',
318        'rm'        => 'audio/x-pn-realaudio',
319        'rmi'        => 'audio/mid',
320        'rmm'        => 'audio/x-pn-realaudio',
321        'rmp'        => 'audio/x-pn-realaudio',
322        'rng'        => 'application/vnd.nokia.ringing-tone',
323        'rnx'        => 'application/vnd.rn-realplayer',
324        'roff'        => 'application/x-troff',
325        'rp'        => 'image/vnd.rn-realpix',
326        'rpm'        => 'audio/x-pn-realaudio-plugin',
327        'rt'        => 'text/richtext',
328        'rtf'        => 'text/richtext',
329        'rtx'        => 'text/richtext',
330        'rv'        => 'video/vnd.rn-realvideo',
331        's'        => 'text/x-asm',
332        's3m'        => 'audio/s3m',
333        'saveme'    => 'application/octet-stream',
334        'sbk'        => 'application/x-tbook',
335        'scm'        => 'video/x-scm',
336        'sdml'        => 'text/plain',
337        'sdp'        => 'application/x-sdp',
338        'sdr'        => 'application/sounder',
339        'sea'        => 'application/x-sea',
340        'set'        => 'application/set',
341        'sgm'        => 'text/x-sgml',
342        'sgml'        => 'text/x-sgml',
343        'sh'        => 'text/x-script.sh',
344        'shar'        => 'application/x-shar',
345        'shtml'        => 'text/x-server-parsed-html',
346        'sid'        => 'audio/x-psid',
347        'sit'        => 'application/x-stuffit',
348        'skd'        => 'application/x-koan',
349        'skm'        => 'application/x-koan',
350        'skp'        => 'application/x-koan',
351        'skt'        => 'application/x-koan',
352        'sl'        => 'application/x-seelogo',
353        'smi'        => 'application/smil',
354        'smil'        => 'application/smil',
355        'snd'        => 'audio/x-adpcm',
356        'sol'        => 'application/solids',
357        'spc'        => 'text/x-speech',
358        'spl'        => 'application/futuresplash',
359        'spr'        => 'application/x-sprite',
360        'sprite'    => 'application/x-sprite',
361        'src'        => 'application/x-wais-source',
362        'ssi'        => 'text/x-server-parsed-html',
363        'ssm'        => 'application/streamingmedia',
364        'sst'        => 'application/vnd.ms-pki.certstore',
365        'step'        => 'application/step',
366        'stl'        => 'application/vnd.ms-pki.stl',
367        'stp'        => 'application/step',
368        'sv4cpio'    => 'application/x-sv4cpio',
369        'sv4crc'    => 'application/x-sv4crc',
370        'svf'        => 'image/x-dwg',
371        'svr'        => 'application/x-world',
372        'swf'        => 'application/x-shockwave-flash',
373        't'        => 'application/x-troff',
374        'talk'        => 'text/x-speech',
375        'tar'        => 'application/x-tar',
376        'tbk'        => 'application/x-tbook',
377        'tcl'        => 'text/x-script.tcl',
378        'tcsh'        => 'text/x-script.tcsh',
379        'tex'        => 'application/x-tex',
380        'texi'        => 'application/x-texinfo',
381        'texinfo'    => 'application/x-texinfo',
382        'text'        => 'text/plain',
383        'tgz'        => 'application/x-compressed',
384        'tif'        => 'image/tiff',
385        'tiff'        => 'image/tiff',
386        'tr'        => 'application/x-troff',
387        'tsi'        => 'audio/tsp-audio',
388        'tsp'        => 'audio/tsplayer',
389        'tsv'        => 'text/tab-separated-values',
390        'turbot'    => 'image/florian',
391        'txt'        => 'text/plain',
392        'uil'        => 'text/x-uil',
393        'uni'        => 'text/uri-list',
394        'unis'        => 'text/uri-list',
395        'unv'        => 'application/i-deas',
396        'uri'        => 'text/uri-list',
397        'uris'        => 'text/uri-list',
398        'ustar'        => 'multipart/x-ustar',
399        'uu'        => 'text/x-uuencode',
400        'uue'        => 'text/x-uuencode',
401        'vcd'        => 'application/x-cdlink',
402        'vcs'        => 'text/x-vcalendar',
403        'vda'        => 'application/vda',
404        'vdo'        => 'video/vdo',
405        'vew'        => 'application/groupwise',
406        'viv'        => 'video/vivo',
407        'vivo'        => 'video/vivo',
408        'vmd'        => 'application/vocaltec-media-desc',
409        'vmf'        => 'application/vocaltec-media-file',
410        'voc'        => 'audio/voc',
411        'vos'        => 'video/vosaic',
412        'vox'        => 'audio/voxware',
413        'vqe'        => 'audio/x-twinvq-plugin',
414        'vqf'        => 'audio/x-twinvq',
415        'vql'        => 'audio/x-twinvq-plugin',
416        'vrml'        => 'application/x-vrml',
417        'vrt'        => 'x-world/x-vrt',
418        'vsd'        => 'application/x-visio',
419        'vst'        => 'application/x-visio',
420        'vsw'        => 'application/x-visio',
421        'w60'        => 'application/wordperfect6.0',
422        'w61'        => 'application/wordperfect6.1',
423        'w6w'        => 'application/msword',
424        'wav'        => 'audio/wav',
425        'wb1'        => 'application/x-qpro',
426        'wbmp'        => 'image/vnd.wap.wbmp',
427        'web'        => 'application/vnd.xara',
428        'webm'        => 'video/webm',
429        'wiz'        => 'application/msword',
430        'wk1'        => 'application/x-123',
431        'wmf'        => 'windows/metafile',
432        'wml'        => 'text/vnd.wap.wml',
433        'wmlc'        => 'application/vnd.wap.wmlc',
434        'wmls'        => 'text/vnd.wap.wmlscript',
435        'wmlsc'        => 'application/vnd.wap.wmlscriptc',
436        'word'        => 'application/msword',
437        'wp'        => 'application/wordperfect',
438        'wp5'        => 'application/wordperfect',
439        'wp6'        => 'application/wordperfect',
440        'wpd'        => 'application/wordperfect',
441        'wq1'        => 'application/x-lotus',
442        'wri'        => 'application/mswrite',
443        'wrl'        => 'model/vrml',
444        'wrz'        => 'model/vrml',
445        'wsc'        => 'text/scriplet',
446        'wsrc'        => 'application/x-wais-source',
447        'wtk'        => 'application/x-wintalk',
448        'xbm'        => 'image/xbm',
449        'xdr'        => 'video/x-amt-demorun',
450        'xgz'        => 'xgl/drawing',
451        'xif'        => 'image/vnd.xiff',
452        'xl'        => 'application/excel',
453        'xla'        => 'application/excel',
454        'xlb'        => 'application/excel',
455        'xlc'        => 'application/excel',
456        'xld'        => 'application/excel',
457        'xlk'        => 'application/excel',
458        'xll'        => 'application/excel',
459        'xlm'        => 'application/excel',
460        'xls'        => 'application/excel',
461        'xlt'        => 'application/excel',
462        'xlv'        => 'application/excel',
463        'xlw'        => 'application/excel',
464        'xm'        => 'audio/xm',
465        'xml'        => 'text/xml',
466        'xmz'        => 'xgl/movie',
467        'xpix'        => 'application/x-vnd.ls-xpix',
468        'xpm'        => 'image/xpm',
469        'x-png'        => 'image/png',
470        'xsr'        => 'video/x-amt-showrun',
471        'xwd'        => 'image/x-xwindowdump',
472        'xyz'        => 'chemical/x-pdb',
473        'z'        => 'application/x-compressed',
474        'zip'        => 'application/x-zip-compressed',
475        'zoo'        => 'application/octet-stream',
476        'zsh'        => 'text/x-script.zsh',
477    );
478
479    /**
480    * {@inheritdoc}
481    */
482    public function is_supported()
483    {
484        return true;
485    }
486
487    /**
488    * {@inheritdoc}
489    */
490    public function guess($file, $file_name = '')
491    {
492        $file_name = (empty($file_name)) ? $file : $file_name;
493        return $this->map_extension_to_type($file_name);
494    }
495
496    /**
497    * Map extension of supplied file_name to mime type
498    *
499    * @param string $file_name Path to file or filename
500    *
501    * @return string|null Mimetype if known or null if not
502    */
503    protected function map_extension_to_type($file_name)
504    {
505        $extension = pathinfo($file_name, PATHINFO_EXTENSION);
506
507        return $this->extension_map[$extension] ?? null;
508    }
509}