Passed
Push — master ( e83d3e...f8b104 )
by alpha
02:24
created

AliyunOssUtil::getHeadersFromConfig()   A

Complexity

Conditions 5
Paths 9

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 5.1502

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 9
cts 11
cp 0.8182
rs 9.3222
c 0
b 0
f 0
cc 5
nc 9
nop 1
crap 5.1502
1
<?php
2
3
namespace AlphaSnow\AliyunOss;
4
5
use League\Flysystem\Config;
6
use OSS\OssClient;
7
8
class AliyunOssUtil
9
{
10
    public static $resultMap = [
11
        'Body' => 'raw_contents',
12
        'Content-Length' => 'size',
13
        'ContentType' => 'mimetype',
14
        'Size' => 'size',
15
        'StorageClass' => 'storage_class',
16
    ];
17
    /**
18
     * @var array
19
     */
20
    public static $metaOptions = [
21
        'CacheControl',
22
        'Expires',
23
        'ServerSideEncryption',
24
        'Metadata',
25
        'ACL',
26
        'ContentType',
27
        'ContentDisposition',
28
        'ContentLanguage',
29
        'ContentEncoding',
30
    ];
31
32
    /**
33
     * @var string[]
34
     */
35
    public static $metaMap = [
36
        'CacheControl' => 'Cache-Control',
37
        'Expires' => 'Expires',
38
        'ServerSideEncryption' => 'x-oss-server-side-encryption',
39
        'Metadata' => 'x-oss-metadata-directive',
40
        'ACL' => 'x-oss-object-acl',
41
        'ContentType' => 'Content-Type',
42
        'ContentDisposition' => 'Content-Disposition',
43
        'ContentLanguage' => 'response-content-language',
44
        'ContentEncoding' => 'Content-Encoding',
45
    ];
46
47
    public static $metaHeaders = [
48
        'storage',
49
        OssClient::OSS_ACL,
50
        OssClient::OSS_OBJECT_ACL,
51
        OssClient::OSS_OBJECT_GROUP,
52
        OssClient::OSS_OBJECT_COPY_SOURCE,
53
        OssClient::OSS_OBJECT_COPY_SOURCE_RANGE,
54
        OssClient::OSS_PROCESS,
55
        OssClient::OSS_CALLBACK,
56
        OssClient::OSS_CALLBACK_VAR,
57
        OssClient::OSS_REQUEST_PAYER,
58
        OssClient::OSS_TRAFFIC_LIMIT,
59
        OssClient::OSS_SECURITY_TOKEN
60
    ];
61
62 4
    public static function getHeadersFromConfig(Config $config)
63
    {
64 4
        $headers = [];
65 4
        foreach (static::$metaOptions as $option) {
66 4
            if (!$config->has($option)) {
67 4
                continue;
68
            }
69
            $headers[static::$metaMap[$option]] = $config->get($option);
70
        }
71
72 4
        foreach (static::$metaHeaders as $header) {
73 4
            if (!$config->has($header)) {
74 4
                continue;
75
            }
76
            $headers[$header] = $config->get($header);
77
        }
78
79 4
        return $headers;
80
    }
81
}
82