Skip to content

Commit 65856e0

Browse files
committed
Merge pull request #119 from rwifeng/code_comments
Code comments
2 parents 3677cf0 + 4d35517 commit 65856e0

File tree

9 files changed

+292
-14
lines changed

9 files changed

+292
-14
lines changed

CHANGELOG.md

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

3+
## 7.0.1 (2015-03-27)
4+
### 增加
5+
* 增加代码注释
6+
37
## 7.0.0 (2015-02-03)
48

59
### 增加

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
}
1414
],
1515
"require": {
16-
"php": ">=5.3.3"
16+
"php": ">=5.3.3",
17+
"squizlabs/php_codesniffer": "~2.3"
1718
},
1819
"require-dev": {
19-
"phpunit/phpunit": "~4.0",
20-
"squizlabs/php_codesniffer": "~2.0"
20+
"phpunit/phpunit": "~4.0"
2121
},
2222
"autoload": {
2323
"psr-4": {"Qiniu\\": "src/Qiniu"},

src/Qiniu/Auth.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ public function uploadToken(
8787
return $this->signWithData($b);
8888
}
8989

90+
/**
91+
*上传策略,参数规格详见
92+
*http://developer.qiniu.com/docs/v6/api/reference/security/put-policy.html
93+
*/
9094
private static $policyFields = array(
9195
'callbackUrl',
9296
'callbackBody',

src/Qiniu/Config.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ final class Config
55
{
66
const SDK_VER = '7.0.0';
77

8-
const IO_HOST = 'http://iovip.qbox.me';
9-
const RS_HOST = 'http://rs.qbox.me';
10-
const RSF_HOST = 'http://rsf.qbox.me';
11-
const API_HOST = 'http://api.qiniu.com';
8+
const IO_HOST = 'http://iovip.qbox.me'; // 七牛源站Host
9+
const RS_HOST = 'http://rs.qbox.me'; // 文件元信息管理操作Host
10+
const RSF_HOST = 'http://rsf.qbox.me'; // 列举操作Host
11+
const API_HOST = 'http://api.qiniu.com'; // 数据处理操作Host
1212

13-
const UPAUTO_HOST = 'http://up.qiniu.com';
14-
const UPDX_HOST = 'http://updx.qiniu.com';
15-
const UPLT_HOST = 'http://uplt.qiniu.com';
16-
const UPYD_HOST = 'http://upyd.qiniu.com';
17-
const UPBACKUP_HOST = 'http://upload.qiniu.com';
13+
const UPAUTO_HOST = 'http://up.qiniu.com'; // 默认上传Host
14+
const UPDX_HOST = 'http://updx.qiniu.com'; // 电信上传Host
15+
const UPLT_HOST = 'http://uplt.qiniu.com'; // 联通上传Host
16+
const UPYD_HOST = 'http://upyd.qiniu.com'; // 移动上传Host
17+
const UPBACKUP_HOST = 'http://upload.qiniu.com'; // 备用上传Host
1818

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

21-
public static $defaultHost = self::UPAUTO_HOST;
21+
public static $defaultHost = self::UPAUTO_HOST; // 设置为默认上传Host
2222
}

src/Qiniu/Processing/PersistentFop.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,31 @@
66
use Qiniu\Http\Error;
77
use Qiniu\Processing\Operation;
88

9+
/**
10+
* 持久化处理类,该类用于主动触发异步持久化操作.
11+
*
12+
* @link http://developer.qiniu.com/docs/v6/api/reference/fop/pfop/pfop.html
13+
*/
914
final class PersistentFop
1015
{
16+
/**
17+
* @var 账号管理密钥对,Auth对象
18+
*/
1119
private $auth;
20+
21+
/**
22+
* @var 操作资源所在空间
23+
*/
1224
private $bucket;
25+
26+
/**
27+
* @var 多媒体处理队列,详见 https://portal.qiniu.com/mps/pipeline
28+
*/
1329
private $pipeline;
30+
31+
/**
32+
* @var 持久化处理结果通知URL
33+
*/
1434
private $notify_url;
1535

1636
public function __construct($auth, $bucket, $pipeline = null, $notify_url = null, $force = false)
@@ -22,6 +42,14 @@ public function __construct($auth, $bucket, $pipeline = null, $notify_url = null
2242
$this->force = $force;
2343
}
2444

45+
/**
46+
* 列取空间的文件列表
47+
*
48+
* @param $key 待处理的源文件
49+
* @param $fops 处理详细操作,规格详见 http://developer.qiniu.com/docs/v6/api/reference/fop/
50+
*
51+
* @return array[] 返回持久化处理的persistentId, 和返回的错误。
52+
*/
2553
public function execute($key, array $fops)
2654
{
2755
$ops = implode(';', $fops);

src/Qiniu/Storage/BucketManager.php

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,53 @@
66
use Qiniu\Http\Client;
77
use Qiniu\Http\Error;
88

9+
/**
10+
* 主要涉及了空间资源管理及批量操作接口的实现,具体的接口规格可以参考
11+
*
12+
* @link http://developer.qiniu.com/docs/v6/api/reference/rs/
13+
*/
914
final class BucketManager
1015
{
16+
/**
17+
* @var Qiniu\Auth 账号管理密钥对
18+
*/
1119
private $auth;
1220

1321
public function __construct(Auth $auth)
1422
{
1523
$this->auth = $auth;
1624
}
1725

26+
/**
27+
* 获取指定账号下所有的空间名。
28+
*
29+
* @return string[] 包含所有空间名
30+
*/
1831
public function buckets()
1932
{
2033
return $this->rsget('/buckets');
2134
}
2235

36+
/**
37+
* 列取空间的文件列表
38+
*
39+
* @param $bucket 空间名
40+
* @param $prefix 列举前缀
41+
* @param $marker 列举标识符
42+
* @param $limit 单次列举个数限制
43+
* @param $delimiter 指定目录分隔符
44+
*
45+
* @return array[] 包含文件信息的数组,类似:[
46+
* {
47+
* "hash" => "<Hash string>",
48+
* "key" => "<Key string>",
49+
* "fsize" => "<file size>",
50+
* "putTime" => "<file modify time>"
51+
* },
52+
* ...
53+
* ]
54+
* @link http://developer.qiniu.com/docs/v6/api/reference/rs/list.html
55+
*/
2356
public function listFiles($bucket, $prefix = null, $marker = null, $limit = 1000, $delimiter = null)
2457
{
2558
$query = array('bucket' => $bucket);
@@ -44,24 +77,70 @@ public function listFiles($bucket, $prefix = null, $marker = null, $limit = 1000
4477
return array($ret['items'], $marker, null);
4578
}
4679

80+
/**
81+
* 获取资源的元信息,但不返回文件内容
82+
*
83+
* @param $bucket 待获取信息资源所在的空间
84+
* @param $key 待获取资源的文件名
85+
*
86+
* @return array[] 包含文件信息的数组,类似:
87+
* [
88+
* "hash" => "<Hash string>",
89+
* "key" => "<Key string>",
90+
* "fsize" => "<file size>",
91+
* "putTime" => "<file modify time>"
92+
* ]
93+
*
94+
* @link http://developer.qiniu.com/docs/v6/api/reference/rs/stat.html
95+
*/
4796
public function stat($bucket, $key)
4897
{
4998
$path = '/stat/' . \Qiniu\entry($bucket, $key);
5099
return $this->rsGet($path);
51100
}
52101

102+
/**
103+
* 删除指定资源
104+
*
105+
* @param $bucket 待删除资源所在的空间
106+
* @param $key 待删除资源的文件名
107+
*
108+
* @return 成功返回NULL,失败返回对象{"error" => "<errMsg string>", ...}
109+
* @link http://developer.qiniu.com/docs/v6/api/reference/rs/delete.html
110+
*/
53111
public function delete($bucket, $key)
54112
{
55113
$path = '/delete/' . \Qiniu\entry($bucket, $key);
56114
list($_, $error) = $this->rsPost($path);
57115
return $error;
58116
}
59117

118+
119+
/**
120+
* 给资源进行重命名,本质为move操作。
121+
*
122+
* @param $bucket 待操作资源所在空间
123+
* @param $oldname 待操作资源文件名
124+
* @param $newname 目标资源文件名
125+
*
126+
* @return 成功返回NULL,失败返回对象{"error" => "<errMsg string>", ...}
127+
*/
60128
public function rename($bucket, $oldname, $newname)
61129
{
62130
return $this->move($bucket, $oldname, $bucket, $newname);
63131
}
64132

133+
/**
134+
* 给资源进行重命名,本质为move操作。
135+
*
136+
* @param $from_bucket 待操作资源所在空间
137+
* @param $from_key 待操作资源文件名
138+
* @param $to_bucket 目标资源空间名
139+
* @param $to_key 目标资源文件名
140+
*
141+
* @return 成功返回NULL,失败返回对象{"error" => "<errMsg string>", ...}
142+
* @link http://developer.qiniu.com/docs/v6/api/reference/rs/copy.html
143+
*/
65144
public function copy($from_bucket, $from_key, $to_bucket, $to_key)
66145
{
67146
$from = \Qiniu\entry($from_bucket, $from_key);
@@ -71,6 +150,17 @@ public function copy($from_bucket, $from_key, $to_bucket, $to_key)
71150
return $error;
72151
}
73152

153+
/**
154+
* 将资源从一个空间到另一个空间
155+
*
156+
* @param $from_bucket 待操作资源所在空间
157+
* @param $from_key 待操作资源文件名
158+
* @param $to_bucket 目标资源空间名
159+
* @param $to_key 目标资源文件名
160+
*
161+
* @return 成功返回NULL,失败返回对象{"error" => "<errMsg string>", ...}
162+
* @link http://developer.qiniu.com/docs/v6/api/reference/rs/move.html
163+
*/
74164
public function move($from_bucket, $from_key, $to_bucket, $to_key)
75165
{
76166
$from = \Qiniu\entry($from_bucket, $from_key);
@@ -80,6 +170,16 @@ public function move($from_bucket, $from_key, $to_bucket, $to_key)
80170
return $error;
81171
}
82172

173+
/**
174+
* 主动修改指定资源的文件类型
175+
*
176+
* @param $bucket 待操作资源所在空间
177+
* @param $key 待操作资源文件名
178+
* @param $mime 待操作文件目标mimeType
179+
*
180+
* @return 成功返回NULL,失败返回对象{"error" => "<errMsg string>", ...}
181+
* @link http://developer.qiniu.com/docs/v6/api/reference/rs/chgm.html
182+
*/
83183
public function changeMime($bucket, $key, $mime)
84184
{
85185
$resource = \Qiniu\entry($bucket, $key);
@@ -89,6 +189,16 @@ public function changeMime($bucket, $key, $mime)
89189
return $error;
90190
}
91191

192+
/**
193+
* 从指定URL抓取资源,并将该资源存储到指定空间中
194+
*
195+
* @param $url 指定的URL
196+
* @param $bucket 目标资源空间
197+
* @param $key 目标资源文件名
198+
*
199+
* @return 成功返回NULL,失败返回对象{"error" => "<errMsg string>", ...}
200+
* @link http://developer.qiniu.com/docs/v6/api/reference/rs/fetch.html
201+
*/
92202
public function fetch($url, $bucket, $key)
93203
{
94204
$resource = \Qiniu\base64_urlSafeEncode($url);
@@ -98,6 +208,15 @@ public function fetch($url, $bucket, $key)
98208
return $error;
99209
}
100210

211+
/**
212+
* 从镜像源站抓取资源到空间中,如果空间中已经存在,则覆盖该资源
213+
*
214+
* @param $bucket 待获取资源所在的空间
215+
* @param $key 代获取资源文件名
216+
*
217+
* @return 成功返回NULL,失败返回对象{"error" => "<errMsg string>", ...}
218+
* @link http://developer.qiniu.com/docs/v6/api/reference/rs/prefetch.html
219+
*/
101220
public function prefetch($bucket, $key)
102221
{
103222
$resource = \Qiniu\entry($bucket, $key);
@@ -106,6 +225,22 @@ public function prefetch($bucket, $key)
106225
return $error;
107226
}
108227

228+
/**
229+
* 在单次请求中进行多个资源管理操作
230+
*
231+
* @param $operations 资源管理操作数组
232+
*
233+
* @return 每个资源的处理情况,结果类似:
234+
* [
235+
* { "code" => <HttpCode int>, "data" => <Data> },
236+
* { "code" => <HttpCode int> },
237+
* { "code" => <HttpCode int> },
238+
* { "code" => <HttpCode int> },
239+
* { "code" => <HttpCode int>, "data" => { "error": "<ErrorMessage string>" } },
240+
* ...
241+
* ]
242+
* @link http://developer.qiniu.com/docs/v6/api/reference/rs/batch.html
243+
*/
109244
public function batch($operations)
110245
{
111246
$params = 'op=' . implode('&op=', $operations);

src/Qiniu/Storage/ResumeUploader.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
use Qiniu\Http\Client;
66
use Qiniu\Http\Error;
77

8+
/**
9+
* 断点续上传类, 该类主要实现了断点续上传中的分块上传,
10+
* 以及相应地创建块和创建文件过程.
11+
*
12+
* @link http://developer.qiniu.com/docs/v6/api/reference/up/mkblk.html
13+
* @link http://developer.qiniu.com/docs/v6/api/reference/up/mkfile.html
14+
*/
815
final class ResumeUploader
916
{
1017
private $upToken;
@@ -18,6 +25,18 @@ final class ResumeUploader
1825
private $host;
1926
private $currentUrl;
2027

28+
/**
29+
* 上传二进制流到七牛
30+
*
31+
* @param $upToken 上传凭证
32+
* @param $key 上传文件名
33+
* @param $inputStream 上传二进制流
34+
* @param $size 上传流的大小
35+
* @param $params 自定义变量
36+
* @param $mime 上传数据的mimeType
37+
*
38+
* @link http://developer.qiniu.com/docs/v6/api/overview/up/response/vars.html#xvar
39+
*/
2140
public function __construct(
2241
$upToken,
2342
$key,
@@ -36,6 +55,10 @@ public function __construct(
3655
$this->contexts = array();
3756
}
3857

58+
59+
/**
60+
* 上传操作
61+
*/
3962
public function upload()
4063
{
4164
$uploaded = 0;
@@ -71,6 +94,9 @@ public function upload()
7194
return $this->makeFile();
7295
}
7396

97+
/**
98+
* 创建块
99+
*/
74100
private function makeBlock($block, $blockSize)
75101
{
76102
$url = $this->host . '/mkblk/' . $blockSize;
@@ -93,6 +119,9 @@ private function fileUrl()
93119
return $url;
94120
}
95121

122+
/**
123+
* 创建文件
124+
*/
96125
private function makeFile()
97126
{
98127
$url = $this->fileUrl();

0 commit comments

Comments
 (0)