Lines
100.00%
2 / 2
Methods
100.00%
1 / 1
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| guessByExt | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 2 | ||
| 27 | abstract class AbstractMimeType | |
| 28 | { | |
| 29 | /** | |
| 30 | * Simple file extension to mime type mapping. | |
| 31 | */ | |
| 32 | protected static array $list = [ | |
| 33 | 'ez' => 'application/andrew-inset', | |
| 34 | 'hqx' => 'application/mac-binhex40', | |
| 35 | 'cpt' => 'application/mac-compactpro', | |
| 36 | 'doc' => 'application/msword', | |
| 37 | 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', | |
| 38 | 'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template', | |
| 39 | 'bin' => 'application/octet-stream', | |
| 40 | 'dms' => 'application/octet-stream', | |
| 41 | 'lha' => 'application/octet-stream', | |
| 42 | 'lzh' => 'application/octet-stream', | |
| 43 | 'exe' => 'application/octet-stream', | |
| 44 | 'rar' => 'application/x-rar-compressed', | |
| 45 | 'class' => 'application/octet-stream', | |
| 46 | 'so' => 'application/octet-stream', | |
| 47 | 'dll' => 'application/octet-stream', | |
| 48 | 'oda' => 'application/oda', | |
| 49 | 'pdf' => 'application/pdf', | |
| 50 | 'ai' => 'application/postscript', | |
| 51 | 'eps' => 'application/postscript', | |
| 52 | 'ps' => 'application/postscript', | |
| 53 | 'smi' => 'application/smil', | |
| 54 | 'smil' => 'application/smil', | |
| 55 | 'mif' => 'application/vnd.mif', | |
| 56 | 'xls' => 'application/vnd.ms-excel', | |
| 57 | 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', | |
| 58 | 'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template', | |
| 59 | 'ppt' => 'application/vnd.ms-powerpoint', | |
| 60 | 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation', | |
| 61 | 'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template', | |
| 62 | 'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow', | |
| 63 | 'wbxml' => 'application/vnd.wap.wbxml', | |
| 64 | 'wmlc' => 'application/vnd.wap.wmlc', | |
| 65 | 'wmlsc' => 'application/vnd.wap.wmlscriptc', | |
| 66 | 'bcpio' => 'application/x-bcpio', | |
| 67 | 'vcd' => 'application/x-cdlink', | |
| 68 | 'pgn' => 'application/x-chess-pgn', | |
| 69 | 'cpio' => 'application/x-cpio', | |
| 70 | 'csh' => 'application/x-csh', | |
| 71 | 'dcr' => 'application/x-director', | |
| 72 | 'dir' => 'application/x-director', | |
| 73 | 'dxr' => 'application/x-director', | |
| 74 | 'dvi' => 'application/x-dvi', | |
| 75 | 'spl' => 'application/x-futuresplash', | |
| 76 | 'gtar' => 'application/x-gtar', | |
| 77 | 'hdf' => 'application/x-hdf', | |
| 78 | 'js' => 'application/x-javascript', | |
| 79 | 'skp' => 'application/x-koan', | |
| 80 | 'skd' => 'application/x-koan', | |
| 81 | 'skt' => 'application/x-koan', | |
| 82 | 'skm' => 'application/x-koan', | |
| 83 | 'latex' => 'application/x-latex', | |
| 84 | 'nc' => 'application/x-netcdf', | |
| 85 | 'cdf' => 'application/x-netcdf', | |
| 86 | 'sh' => 'application/x-sh', | |
| 87 | 'shar' => 'application/x-shar', | |
| 88 | 'swf' => 'application/x-shockwave-flash', | |
| 89 | 'sit' => 'application/x-stuffit', | |
| 90 | 'sv4cpio' => 'application/x-sv4cpio', | |
| 91 | 'sv4crc' => 'application/x-sv4crc', | |
| 92 | 'tar' => 'application/x-tar', | |
| 93 | 'tcl' => 'application/x-tcl', | |
| 94 | 'tex' => 'application/x-tex', | |
| 95 | 'texinfo' => 'application/x-texinfo', | |
| 96 | 'texi' => 'application/x-texinfo', | |
| 97 | 't' => 'application/x-troff', | |
| 98 | 'tr' => 'application/x-troff', | |
| 99 | 'roff' => 'application/x-troff', | |
| 100 | 'man' => 'application/x-troff-man', | |
| 101 | 'me' => 'application/x-troff-me', | |
| 102 | 'ms' => 'application/x-troff-ms', | |
| 103 | 'ustar' => 'application/x-ustar', | |
| 104 | 'src' => 'application/x-wais-source', | |
| 105 | 'xhtml' => 'application/xhtml+xml', | |
| 106 | 'xht' => 'application/xhtml+xml', | |
| 107 | 'zip' => 'application/zip', | |
| 108 | 'au' => 'audio/basic', | |
| 109 | 'snd' => 'audio/basic', | |
| 110 | 'mid' => 'audio/midi', | |
| 111 | 'midi' => 'audio/midi', | |
| 112 | 'kar' => 'audio/midi', | |
| 113 | 'mpga' => 'audio/mpeg', | |
| 114 | 'mp2' => 'audio/mpeg', | |
| 115 | 'mp3' => 'audio/mpeg', | |
| 116 | 'aif' => 'audio/x-aiff', | |
| 117 | 'aiff' => 'audio/x-aiff', | |
| 118 | 'aifc' => 'audio/x-aiff', | |
| 119 | 'm3u' => 'audio/x-mpegurl', | |
| 120 | 'ram' => 'audio/x-pn-realaudio', | |
| 121 | 'rm' => 'audio/x-pn-realaudio', | |
| 122 | 'rpm' => 'audio/x-pn-realaudio-plugin', | |
| 123 | 'ra' => 'audio/x-realaudio', | |
| 124 | 'wav' => 'audio/x-wav', | |
| 125 | 'pdb' => 'chemical/x-pdb', | |
| 126 | 'xyz' => 'chemical/x-xyz', | |
| 127 | 'bmp' => 'image/bmp', | |
| 128 | 'gif' => 'image/gif', | |
| 129 | 'ief' => 'image/ief', | |
| 130 | 'jpeg' => 'image/jpeg', | |
| 131 | 'jpg' => 'image/jpeg', | |
| 132 | 'jpe' => 'image/jpeg', | |
| 133 | 'png' => 'image/png', | |
| 134 | 'tiff' => 'image/tiff', | |
| 135 | 'tif' => 'image/tiff', | |
| 136 | 'djvu' => 'image/vnd.djvu', | |
| 137 | 'djv' => 'image/vnd.djvu', | |
| 138 | 'wbmp' => 'image/vnd.wap.wbmp', | |
| 139 | 'ras' => 'image/x-cmu-raster', | |
| 140 | 'pnm' => 'image/x-portable-anymap', | |
| 141 | 'pbm' => 'image/x-portable-bitmap', | |
| 142 | 'pgm' => 'image/x-portable-graymap', | |
| 143 | 'ppm' => 'image/x-portable-pixmap', | |
| 144 | 'rgb' => 'image/x-rgb', | |
| 145 | 'xbm' => 'image/x-xbitmap', | |
| 146 | 'xpm' => 'image/x-xpixmap', | |
| 147 | 'xwd' => 'image/x-xwindowdump', | |
| 148 | 'igs' => 'model/iges', | |
| 149 | 'iges' => 'model/iges', | |
| 150 | 'msh' => 'model/mesh', | |
| 151 | 'mesh' => 'model/mesh', | |
| 152 | 'silo' => 'model/mesh', | |
| 153 | 'wrl' => 'model/vrml', | |
| 154 | 'vrml' => 'model/vrml', | |
| 155 | 'css' => 'text/css', | |
| 156 | 'html' => 'text/html', | |
| 157 | 'htm' => 'text/html', | |
| 158 | 'asc' => 'text/plain', | |
| 159 | 'txt' => 'text/plain', | |
| 160 | 'rtx' => 'text/richtext', | |
| 161 | 'rtf' => 'text/rtf', | |
| 162 | 'sgml' => 'text/sgml', | |
| 163 | 'sgm' => 'text/sgml', | |
| 164 | 'tsv' => 'text/tab-separated-values', | |
| 165 | 'wml' => 'text/vnd.wap.wml', | |
| 166 | 'wmls' => 'text/vnd.wap.wmlscript', | |
| 167 | 'etx' => 'text/x-setext', | |
| 168 | 'xsl' => 'text/xml', | |
| 169 | 'xml' => 'text/xml', | |
| 170 | 'mpeg' => 'video/mpeg', | |
| 171 | 'mpg' => 'video/mpeg', | |
| 172 | 'mpe' => 'video/mpeg', | |
| 173 | 'qt' => 'video/quicktime', | |
| 174 | 'mov' => 'video/quicktime', | |
| 175 | 'mxu' => 'video/vnd.mpegurl', | |
| 176 | 'avi' => 'video/x-msvideo', | |
| 177 | 'movie' => 'video/x-sgi-movie', | |
| 178 | 'ice' => 'x-conference/x-cooltalk', | |
| 179 | 'ods' => 'application/vnd.oasis.opendocument.spreadsheet', | |
| 180 | 'odp' => 'application/vnd.oasis.opendocument.presentation ', | |
| 181 | 'sxc' => 'application/vnd.sun.xml.calc', | |
| 182 | 'odt' => 'application/vnd.oasis.opendocument.text', | |
| 183 | 'log' => 'text/plain', | |
| 184 | ]; | |
| 185 | ||
| 186 | /** | |
| 187 | * Read mime type mapped to extension. | |
| 188 | * | |
| 189 | * @param string $ext file extension | |
| 190 | */ | |
| 191 | public static function guessByExt(string $ext): string | |
| 192 | { | |
| 193 | $mimeType = self::$list[$ext] ?? null; | |
| 194 | ||
| 195 | return is_string($mimeType) ? $mimeType : 'application/octet-stream'; | |
| 196 | } | |
| 197 | } |