Skip to content

Commit

Permalink
Merge remote-tracking branch 'qiniu/master' into copy_force_param
Browse files Browse the repository at this point in the history
  • Loading branch information
rwifeng committed Nov 18, 2016
2 parents beaf332 + 3c06a10 commit 0ecd8ca
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 15 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
#Changelog

## 7.1.2 (2016-11-12)
### 修正
* 明确抛出获取各区域域名失败时的报错

## 7.1.1 (2016-11-02)
### 修正
* 多区域配置文件存储目录从home修改到tmp目录


## 7.1.0 (2016-10-22)
### 增加
* 多存储区域的支持

## 7.0.8 (2016-07-19)
### 增加
* demo
Expand Down
2 changes: 1 addition & 1 deletion src/Qiniu/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

final class Config
{
const SDK_VER = '7.1.0';
const SDK_VER = '7.1.2';

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

Expand Down
12 changes: 10 additions & 2 deletions src/Qiniu/Storage/FormUploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ public static function put(
}
}

$upHost = $config->zone->getUpHostByToken($upToken);
list($upHost, $err) = $config->zone->getUpHostByToken($upToken);
if ($err != null) {
return array(null, $err);
}

$response = Client::multipartPost($upHost, $fields, 'file', $fname, $data, $mime);
if (!$response->ok()) {
return array(null, new Error($upHost, $response));
Expand Down Expand Up @@ -99,7 +103,11 @@ public static function putFile(
$fields['key'] = $key;
$headers =array('Content-Type' => 'multipart/form-data');

$upHost = $config->zone->getUpHostByToken($upToken);
list($upHost, $err) = $config->zone->getUpHostByToken($upToken);
if ($err != null) {
return array(null, $err);
}

$response = client::post($upHost, $fields, $headers);
if (!$response->ok()) {
return array(null, new Error($upHost, $response));
Expand Down
13 changes: 11 additions & 2 deletions src/Qiniu/Storage/ResumeUploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ public function __construct(
$this->mime = $mime;
$this->contexts = array();
$this->config = $config;
$this->host = $config->zone->getUpHostByToken($upToken);

list($upHost, $err) = $config->zone->getUpHostByToken($upToken);
if ($err != null) {
throw new \Exception($err, 1);
}
$this->host = $upHost;
}

/**
Expand All @@ -76,7 +81,11 @@ public function upload()
$ret = $response->json();
}
if ($response->statusCode < 0) {
$this->host = $this->config->zone->getBackupUpHostByToken($this->upToken);
list($bakHost, $err) = $this->config->zone->getBackupUpHostByToken($this->upToken);
if ($err != null) {
return array(null, $err);
}
$this->host = $bakHost;
}
if ($response->needRetry() || !isset($ret['crc32']) || $crc != $ret['crc32']) {
$response = $this->makeBlock($data, $blockSize);
Expand Down
11 changes: 5 additions & 6 deletions src/Qiniu/Zone.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ public function __construct($scheme = null)
public function getUpHostByToken($uptoken)
{
list($ak, $bucket) = $this->unmarshalUpToken($uptoken);
list($upHosts,) = $this->getUpHosts($ak, $bucket);
return $upHosts[0];
list($upHosts, $err) = $this->getUpHosts($ak, $bucket);
return array($upHosts[0], $err);
}

public function getBackupUpHostByToken($uptoken)
{
list($ak, $bucket) = $this->unmarshalUpToken($uptoken);
list($upHosts,) = $this->getUpHosts($ak, $bucket);
list($upHosts, $err) = $this->getUpHosts($ak, $bucket);

$upHost = isset($upHosts[1]) ? $upHosts[1] : $upHosts[0];
return $upHost;
return array($upHost, $err);
}

public function getIoHost($ak, $bucket)
Expand Down Expand Up @@ -153,8 +153,7 @@ private function hostCacheToFile()

private function hostCacheFilePath()
{
$home = getenv('HOME');
return $home . '/.qiniu_phpsdk_hostscache.json';
return sys_get_temp_dir() . '/.qiniu_phpsdk_hostscache.json';
}

/* 请求包:
Expand Down
42 changes: 38 additions & 4 deletions tests/Qiniu/Tests/ZoneTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class ZoneTest extends \PHPUnit_Framework_TestCase

protected $bucketName;
protected $bucketNameBC;
protected $bucketNameNA;


protected function setUp()
Expand All @@ -22,6 +23,9 @@ protected function setUp()
global $bucketNameBC;
$this->bucketNameBC = $bucketNameBC;

global $bucketNameNA;
$this->bucketNameNA = $bucketNameNA;

global $accessKey;
$this->ak = $accessKey;

Expand All @@ -32,23 +36,37 @@ protected function setUp()
public function testUpHosts()
{

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

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

// test na http
list($upHosts, $err) = $this->zone->getUpHosts($this->ak, $this->bucketNameNA);
$this->assertNull($err);
$this->assertEquals('http://up-na0.qiniu.com', $upHosts[0]);

// test nb https
list($upHosts, $err) = $this->zoneHttps->getUpHosts($this->ak, $this->bucketName);
$this->assertNull($err);
$this->assertEquals('https://up.qbox.me', $upHosts[0]);

// test bc https
list($upHosts, $err) = $this->zoneHttps->getUpHosts($this->ak, $this->bucketNameBC);
$this->assertNull($err);
$this->assertEquals('https://up-z1.qbox.me', $upHosts[0]);

// test na https
list($upHosts, $err) = $this->zoneHttps->getUpHosts($this->ak, $this->bucketNameNA);
$this->assertNull($err);
$this->assertEquals('https://up-na0.qbox.me', $upHosts[0]);
}

public function testUpHostByToken()
Expand All @@ -58,36 +76,52 @@ public function testUpHostByToken()
3RzIjpbImh0dHA6XC9cL3VwLXoxLnFpbml1LmNvbSIsImh0dHA6XC9cL3VwbG9hZC16MS5xaW5p
dS5jb20iLCItSCB1cC16MS5xaW5pdS5jb20gaHR0cDpcL1wvMTA2LjM4LjIyNy4yNyJdfQ==';

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

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


$uptoken_bc_https = 'QWYn5TFQsLLU1pL5MFEmX3s5DmHdUThav9WyOWOm:7I47O-vFcN5TKO
6D7cobHPVkyIA=:eyJzY29wZSI6InBocHNkay1iYyIsImRlYWRsaW5lIjoxNDcwNzIyNzQ1LCJ1c
Ehvc3RzIjpbImh0dHBzOlwvXC91cC16MS5xYm94Lm1lIl19';
$upHost = $this->zoneHttps->getUpHostByToken($uptoken_bc_https);
list($upHost, $err) = $this->zoneHttps->getUpHostByToken($uptoken_bc_https);
$this->assertEquals('https://up-z1.qbox.me', $upHost);
$this->assertEquals(null, $err);

$upHostBackup = $this->zoneHttps->getBackupUpHostByToken($uptoken_bc_https);
list($upHostBackup, $err) = $this->zoneHttps->getBackupUpHostByToken($uptoken_bc_https);
$this->assertEquals('https://up-z1.qbox.me', $upHostBackup);
$this->assertEquals(null, $err);
}

public function testIoHosts()
{

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

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

// test na http
$ioHost = $this->zone->getIoHost($this->ak, $this->bucketNameNA);
$this->assertEquals('http://iovip-na0.qbox.me', $ioHost);

// test nb https
$ioHost = $this->zoneHttps->getIoHost($this->ak, $this->bucketName);
$this->assertEquals('https://iovip.qbox.me', $ioHost);

// test bc https
$ioHost = $this->zoneHttps->getIoHost($this->ak, $this->bucketNameBC);
$this->assertEquals('https://iovip-z1.qbox.me', $ioHost);

// test na https
$ioHost = $this->zoneHttps->getIoHost($this->ak, $this->bucketNameNA);
$this->assertEquals('https://iovip-na0.qbox.me', $ioHost);
}
}
1 change: 1 addition & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
$key = 'php-logo.png';
$key2 = 'niu.jpg';
$bucketNameBC = 'phpsdk-bc';
$bucketNameNA = 'phpsdk-na';

$dummyAccessKey = 'abcdefghklmnopq';
$dummySecretKey = '1234567890';
Expand Down

0 comments on commit 0ecd8ca

Please sign in to comment.