Skip to content

Commit c8412b3

Browse files
committed
merge qiniu master
2 parents 19534f2 + a7c996c commit c8412b3

File tree

14 files changed

+72
-60
lines changed

14 files changed

+72
-60
lines changed

CHANGELOG.md

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

3+
## 7.0.4 (2015-07-23)
4+
### 修正
5+
* 一些地方的严格比较检查
6+
* resumeupload 备用地址失效
7+
8+
## 7.0.3 (2015-07-10)
9+
### 修改
10+
* 多zone 支持
11+
312
## 7.0.2 (2015-04-18)
413
### 修改
514
* fetch 接口返回内容调整

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# Qiniu Resource Storage SDK for PHP
2-
[![@qiniu on weibo](http://img.shields.io/badge/weibo-%40qiniutek-blue.svg)](http://weibo.com/qiniutek)
2+
[![doxygen.io](http://doxygen.io/github.com/qiniu/php-sdk/?status.svg)](http://doxygen.io/github.com/qiniu/php-sdk/)
33
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](LICENSE)
44
[![Build Status](https://travis-ci.org/qiniu/php-sdk.svg)](https://travis-ci.org/qiniu/php-sdk)
55
[![Latest Stable Version](https://img.shields.io/packagist/v/qiniu/php-sdk.svg)](https://packagist.org/packages/qiniu/php-sdk)
66
[![Total Downloads](https://img.shields.io/packagist/dt/qiniu/php-sdk.svg)](https://packagist.org/packages/qiniu/php-sdk)
77
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/qiniu/php-sdk/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/qiniu/php-sdk/?branch=master)
88
[![Code Coverage](https://scrutinizer-ci.com/g/qiniu/php-sdk/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/qiniu/php-sdk/?branch=master)
99
[![Join Chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/qiniu/php-sdk?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
10+
[![@qiniu on weibo](http://img.shields.io/badge/weibo-%40qiniutek-blue.svg)](http://weibo.com/qiniutek)
11+
1012
## 安装
1113

1214
* 通过composer,这是推荐的方式,可以使用composer.json 声明依赖,或者运行下面的命令。SDK 包已经放到这里 [`qiniu/php-sdk`][install-packagist]

Zone.php

Whitespace-only changes.

src/Qiniu/Auth.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,16 @@ public function signRequest($urlString, $body, $contentType = null)
3030
{
3131
$url = parse_url($urlString);
3232
$data = '';
33-
if (isset($url['path'])) {
33+
if (array_key_exists('path', $url)) {
3434
$data = $url['path'];
3535
}
36-
if (isset($url['query'])) {
36+
if (array_key_exists('query', $url)) {
3737
$data .= '?' . $url['query'];
3838
}
3939
$data .= "\n";
4040

41-
if ($body != null &&
42-
($contentType == 'application/x-www-form-urlencoded') || $contentType == 'application/json') {
41+
if ($body !== null &&
42+
in_array((string) $contentType, array('application/x-www-form-urlencoded', 'application/json'), true)) {
4343
$data .= $body;
4444
}
4545
return $this->sign($data);
@@ -76,7 +76,7 @@ public function uploadToken(
7676
) {
7777
$deadline = time() + $expires;
7878
$scope = $bucket;
79-
if ($key != null) {
79+
if ($key !== null) {
8080
$scope .= ':' . $key;
8181
}
8282
$args = array();
@@ -120,14 +120,14 @@ public function uploadToken(
120120

121121
private static function copyPolicy(&$policy, $originPolicy, $strictPolicy)
122122
{
123-
if ($originPolicy == null) {
124-
return;
123+
if ($originPolicy === null) {
124+
return array();
125125
}
126126
foreach ($originPolicy as $key => $value) {
127-
if (in_array($key, self::$deprecatedPolicyFields)) {
127+
if (in_array((string) $key, self::$deprecatedPolicyFields, true)) {
128128
throw new \InvalidArgumentException("{$key} has deprecated");
129129
}
130-
if (!$strictPolicy || in_array($key, self::$policyFields)) {
130+
if (!$strictPolicy || in_array((string) $key, self::$policyFields, true)) {
131131
$policy[$key] = $value;
132132
}
133133
}

src/Qiniu/Config.php

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,34 @@
33

44
final class Config
55
{
6-
const SDK_VER = '7.0.2';
6+
const SDK_VER = '7.0.4';
77

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

1010
const IO_HOST = 'http://iovip.qbox.me'; // 七牛源站Host
1111
const RS_HOST = 'http://rs.qbox.me'; // 文件元信息管理操作Host
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/Etag.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ private static function calcSha1($data)
2020
{
2121
$sha1Str = sha1($data, true);
2222
$err = error_get_last();
23-
if ($err != null) {
23+
if ($err !== null) {
2424
return array(null, $err);
2525
}
2626
$byteArray = unpack('C*', $sha1Str);
@@ -32,7 +32,7 @@ public static function sum($filename)
3232
{
3333
$fhandler = fopen($filename, 'r');
3434
$err = error_get_last();
35-
if ($err != null) {
35+
if ($err !== null) {
3636
return array(null, $err);
3737
}
3838

@@ -48,7 +48,7 @@ public static function sum($filename)
4848
if ($blockCnt <= 1) {
4949
array_push($sha1Buf, 0x16);
5050
$fdata = fread($fhandler, Config::BLOCK_SIZE);
51-
if ($err != null) {
51+
if ($err !== null) {
5252
fclose($fhandler);
5353
return array(null, $err);
5454
}
@@ -60,7 +60,7 @@ public static function sum($filename)
6060
for ($i=0; $i < $blockCnt; $i++) {
6161
$fdata = fread($fhandler, Config::BLOCK_SIZE);
6262
list($sha1Code, $err) = self::calcSha1($fdata);
63-
if ($err != null) {
63+
if ($err !== null) {
6464
fclose($fhandler);
6565
return array(null, $err);
6666
}

src/Qiniu/Http/Response.php

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ public function __construct($code, $duration, array $headers = array(), $body =
8484
$this->body = $body;
8585
$this->error = $error;
8686
$this->jsonData = null;
87-
if ($error != null) {
87+
if ($error !== null) {
8888
return;
8989
}
9090

91-
if ($body == null) {
91+
if ($body === null) {
9292
if ($code >= 400) {
9393
$this->error = self::$statusTexts[$code];
9494
}
@@ -98,18 +98,16 @@ public function __construct($code, $duration, array $headers = array(), $body =
9898
try {
9999
$jsonData = self::bodyJson($body);
100100
if ($code >=400) {
101-
if ($jsonData['error'] != null) {
101+
$this->error = $body;
102+
if ($jsonData['error'] !== null) {
102103
$this->error = $jsonData['error'];
103-
} else {
104-
$this->error = $body;
105104
}
106105
}
107106
$this->jsonData = $jsonData;
108107
} catch (\InvalidArgumentException $e) {
108+
$this->error = $body;
109109
if ($code >= 200 && $code < 300) {
110110
$this->error = $e->getMessage();
111-
} else {
112-
$this->error = $body;
113111
}
114112
}
115113
} elseif ($code >=400) {
@@ -127,19 +125,19 @@ private static function bodyJson($body, array $config = array())
127125
{
128126
return \Qiniu\json_decode(
129127
(string) $body,
130-
isset($config['object']) ? !$config['object'] : true,
128+
array_key_exists('object', $config) ? !$config['object'] : true,
131129
512,
132-
isset($config['big_int_strings']) ? JSON_BIGINT_AS_STRING : 0
130+
array_key_exists('big_int_strings', $config) ? JSON_BIGINT_AS_STRING : 0
133131
);
134132
}
135133

136134
public function xVia()
137135
{
138136
$via = $this->headers['X-Via'];
139-
if ($via == null) {
137+
if ($via === null) {
140138
$via = $this->headers['X-Px'];
141139
}
142-
if ($via == null) {
140+
if ($via === null) {
143141
$via = $this->headers['Fw-Via'];
144142
}
145143
return $via;
@@ -157,20 +155,20 @@ public function xReqId()
157155

158156
public function ok()
159157
{
160-
return $this->statusCode >= 200 && $this->statusCode < 300 && $this->error == null;
158+
return $this->statusCode >= 200 && $this->statusCode < 300 && $this->error === null;
161159
}
162160

163161
public function needRetry()
164162
{
165163
$code = $this->statusCode;
166-
if ($code< 0 || ($code / 100 == 5 and $code != 579) || $code == 996) {
164+
if ($code< 0 || ($code / 100 === 5 and $code !== 579) || $code === 996) {
167165
return true;
168166
}
169167
}
170168

171169
private static function isJson($headers)
172170
{
173-
return isset($headers['Content-Type']) &&
171+
return array_key_exists('Content-Type', $headers) &&
174172
strpos($headers['Content-Type'], 'application/json') === 0;
175173
}
176174
}

src/Qiniu/Processing/Operation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function execute($key, $fops)
3838
if (!$resp->ok()) {
3939
return array(null, new Error($url, $resp));
4040
}
41-
if ($resp->json() != null) {
41+
if ($resp->json() !== null) {
4242
return array($resp->json(), null);
4343
}
4444
return array($resp->body, null);

src/Qiniu/Processing/PersistentFop.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ final class PersistentFop
3434
private $notify_url;
3535

3636
/**
37-
* @var 是否强制覆盖已有的重名文件
37+
* @var boolean 是否强制覆盖已有的重名文件
3838
*/
3939
private $force;
4040

src/Qiniu/Storage/BucketManager.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
*/
1414
final class BucketManager
1515
{
16-
/**
17-
* @var Qiniu\Auth 账号管理密钥对
18-
*/
1916
private $auth;
2017

2118
public function __construct(Auth $auth)
@@ -30,7 +27,7 @@ public function __construct(Auth $auth)
3027
*/
3128
public function buckets()
3229
{
33-
return $this->rsget('/buckets');
30+
return $this->rsGet('/buckets');
3431
}
3532

3633
/**
@@ -70,10 +67,10 @@ public function listFiles($bucket, $prefix = null, $marker = null, $limit = 1000
7067
}
7168
$url = Config::RSF_HOST . '/list?' . http_build_query($query);
7269
list($ret, $error) = $this->get($url);
73-
if ($ret == null) {
70+
if ($ret === null) {
7471
return array(null, null, $error);
7572
}
76-
$marker = isset($ret['marker']) ? $ret['marker'] : null;
73+
$marker = array_key_exists('marker', $ret) ? $ret['marker'] : null;
7774
return array($ret['items'], $marker, null);
7875
}
7976

@@ -294,7 +291,7 @@ private function post($url, $body)
294291
if (!$ret->ok()) {
295292
return array(null, new Error($url, $ret));
296293
}
297-
$r = $ret->body == null ? array() : $ret->json();
294+
$r = ($ret->body === null) ? array() : $ret->json();
298295
return array($r, null);
299296
}
300297

@@ -338,7 +335,7 @@ private static function oneKeyBatch($operation, $bucket, $keys)
338335

339336
private static function twoKeyBatch($operation, $source_bucket, $key_pairs, $target_bucket)
340337
{
341-
if ($target_bucket == null) {
338+
if ($target_bucket === null) {
342339
$target_bucket = $source_bucket;
343340
}
344341
$data = array();

0 commit comments

Comments
 (0)