Skip to content

Commit 0ecd8ca

Browse files
committed
Merge remote-tracking branch 'qiniu/master' into copy_force_param
2 parents beaf332 + 3c06a10 commit 0ecd8ca

File tree

7 files changed

+79
-15
lines changed

7 files changed

+79
-15
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
#Changelog
22

3+
## 7.1.2 (2016-11-12)
4+
### 修正
5+
* 明确抛出获取各区域域名失败时的报错
6+
7+
## 7.1.1 (2016-11-02)
8+
### 修正
9+
* 多区域配置文件存储目录从home修改到tmp目录
10+
11+
12+
## 7.1.0 (2016-10-22)
13+
### 增加
14+
* 多存储区域的支持
15+
316
## 7.0.8 (2016-07-19)
417
### 增加
518
* demo

src/Qiniu/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
final class Config
77
{
8-
const SDK_VER = '7.1.0';
8+
const SDK_VER = '7.1.2';
99

1010
const BLOCK_SIZE = 4194304; //4*1024*1024 分块上传块大小,该参数为接口规格,不能修改
1111

src/Qiniu/Storage/FormUploader.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ public static function put(
4949
}
5050
}
5151

52-
$upHost = $config->zone->getUpHostByToken($upToken);
52+
list($upHost, $err) = $config->zone->getUpHostByToken($upToken);
53+
if ($err != null) {
54+
return array(null, $err);
55+
}
56+
5357
$response = Client::multipartPost($upHost, $fields, 'file', $fname, $data, $mime);
5458
if (!$response->ok()) {
5559
return array(null, new Error($upHost, $response));
@@ -99,7 +103,11 @@ public static function putFile(
99103
$fields['key'] = $key;
100104
$headers =array('Content-Type' => 'multipart/form-data');
101105

102-
$upHost = $config->zone->getUpHostByToken($upToken);
106+
list($upHost, $err) = $config->zone->getUpHostByToken($upToken);
107+
if ($err != null) {
108+
return array(null, $err);
109+
}
110+
103111
$response = client::post($upHost, $fields, $headers);
104112
if (!$response->ok()) {
105113
return array(null, new Error($upHost, $response));

src/Qiniu/Storage/ResumeUploader.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,12 @@ public function __construct(
5454
$this->mime = $mime;
5555
$this->contexts = array();
5656
$this->config = $config;
57-
$this->host = $config->zone->getUpHostByToken($upToken);
57+
58+
list($upHost, $err) = $config->zone->getUpHostByToken($upToken);
59+
if ($err != null) {
60+
throw new \Exception($err, 1);
61+
}
62+
$this->host = $upHost;
5863
}
5964

6065
/**
@@ -76,7 +81,11 @@ public function upload()
7681
$ret = $response->json();
7782
}
7883
if ($response->statusCode < 0) {
79-
$this->host = $this->config->zone->getBackupUpHostByToken($this->upToken);
84+
list($bakHost, $err) = $this->config->zone->getBackupUpHostByToken($this->upToken);
85+
if ($err != null) {
86+
return array(null, $err);
87+
}
88+
$this->host = $bakHost;
8089
}
8190
if ($response->needRetry() || !isset($ret['crc32']) || $crc != $ret['crc32']) {
8291
$response = $this->makeBlock($data, $blockSize);

src/Qiniu/Zone.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ public function __construct($scheme = null)
2828
public function getUpHostByToken($uptoken)
2929
{
3030
list($ak, $bucket) = $this->unmarshalUpToken($uptoken);
31-
list($upHosts,) = $this->getUpHosts($ak, $bucket);
32-
return $upHosts[0];
31+
list($upHosts, $err) = $this->getUpHosts($ak, $bucket);
32+
return array($upHosts[0], $err);
3333
}
3434

3535
public function getBackupUpHostByToken($uptoken)
3636
{
3737
list($ak, $bucket) = $this->unmarshalUpToken($uptoken);
38-
list($upHosts,) = $this->getUpHosts($ak, $bucket);
38+
list($upHosts, $err) = $this->getUpHosts($ak, $bucket);
3939

4040
$upHost = isset($upHosts[1]) ? $upHosts[1] : $upHosts[0];
41-
return $upHost;
41+
return array($upHost, $err);
4242
}
4343

4444
public function getIoHost($ak, $bucket)
@@ -153,8 +153,7 @@ private function hostCacheToFile()
153153

154154
private function hostCacheFilePath()
155155
{
156-
$home = getenv('HOME');
157-
return $home . '/.qiniu_phpsdk_hostscache.json';
156+
return sys_get_temp_dir() . '/.qiniu_phpsdk_hostscache.json';
158157
}
159158

160159
/* 请求包:

tests/Qiniu/Tests/ZoneTest.php

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class ZoneTest extends \PHPUnit_Framework_TestCase
1212

1313
protected $bucketName;
1414
protected $bucketNameBC;
15+
protected $bucketNameNA;
1516

1617

1718
protected function setUp()
@@ -22,6 +23,9 @@ protected function setUp()
2223
global $bucketNameBC;
2324
$this->bucketNameBC = $bucketNameBC;
2425

26+
global $bucketNameNA;
27+
$this->bucketNameNA = $bucketNameNA;
28+
2529
global $accessKey;
2630
$this->ak = $accessKey;
2731

@@ -32,23 +36,37 @@ protected function setUp()
3236
public function testUpHosts()
3337
{
3438

39+
// test nb http
3540
list($upHosts, $err) = $this->zone->getUpHosts($this->ak, $this->bucketName);
3641
$this->assertNull($err);
3742
$this->assertEquals('http://up.qiniu.com', $upHosts[0]);
3843
$this->assertEquals('http://upload.qiniu.com', $upHosts[1]);
3944

45+
// test bc http
4046
list($upHosts, $err) = $this->zone->getUpHosts($this->ak, $this->bucketNameBC);
4147
$this->assertNull($err);
4248
$this->assertEquals('http://up-z1.qiniu.com', $upHosts[0]);
4349
$this->assertEquals('http://upload-z1.qiniu.com', $upHosts[1]);
4450

51+
// test na http
52+
list($upHosts, $err) = $this->zone->getUpHosts($this->ak, $this->bucketNameNA);
53+
$this->assertNull($err);
54+
$this->assertEquals('http://up-na0.qiniu.com', $upHosts[0]);
55+
56+
// test nb https
4557
list($upHosts, $err) = $this->zoneHttps->getUpHosts($this->ak, $this->bucketName);
4658
$this->assertNull($err);
4759
$this->assertEquals('https://up.qbox.me', $upHosts[0]);
4860

61+
// test bc https
4962
list($upHosts, $err) = $this->zoneHttps->getUpHosts($this->ak, $this->bucketNameBC);
5063
$this->assertNull($err);
5164
$this->assertEquals('https://up-z1.qbox.me', $upHosts[0]);
65+
66+
// test na https
67+
list($upHosts, $err) = $this->zoneHttps->getUpHosts($this->ak, $this->bucketNameNA);
68+
$this->assertNull($err);
69+
$this->assertEquals('https://up-na0.qbox.me', $upHosts[0]);
5270
}
5371

5472
public function testUpHostByToken()
@@ -58,36 +76,52 @@ public function testUpHostByToken()
5876
3RzIjpbImh0dHA6XC9cL3VwLXoxLnFpbml1LmNvbSIsImh0dHA6XC9cL3VwbG9hZC16MS5xaW5p
5977
dS5jb20iLCItSCB1cC16MS5xaW5pdS5jb20gaHR0cDpcL1wvMTA2LjM4LjIyNy4yNyJdfQ==';
6078

61-
$upHost = $this->zone->getUpHostByToken($uptoken_bc);
79+
list($upHost, $err) = $this->zone->getUpHostByToken($uptoken_bc);
6280
$this->assertEquals('http://up-z1.qiniu.com', $upHost);
81+
$this->assertEquals(null, $err);
6382

64-
$upHostBackup = $this->zone->getBackupUpHostByToken($uptoken_bc);
83+
list($upHostBackup, $err) = $this->zone->getBackupUpHostByToken($uptoken_bc);
6584
$this->assertEquals('http://upload-z1.qiniu.com', $upHostBackup);
85+
$this->assertEquals(null, $err);
6686

6787

6888
$uptoken_bc_https = 'QWYn5TFQsLLU1pL5MFEmX3s5DmHdUThav9WyOWOm:7I47O-vFcN5TKO
6989
6D7cobHPVkyIA=:eyJzY29wZSI6InBocHNkay1iYyIsImRlYWRsaW5lIjoxNDcwNzIyNzQ1LCJ1c
7090
Ehvc3RzIjpbImh0dHBzOlwvXC91cC16MS5xYm94Lm1lIl19';
71-
$upHost = $this->zoneHttps->getUpHostByToken($uptoken_bc_https);
91+
list($upHost, $err) = $this->zoneHttps->getUpHostByToken($uptoken_bc_https);
7292
$this->assertEquals('https://up-z1.qbox.me', $upHost);
93+
$this->assertEquals(null, $err);
7394

74-
$upHostBackup = $this->zoneHttps->getBackupUpHostByToken($uptoken_bc_https);
95+
list($upHostBackup, $err) = $this->zoneHttps->getBackupUpHostByToken($uptoken_bc_https);
7596
$this->assertEquals('https://up-z1.qbox.me', $upHostBackup);
97+
$this->assertEquals(null, $err);
7698
}
7799

78100
public function testIoHosts()
79101
{
80102

103+
// test nb http
81104
$ioHost = $this->zone->getIoHost($this->ak, $this->bucketName);
82105
$this->assertEquals('http://iovip.qbox.me', $ioHost);
83106

107+
// test bc http
84108
$ioHost = $this->zone->getIoHost($this->ak, $this->bucketNameBC);
85109
$this->assertEquals('http://iovip-z1.qbox.me', $ioHost);
86110

111+
// test na http
112+
$ioHost = $this->zone->getIoHost($this->ak, $this->bucketNameNA);
113+
$this->assertEquals('http://iovip-na0.qbox.me', $ioHost);
114+
115+
// test nb https
87116
$ioHost = $this->zoneHttps->getIoHost($this->ak, $this->bucketName);
88117
$this->assertEquals('https://iovip.qbox.me', $ioHost);
89118

119+
// test bc https
90120
$ioHost = $this->zoneHttps->getIoHost($this->ak, $this->bucketNameBC);
91121
$this->assertEquals('https://iovip-z1.qbox.me', $ioHost);
122+
123+
// test na https
124+
$ioHost = $this->zoneHttps->getIoHost($this->ak, $this->bucketNameNA);
125+
$this->assertEquals('https://iovip-na0.qbox.me', $ioHost);
92126
}
93127
}

tests/bootstrap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
$key = 'php-logo.png';
1212
$key2 = 'niu.jpg';
1313
$bucketNameBC = 'phpsdk-bc';
14+
$bucketNameNA = 'phpsdk-na';
1415

1516
$dummyAccessKey = 'abcdefghklmnopq';
1617
$dummySecretKey = '1234567890';

0 commit comments

Comments
 (0)