Skip to content

Commit e251905

Browse files
committed
fixed config upload backup host miss
1 parent 326c9b3 commit e251905

File tree

4 files changed

+26
-17
lines changed

4 files changed

+26
-17
lines changed

src/Qiniu/Config.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,25 @@ final class Config
1212
const RSF_HOST = 'http://rsf.qbox.me'; // 列举操作Host
1313
const API_HOST = 'http://api.qiniu.com'; // 数据处理操作Host
1414

15-
public static $upHost; // 上传Host
16-
public static $upHostBackup; // 上传备用Host
15+
private $upHost; // 上传Host
16+
private $upHostBackup; // 上传备用Host
1717

18-
public function __construct() // 构造函数,默认为zone0
18+
public function __construct(Zone $z = null) // 构造函数,默认为zone0
1919
{
20-
self::setZone(Zone::zone0());
20+
if ($z === null) {
21+
$z = Zone::zone0();
22+
}
23+
$this->upHost = $z->upHost;
24+
$this->upHostBackup = $z->upHostBackup;
2125
}
22-
23-
public static function setZone(Zone $z)
26+
27+
public function getUpHost()
28+
{
29+
return $this->upHost;
30+
}
31+
32+
public function getUpHostBackup()
2433
{
25-
self::$upHost = $z->upHost;
26-
self::$upHostBackup = $z->upHostBackup;
34+
return $this->upHostBackup;
2735
}
2836
}

src/Qiniu/Storage/FormUploader.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ public static function put(
3232
}
3333
}
3434

35-
$response = Client::multipartPost($config::$upHost, $fields, 'file', $fname, $data, $mime);
35+
$response = Client::multipartPost($config->getUpHost(), $fields, 'file', $fname, $data, $mime);
3636
if (!$response->ok()) {
37-
return array(null, new Error($config::$upHost, $response));
37+
return array(null, new Error($config->getUpHost(), $response));
3838
}
3939
return array($response->json(), null);
4040
}
@@ -65,9 +65,9 @@ public static function putFile(
6565
}
6666
}
6767
$headers =array('Content-Type' => 'multipart/form-data');
68-
$response = client::post($config::$upHost, $fields, $headers);
68+
$response = client::post($config->getUpHost(), $fields, $headers);
6969
if (!$response->ok()) {
70-
return array(null, new Error($config::$upHost, $response));
70+
return array(null, new Error($config->getUpHost(), $response));
7171
}
7272
return array($response->json(), null);
7373
}

src/Qiniu/Storage/ResumeUploader.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ final class ResumeUploader
2424
private $contexts;
2525
private $host;
2626
private $currentUrl;
27+
private $config;
2728

2829
/**
2930
* 上传二进制流到七牛
@@ -52,11 +53,11 @@ public function __construct(
5253
$this->size = $size;
5354
$this->params = $params;
5455
$this->mime = $mime;
55-
$this->host = $config::$upHost;
5656
$this->contexts = array();
57+
$this->config = $config;
58+
$this->host = $config->getUpHost();
5759
}
5860

59-
6061
/**
6162
* 上传操作
6263
*/
@@ -77,7 +78,7 @@ public function upload()
7778
$ret = $response->json();
7879
}
7980
if ($response->statusCode < 0) {
80-
$this->host = $config::$upHostBackup;
81+
$this->host = $this->config->getUpHostBackup();
8182
}
8283
if ($response->needRetry() || !isset($ret['crc32']) || $crc != $ret['crc32']) {
8384
$response = $this->makeBlock($data, $blockSize);

src/Qiniu/Storage/UploadManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
*/
1414
final class UploadManager
1515
{
16-
public $config;
16+
private $config;
1717

18-
public function __construct($config = null)
18+
public function __construct(Conifg $config = null)
1919
{
2020
if ($config === null) {
2121
$config = new Config();

0 commit comments

Comments
 (0)