1
|
|
|
<?php |
2
|
|
|
namespace Qiniu; |
3
|
|
|
|
4
|
|
|
final class Config |
5
|
|
|
{ |
6
|
|
|
const SDK_VER = '7.2.1'; |
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://uc.qbox.me'; //UC Host |
14
|
|
|
|
15
|
|
|
// Zone 空间对应的机房 |
16
|
|
|
public $zone; |
17
|
|
|
//BOOL 是否使用https域名 |
18
|
|
|
public $useHTTPS; |
19
|
|
|
//BOOL 是否使用CDN加速上传域名 |
20
|
|
|
public $useCdnDomains; |
21
|
|
|
// Zone Cache |
22
|
|
|
private $zoneCache; |
23
|
|
|
|
24
|
|
|
// 构造函数 |
25
|
69 |
|
public function __construct(Zone $z = null) |
26
|
|
|
{ |
27
|
69 |
|
$this->zone = $z; |
28
|
69 |
|
$this->useHTTPS = false; |
29
|
69 |
|
$this->useCdnDomains = false; |
30
|
69 |
|
$this->zoneCache = array(); |
31
|
69 |
|
} |
32
|
|
|
|
33
|
18 |
|
public function getUpHost($accessKey, $bucket) |
34
|
|
|
{ |
35
|
18 |
|
$zone = $this->getZone($accessKey, $bucket); |
36
|
18 |
|
if ($this->useHTTPS === true) { |
37
|
|
|
$scheme = "https://"; |
38
|
|
|
} else { |
39
|
18 |
|
$scheme = "http://"; |
40
|
|
|
} |
41
|
|
|
|
42
|
18 |
|
$host = $zone->srcUpHosts[0]; |
43
|
18 |
|
if ($this->useCdnDomains === true) { |
44
|
|
|
$host = $zone->cdnUpHosts[0]; |
45
|
|
|
} |
46
|
|
|
|
47
|
18 |
|
return $scheme . $host; |
48
|
|
|
} |
49
|
|
|
|
50
|
3 |
|
public function getUpBackupHost($accessKey, $bucket) |
51
|
|
|
{ |
52
|
3 |
|
$zone = $this->getZone($accessKey, $bucket); |
53
|
3 |
|
if ($this->useHTTPS === true) { |
54
|
|
|
$scheme = "https://"; |
55
|
|
|
} else { |
56
|
3 |
|
$scheme = "http://"; |
57
|
|
|
} |
58
|
|
|
|
59
|
3 |
|
$host = $zone->cdnUpHosts[0]; |
60
|
3 |
|
if ($this->useCdnDomains === true) { |
61
|
|
|
$host = $zone->srcUpHosts[0]; |
62
|
|
|
} |
63
|
|
|
|
64
|
3 |
|
return $scheme . $host; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function getRsHost($accessKey, $bucket) |
68
|
|
|
{ |
69
|
|
|
$zone = $this->getZone($accessKey, $bucket); |
70
|
|
|
|
71
|
|
|
if ($this->useHTTPS === true) { |
72
|
|
|
$scheme = "https://"; |
73
|
|
|
} else { |
74
|
|
|
$scheme = "http://"; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
return $scheme . $zone->rsHost; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function getRsfHost($accessKey, $bucket) |
81
|
|
|
{ |
82
|
|
|
$zone = $this->getZone($accessKey, $bucket); |
83
|
|
|
|
84
|
|
|
if ($this->useHTTPS === true) { |
85
|
|
|
$scheme = "https://"; |
86
|
|
|
} else { |
87
|
|
|
$scheme = "http://"; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
return $scheme . $zone->rsfHost; |
91
|
|
|
} |
92
|
|
|
|
93
|
6 |
|
public function getIovipHost($accessKey, $bucket) |
94
|
|
|
{ |
95
|
6 |
|
$zone = $this->getZone($accessKey, $bucket); |
96
|
|
|
|
97
|
6 |
|
if ($this->useHTTPS === true) { |
98
|
|
|
$scheme = "https://"; |
99
|
|
|
} else { |
100
|
6 |
|
$scheme = "http://"; |
101
|
|
|
} |
102
|
|
|
|
103
|
6 |
|
return $scheme . $zone->iovipHost; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function getApiHost($accessKey, $bucket) |
107
|
|
|
{ |
108
|
|
|
$zone = $this->getZone($accessKey, $bucket); |
109
|
|
|
|
110
|
|
|
if ($this->useHTTPS === true) { |
111
|
|
|
$scheme = "https://"; |
112
|
|
|
} else { |
113
|
|
|
$scheme = "http://"; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
return $scheme . $zone->apiHost; |
117
|
|
|
} |
118
|
|
|
|
119
|
24 |
|
private function getZone($accessKey, $bucket) |
120
|
|
|
{ |
121
|
24 |
|
$cacheId = "$accessKey:$bucket"; |
122
|
|
|
|
123
|
24 |
|
if (isset($this->zoneCache[$cacheId])) { |
124
|
6 |
|
$zone = $this->zoneCache[$cacheId]; |
125
|
24 |
|
} elseif (isset($this->zone)) { |
126
|
3 |
|
$zone = $this->zone; |
127
|
3 |
|
$this->zoneCache[$cacheId] = $zone; |
128
|
3 |
|
} else { |
129
|
21 |
|
$zone = Zone::queryZone($accessKey, $bucket); |
130
|
21 |
|
$this->zoneCache[$cacheId] = $zone; |
131
|
|
|
} |
132
|
24 |
|
return $zone; |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|