1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Qiniu; |
4
|
|
|
|
5
|
|
|
use Qiniu\Http\Client; |
6
|
|
|
use Qiniu\Http\Error; |
7
|
|
|
use Qiniu\Http\Middleware\RetryDomainsMiddleware; |
8
|
|
|
use Qiniu\Http\RequestOptions; |
9
|
|
|
|
10
|
|
|
class Region |
11
|
|
|
{ |
12
|
|
|
|
13
|
|
|
//源站上传域名 |
14
|
|
|
public $srcUpHosts; |
15
|
|
|
//CDN加速上传域名 |
16
|
|
|
public $cdnUpHosts; |
17
|
|
|
//资源管理域名 |
18
|
|
|
public $rsHost; |
19
|
|
|
//资源列举域名 |
20
|
|
|
public $rsfHost; |
21
|
|
|
//资源处理域名 |
22
|
|
|
public $apiHost; |
23
|
|
|
//IOVIP域名 |
24
|
30 |
|
public $iovipHost; |
25
|
|
|
// TTL |
26
|
|
|
public $ttl; |
27
|
|
|
|
28
|
|
|
//构造一个Region对象 |
29
|
|
|
public function __construct( |
30
|
|
|
$srcUpHosts = array(), |
31
|
|
|
$cdnUpHosts = array(), |
32
|
|
|
$rsHost = "rs-z0.qiniuapi.com", |
33
|
30 |
|
$rsfHost = "rsf-z0.qiniuapi.com", |
34
|
30 |
|
$apiHost = "api.qiniuapi.com", |
35
|
30 |
|
$iovipHost = null, |
36
|
30 |
|
$ttl = null |
37
|
30 |
|
) { |
38
|
30 |
|
|
39
|
30 |
|
$this->srcUpHosts = $srcUpHosts; |
40
|
|
|
$this->cdnUpHosts = $cdnUpHosts; |
41
|
|
|
$this->rsHost = $rsHost; |
42
|
|
|
$this->rsfHost = $rsfHost; |
43
|
|
|
$this->apiHost = $apiHost; |
44
|
|
|
$this->iovipHost = $iovipHost; |
45
|
|
|
$this->ttl = $ttl; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
//华东机房 |
49
|
|
|
public static function regionHuadong() |
50
|
|
|
{ |
51
|
|
|
$regionHuadong = new Region( |
52
|
|
|
array("up.qiniup.com"), |
53
|
|
|
array('upload.qiniup.com'), |
54
|
|
|
'rs-z0.qiniuapi.com', |
55
|
|
|
'rsf-z0.qiniuapi.com', |
56
|
|
|
'api.qiniuapi.com', |
57
|
|
|
'iovip.qbox.me' |
58
|
|
|
); |
59
|
|
|
return $regionHuadong; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
//华东机房内网上传 |
63
|
|
|
public static function qvmRegionHuadong() |
64
|
|
|
{ |
65
|
|
|
$qvmRegionHuadong = new Region( |
66
|
|
|
array("free-qvm-z0-xs.qiniup.com"), |
67
|
|
|
'rs-z0.qiniuapi.com', |
68
|
|
|
'rsf-z0.qiniuapi.com', |
69
|
|
|
'api.qiniuapi.com', |
70
|
|
|
'iovip.qbox.me' |
71
|
|
|
); |
72
|
|
|
return $qvmRegionHuadong; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
//华北机房内网上传 |
76
|
|
|
public static function qvmRegionHuabei() |
77
|
|
|
{ |
78
|
|
|
$qvmRegionHuabei = new Region( |
79
|
|
|
array("free-qvm-z1-zz.qiniup.com"), |
80
|
|
|
"rs-z1.qiniuapi.com", |
81
|
|
|
"rsf-z1.qiniuapi.com", |
82
|
|
|
"api-z1.qiniuapi.com", |
83
|
|
|
"iovip-z1.qbox.me" |
84
|
|
|
); |
85
|
|
|
return $qvmRegionHuabei; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
//华北机房 |
89
|
|
|
public static function regionHuabei() |
90
|
|
|
{ |
91
|
|
|
$regionHuabei = new Region( |
92
|
|
|
array('up-z1.qiniup.com'), |
93
|
|
|
array('upload-z1.qiniup.com'), |
94
|
|
|
"rs-z1.qiniuapi.com", |
95
|
|
|
"rsf-z1.qiniuapi.com", |
96
|
|
|
"api-z1.qiniuapi.com", |
97
|
|
|
"iovip-z1.qbox.me" |
98
|
|
|
); |
99
|
|
|
|
100
|
|
|
return $regionHuabei; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
//华南机房 |
104
|
|
|
public static function regionHuanan() |
105
|
|
|
{ |
106
|
|
|
$regionHuanan = new Region( |
107
|
|
|
array('up-z2.qiniup.com'), |
108
|
|
|
array('upload-z2.qiniup.com'), |
109
|
|
|
"rs-z2.qiniuapi.com", |
110
|
|
|
"rsf-z2.qiniuapi.com", |
111
|
|
|
"api-z2.qiniuapi.com", |
112
|
|
|
"iovip-z2.qbox.me" |
113
|
|
|
); |
114
|
|
|
return $regionHuanan; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
//华东2 机房 |
118
|
|
|
public static function regionHuadong2() |
119
|
|
|
{ |
120
|
|
|
return new Region( |
121
|
|
|
array('up-cn-east-2.qiniup.com'), |
122
|
|
|
array('upload-cn-east-2.qiniup.com'), |
123
|
|
|
"rs-cn-east-2.qiniuapi.com", |
124
|
|
|
"rsf-cn-east-2.qiniuapi.com", |
125
|
|
|
"api-cn-east-2.qiniuapi.com", |
126
|
|
|
"iovip-cn-east-2.qiniuio.com" |
127
|
|
|
); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
//北美机房 |
131
|
|
|
public static function regionNorthAmerica() |
132
|
|
|
{ |
133
|
|
|
//北美机房 |
134
|
|
|
$regionNorthAmerica = new Region( |
135
|
|
|
array('up-na0.qiniup.com'), |
136
|
|
|
array('upload-na0.qiniup.com'), |
137
|
|
|
"rs-na0.qiniuapi.com", |
138
|
|
|
"rsf-na0.qiniuapi.com", |
139
|
|
|
"api-na0.qiniuapi.com", |
140
|
|
|
"iovip-na0.qbox.me" |
141
|
|
|
); |
142
|
|
|
return $regionNorthAmerica; |
143
|
27 |
|
} |
144
|
|
|
|
145
|
27 |
|
//新加坡机房 |
146
|
27 |
|
public static function regionSingapore() |
147
|
27 |
|
{ |
148
|
27 |
|
//新加坡机房 |
149
|
|
|
$regionSingapore = new Region( |
150
|
|
|
array('up-as0.qiniup.com'), |
151
|
27 |
|
array('upload-as0.qiniup.com'), |
152
|
|
|
"rs-as0.qiniuapi.com", |
153
|
|
|
"rsf-as0.qiniuapi.com", |
154
|
27 |
|
"api-as0.qiniuapi.com", |
155
|
27 |
|
"iovip-as0.qbox.me" |
156
|
27 |
|
); |
157
|
27 |
|
return $regionSingapore; |
158
|
27 |
|
} |
159
|
27 |
|
|
160
|
27 |
|
/* |
161
|
27 |
|
* GET /v4/query?ak=<ak>&bucket=<bucket> |
162
|
27 |
|
* @param string $ak |
163
|
27 |
|
* @param string $bucket |
164
|
27 |
|
* @param string $ucHost|null |
165
|
27 |
|
* @param array $backupUcHosts |
166
|
27 |
|
* @param int $retryTimes |
167
|
27 |
|
* @param RequestOptions|null $reqOpt |
168
|
27 |
|
* @return Response |
|
|
|
|
169
|
27 |
|
**/ |
170
|
|
|
public static function queryRegion( |
171
|
|
|
$ak, |
172
|
27 |
|
$bucket, |
173
|
6 |
|
$ucHost = null, |
174
|
6 |
|
$backupUcHosts = array(), |
175
|
6 |
|
$retryTimes = 2, |
176
|
27 |
|
$reqOpt = null |
177
|
|
|
) { |
178
|
|
|
$region = new Region(); |
179
|
|
|
if (!$ucHost) { |
180
|
27 |
|
$ucHost = "https://" . Config::QUERY_REGION_HOST; |
181
|
6 |
|
} |
182
|
6 |
|
$url = $ucHost . '/v4/query' . "?ak=$ak&bucket=$bucket"; |
183
|
6 |
|
if ($reqOpt == null) { |
184
|
27 |
|
$reqOpt = new RequestOptions(); |
185
|
|
|
} |
186
|
|
|
$reqOpt->middlewares = array( |
187
|
|
|
new RetryDomainsMiddleware( |
188
|
|
|
$backupUcHosts, |
189
|
27 |
|
$retryTimes |
|
|
|
|
190
|
27 |
|
) |
191
|
27 |
|
); |
192
|
|
|
$ret = Client::get($url, array(), $reqOpt); |
193
|
|
|
if (!$ret->ok()) { |
194
|
27 |
|
return array(null, new Error($url, $ret)); |
|
|
|
|
195
|
|
|
} |
196
|
|
|
$r = ($ret->body === null) ? array() : $ret->json(); |
197
|
|
|
if (!is_array($r["hosts"]) || count($r["hosts"]) == 0) { |
198
|
|
|
return array(null, new Error($url, $ret)); |
|
|
|
|
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
// parse region; |
202
|
|
|
$regionHost = $r["hosts"][0]; |
203
|
|
|
$region->cdnUpHosts = array_merge($region->cdnUpHosts, $regionHost['up']['domains']); |
204
|
|
|
$region->srcUpHosts = array_merge($region->srcUpHosts, $regionHost['up']['domains']); |
205
|
|
|
|
206
|
|
|
// set specific hosts |
207
|
|
|
$region->iovipHost = $regionHost['io']['domains'][0]; |
208
|
|
|
if (isset($regionHost['rs']['domains']) && count($regionHost['rs']['domains']) > 0) { |
209
|
|
|
$region->rsHost = $regionHost['rs']['domains'][0]; |
210
|
|
|
} else { |
211
|
|
|
$region->rsHost = Config::RS_HOST; |
212
|
|
|
} |
213
|
|
|
if (isset($regionHost['rsf']['domains']) && count($regionHost['rsf']['domains']) > 0) { |
214
|
|
|
$region->rsfHost = $regionHost['rsf']['domains'][0]; |
215
|
|
|
} else { |
216
|
|
|
$region->rsfHost = Config::RSF_HOST; |
217
|
|
|
} |
218
|
|
|
if (isset($regionHost['api']['domains']) && count($regionHost['api']['domains']) > 0) { |
219
|
|
|
$region->apiHost = $regionHost['api']['domains'][0]; |
220
|
|
|
} else { |
221
|
|
|
$region->apiHost = Config::API_HOST; |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
// set ttl |
225
|
|
|
$region->ttl = $regionHost['ttl']; |
226
|
|
|
|
227
|
|
|
return $region; |
|
|
|
|
228
|
|
|
} |
229
|
|
|
} |
230
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths