Completed
Push — master ( bc9cc9...628b41 )
by Bai
29:27 queued 07:33
created

Config::getRsHost()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 2
dl 0
loc 12
ccs 0
cts 7
cp 0
crap 6
rs 9.8666
c 0
b 0
f 0
1
<?php
2
namespace Qiniu;
3
4
final class Config
5
{
6
    const SDK_VER = '7.2.5';
7
8
    const BLOCK_SIZE = 4194304; //4*1024*1024 分块上传块大小,该参数为接口规格,不能修改
9
10
    const RSF_HOST = 'rsf.qiniu.com';
11
    const API_HOST = 'api.qiniu.com';
12
    const RS_HOST = 'rs.qiniu.com';      //RS Host
13
    const UC_HOST = 'https://api.qiniu.com';              //UC Host
14
    const RTCAPI_HOST = 'http://rtc.qiniuapi.com';
15
    const ARGUS_HOST = 'argus.atlab.ai';
16
    const RTCAPI_VERSION = 'v3';
17
18
    // Zone 空间对应的机房
19
    public $zone;
20
    //BOOL 是否使用https域名
21
    public $useHTTPS;
22
    //BOOL 是否使用CDN加速上传域名
23
    public $useCdnDomains;
24
    // Zone Cache
25
    private $zoneCache;
26
27
    // 构造函数
28 69
    public function __construct(Zone $z = null)
29
    {
30 69
        $this->zone = $z;
31 69
        $this->useHTTPS = false;
32 69
        $this->useCdnDomains = false;
33 69
        $this->zoneCache = array();
34 69
    }
35
36 18
    public function getUpHost($accessKey, $bucket)
37
    {
38 18
        $zone = $this->getZone($accessKey, $bucket);
39 18
        if ($this->useHTTPS === true) {
40
            $scheme = "https://";
41
        } else {
42 18
            $scheme = "http://";
43
        }
44
45 18
        $host = $zone->srcUpHosts[0];
46 18
        if ($this->useCdnDomains === true) {
47
            $host = $zone->cdnUpHosts[0];
48
        }
49
50 18
        return $scheme . $host;
51
    }
52
53
    public function getUpBackupHost($accessKey, $bucket)
54
    {
55
        $zone = $this->getZone($accessKey, $bucket);
56
        if ($this->useHTTPS === true) {
57
            $scheme = "https://";
58
        } else {
59
            $scheme = "http://";
60
        }
61
62
        $host = $zone->cdnUpHosts[0];
63
        if ($this->useCdnDomains === true) {
64
            $host = $zone->srcUpHosts[0];
65
        }
66
67
        return $scheme . $host;
68
    }
69
70
    public function getRsHost($accessKey, $bucket)
71
    {
72
        $zone = $this->getZone($accessKey, $bucket);
73
74
        if ($this->useHTTPS === true) {
75
            $scheme = "https://";
76
        } else {
77
            $scheme = "http://";
78
        }
79
80
        return $scheme . $zone->rsHost;
81
    }
82
83
    public function getRsfHost($accessKey, $bucket)
84
    {
85
        $zone = $this->getZone($accessKey, $bucket);
86
87
        if ($this->useHTTPS === true) {
88
            $scheme = "https://";
89
        } else {
90
            $scheme = "http://";
91
        }
92
93
        return $scheme . $zone->rsfHost;
94
    }
95
96 6
    public function getIovipHost($accessKey, $bucket)
97
    {
98 6
        $zone = $this->getZone($accessKey, $bucket);
99
100 6
        if ($this->useHTTPS === true) {
101
            $scheme = "https://";
102
        } else {
103 6
            $scheme = "http://";
104
        }
105
106 6
        return $scheme . $zone->iovipHost;
107
    }
108
109
    public function getApiHost($accessKey, $bucket)
110
    {
111
        $zone = $this->getZone($accessKey, $bucket);
112
113
        if ($this->useHTTPS === true) {
114
            $scheme = "https://";
115
        } else {
116
            $scheme = "http://";
117
        }
118
119
        return $scheme . $zone->apiHost;
120
    }
121
122 24
    private function getZone($accessKey, $bucket)
123
    {
124 24
        $cacheId = "$accessKey:$bucket";
125
126 24
        if (isset($this->zoneCache[$cacheId])) {
127 3
            $zone = $this->zoneCache[$cacheId];
128 24
        } elseif (isset($this->zone)) {
129 3
            $zone = $this->zone;
130 3
            $this->zoneCache[$cacheId] = $zone;
131 3
        } else {
132 21
            $zone = Zone::queryZone($accessKey, $bucket);
133 21
            $this->zoneCache[$cacheId] = $zone;
134
        }
135 24
        return $zone;
136
    }
137
}
138