1
|
|
|
<?php |
2
|
|
|
namespace Qiniu; |
3
|
|
|
|
4
|
|
|
final class Config |
5
|
|
|
{ |
6
|
|
|
const SDK_VER = '7.2.9'; |
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 = 'uc.qbox.me'; //UC Host |
14
|
|
|
const RTCAPI_HOST = 'http://rtc.qiniuapi.com'; |
15
|
|
|
const ARGUS_HOST = 'argus.atlab.ai'; |
16
|
|
|
const CASTER_HOST = 'pili-caster.qiniuapi.com'; |
17
|
|
|
const SMS_HOST="https://sms.qiniuapi.com"; |
18
|
|
|
const RTCAPI_VERSION = 'v3'; |
19
|
|
|
const SMS_VERSION='v1'; |
20
|
|
|
|
21
|
|
|
// Zone 空间对应的存储区域 |
22
|
|
|
public $region; |
23
|
|
|
//BOOL 是否使用https域名 |
24
|
|
|
public $useHTTPS; |
25
|
|
|
//BOOL 是否使用CDN加速上传域名 |
26
|
|
|
public $useCdnDomains; |
27
|
|
|
// Zone Cache |
28
|
|
|
private $regionCache; |
29
|
|
|
|
30
|
|
|
// 构造函数 |
31
|
69 |
|
public function __construct(Region $z = null) |
32
|
|
|
{ |
33
|
69 |
|
$this->zone = $z; |
|
|
|
|
34
|
69 |
|
$this->useHTTPS = false; |
35
|
69 |
|
$this->useCdnDomains = false; |
36
|
69 |
|
$this->regionCache = array(); |
37
|
69 |
|
} |
38
|
|
|
|
39
|
18 |
|
public function getUpHost($accessKey, $bucket) |
40
|
|
|
{ |
41
|
18 |
|
$region = $this->getRegion($accessKey, $bucket); |
42
|
18 |
|
if ($this->useHTTPS === true) { |
43
|
|
|
$scheme = "https://"; |
44
|
|
|
} else { |
45
|
18 |
|
$scheme = "http://"; |
46
|
|
|
} |
47
|
|
|
|
48
|
18 |
|
$host = $region->srcUpHosts[0]; |
49
|
18 |
|
if ($this->useCdnDomains === true) { |
50
|
|
|
$host = $region->cdnUpHosts[0]; |
51
|
|
|
} |
52
|
|
|
|
53
|
18 |
|
return $scheme . $host; |
54
|
|
|
} |
55
|
|
|
|
56
|
3 |
|
public function getUpBackupHost($accessKey, $bucket) |
57
|
|
|
{ |
58
|
3 |
|
$region = $this->getRegion($accessKey, $bucket); |
59
|
3 |
|
if ($this->useHTTPS === true) { |
60
|
|
|
$scheme = "https://"; |
61
|
|
|
} else { |
62
|
3 |
|
$scheme = "http://"; |
63
|
|
|
} |
64
|
|
|
|
65
|
3 |
|
$host = $region->cdnUpHosts[0]; |
66
|
3 |
|
if ($this->useCdnDomains === true) { |
67
|
|
|
$host = $region->srcUpHosts[0]; |
68
|
|
|
} |
69
|
|
|
|
70
|
3 |
|
return $scheme . $host; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function getRsHost($accessKey, $bucket) |
74
|
|
|
{ |
75
|
|
|
$region = $this->getRegion($accessKey, $bucket); |
76
|
|
|
|
77
|
|
|
if ($this->useHTTPS === true) { |
78
|
|
|
$scheme = "https://"; |
79
|
|
|
} else { |
80
|
|
|
$scheme = "http://"; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
return $scheme . $region->rsHost; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function getRsfHost($accessKey, $bucket) |
87
|
|
|
{ |
88
|
|
|
$region = $this->getRegion($accessKey, $bucket); |
89
|
|
|
|
90
|
|
|
if ($this->useHTTPS === true) { |
91
|
|
|
$scheme = "https://"; |
92
|
|
|
} else { |
93
|
|
|
$scheme = "http://"; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
return $scheme . $region->rsfHost; |
97
|
|
|
} |
98
|
|
|
|
99
|
6 |
|
public function getIovipHost($accessKey, $bucket) |
100
|
|
|
{ |
101
|
6 |
|
$region = $this->getRegion($accessKey, $bucket); |
102
|
|
|
|
103
|
6 |
|
if ($this->useHTTPS === true) { |
104
|
|
|
$scheme = "https://"; |
105
|
|
|
} else { |
106
|
6 |
|
$scheme = "http://"; |
107
|
|
|
} |
108
|
|
|
|
109
|
6 |
|
return $scheme . $region->iovipHost; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function getApiHost($accessKey, $bucket) |
113
|
|
|
{ |
114
|
|
|
$region = $this->getRegion($accessKey, $bucket); |
115
|
|
|
|
116
|
|
|
if ($this->useHTTPS === true) { |
117
|
|
|
$scheme = "https://"; |
118
|
|
|
} else { |
119
|
|
|
$scheme = "http://"; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
return $scheme . $region->apiHost; |
123
|
|
|
} |
124
|
|
|
|
125
|
24 |
|
private function getRegion($accessKey, $bucket) |
126
|
|
|
{ |
127
|
24 |
|
$cacheId = "$accessKey:$bucket"; |
128
|
|
|
|
129
|
24 |
|
if (isset($this->regionCache[$cacheId])) { |
130
|
6 |
|
$region = $this->regionCache[$cacheId]; |
131
|
24 |
|
} elseif (isset($this->zone)) { |
132
|
3 |
|
$region = $this->zone; |
133
|
3 |
|
$this->regionCache[$cacheId] = $region; |
134
|
3 |
|
} else { |
135
|
21 |
|
$region = Zone::queryZone($accessKey, $bucket); |
136
|
21 |
|
$this->regionCache[$cacheId] = $region; |
137
|
|
|
} |
138
|
24 |
|
return $region; |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: