Passed
Push — master ( ae009e...1bc377 )
by 世昌
02:06
created

MimeType   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 46
dl 0
loc 70
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A getMimeType() 0 3 1
1
<?php
2
namespace nebula\application\response\provider;
3
4
/**
5
 * 响应MIME
6
 */
7
class MimeType
8
{
9
    /**
10
     * 内置Mime数组
11
     *
12
     * @var array
13
     */
14
    protected static $mimes = [
15
        # Image Type
16
        'jpe' => 'image/jpeg' ,
17
        'jpeg' => 'image/jpeg' ,
18
        'jpg' => 'image/jpeg' ,
19
        'svg' => 'image/svg+xml' ,
20
        'png' => 'image/png' ,
21
        'gif' => 'image/gif' ,
22
        'ico' => 'image/x-icon',
23
        'webp' => 'image/webp',
24
25
        # Text Type
26
        'js' => 'text/javascript',
27
        'css' => 'text/css',
28
        'txt' => 'text/plain',
29
        'html' => 'text/html' ,
30
        'csv' => 'text/csv' ,
31
        'xml' => 'text/xml',
32
33
        # App type
34
        'json' => 'application/json',
35
        'pdf' => 'application/pdf',
36
        'rss' => 'application/rss+xml',
37
        'rtf' => 'application/rtf',
38
        'apk' => 'application/vnd.android.package-archive',
39
40
        # Archive
41
        'zip' => 'application/zip',
42
        'gtar' => 'application/x-gtar' ,
43
        'gz' => 'application/x-gzip' ,
44
        '7z' => 'application/x-7z-compressed',
45
        'rar' => 'application/x-rar-compressed',
46
47
        # Office
48
        'dot' => 'application/msword',
49
        'doc' => 'application/msword',
50
        'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
51
        'xls' => 'application/vnd.ms-excel',
52
        'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
53
        'ppt' => 'application/vnd.ms-powerpoint',
54
        'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
55
        'pps' => 'application/vnd.ms-powerpoint',
56
        'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
57
58
        # Audio
59
        'wav' => 'audio/wav',
60
        'mp3' => 'audio/mp3',
61
        'ogg' => 'audio/ogg',
62
        'm4a' => 'audio/x-m4a',
63
64
        # Video
65
        'avi' => 'video/avi',
66
        'mp4' => 'video/mp4',
67
        'flv' => 'video/x-flv',
68
        'webm' => 'video/webm',
69
        'm4v' => 'video/x-m4v',
70
        '3gp' => 'video/3gpp',
71
    ];
72
73
74
    public static function getMimeType(string $extension)
75
    {
76
        return static::$mimes[$extension] ?? 'application/octet-stream';
77
    }
78
}
79