Conditions | 3 |
Paths | 3 |
Total Lines | 29 |
Code Lines | 18 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
25 | public function getMimeType(): string |
||
26 | { |
||
27 | $extension = pathinfo($this->path, PATHINFO_EXTENSION); |
||
28 | |||
29 | // See if we can find a mime type for the extension, |
||
30 | // instead of having to rely on a PHP extension. |
||
31 | $lookup = [ |
||
32 | 'txt' => 'text/plain', |
||
33 | 'md' => 'text/markdown', |
||
34 | 'html' => 'text/html', |
||
35 | 'css' => 'text/css', |
||
36 | 'svg' => 'image/svg+xml', |
||
37 | 'png' => 'image/png', |
||
38 | 'jpg' => 'image/jpeg', |
||
39 | 'jpeg' => 'image/jpeg', |
||
40 | 'gif' => 'image/gif', |
||
41 | 'json' => 'application/json', |
||
42 | 'js' => 'application/javascript', |
||
43 | ]; |
||
44 | |||
45 | if (isset($lookup[$extension])) { |
||
46 | return $lookup[$extension]; |
||
47 | } |
||
48 | |||
49 | if (extension_loaded('fileinfo')) { |
||
50 | return mime_content_type($this->path); |
||
51 | } |
||
52 | |||
53 | return 'text/plain'; |
||
54 | } |
||
61 |