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