MIME   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 77
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A get() 0 8 2
1
<?php
2
namespace PHPDaemon\Utils;
3
4
/**
5
 * MIME class
6
 * @package PHPDaemon\Utils
7
 * @author  Vasily Zorin <[email protected]>
8
 */
9
class MIME
10
{
11
    use \PHPDaemon\Traits\ClassWatchdog;
12
    use \PHPDaemon\Traits\StaticObjectWatchdog;
13
14
    /**
15
     * @var array MIME types
16
     */
17
    protected static $fileTypes = [
18
        'txt' => 'text/plain',
19
        'htm' => 'text/html',
20
        'html' => 'text/html',
21
        'php' => 'text/html',
22
        'css' => 'text/css',
23
        'js' => 'application/javascript',
24
        'json' => 'application/json',
25
        'xml' => 'application/xml',
26
        'swf' => 'application/x-shockwave-flash',
27
        'flv' => 'video/x-flv',
28
29
        // images
30
        'png' => 'image/png',
31
        'jpe' => 'image/jpeg',
32
        'jpeg' => 'image/jpeg',
33
        'jpg' => 'image/jpeg',
34
        'gif' => 'image/gif',
35
        'bmp' => 'image/bmp',
36
        'ico' => 'image/vnd.microsoft.icon',
37
        'tiff' => 'image/tiff',
38
        'tif' => 'image/tiff',
39
        'svg' => 'image/svg+xml',
40
        'svgz' => 'image/svg+xml',
41
42
        // archives
43
        'zip' => 'application/zip',
44
        'rar' => 'application/x-rar-compressed',
45
        'exe' => 'application/x-msdownload',
46
        'msi' => 'application/x-msdownload',
47
        'cab' => 'application/vnd.ms-cab-compressed',
48
49
        // audio/video
50
        'mp3' => 'audio/mpeg',
51
        'qt' => 'video/quicktime',
52
        'mov' => 'video/quicktime',
53
54
        // adobe
55
        'pdf' => 'application/pdf',
56
        'psd' => 'image/vnd.adobe.photoshop',
57
        'ai' => 'application/postscript',
58
        'eps' => 'application/postscript',
59
        'ps' => 'application/postscript',
60
61
        // ms office
62
        'doc' => 'application/msword',
63
        'rtf' => 'application/rtf',
64
        'xls' => 'application/vnd.ms-excel',
65
        'ppt' => 'application/vnd.ms-powerpoint',
66
67
        // open office
68
        'odt' => 'application/vnd.oasis.opendocument.text',
69
        'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
70
    ];
71
72
    /**
73
     * Returns MIME type of the given file
74
     * @param  string $path Path
75
     * @return string       MIME type
76
     */
77
    public static function get($path)
78
    {
79
        $ext = strtolower(pathinfo($path, PATHINFO_EXTENSION));
80
        if (!isset(self::$fileTypes[$ext])) {
81
            return false;
82
        }
83
        return self::$fileTypes[$ext];
84
    }
85
}
86