Skip to content

Commit 78b826f

Browse files
committed
Merge pull request #120 from rwifeng/code_comments
new fetch api
2 parents 65856e0 + 39c1654 commit 78b826f

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

src/Qiniu/Storage/BucketManager.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,16 +196,28 @@ public function changeMime($bucket, $key, $mime)
196196
* @param $bucket 目标资源空间
197197
* @param $key 目标资源文件名
198198
*
199-
* @return 成功返回NULL,失败返回对象{"error" => "<errMsg string>", ...}
199+
* @return array[] 包含已拉取的文件信息。
200+
* 成功时: [
201+
* [
202+
* "hash" => "<Hash string>",
203+
* "key" => "<Key string>"
204+
* ],
205+
* null
206+
* ]
207+
*
208+
* 失败时: [
209+
* null,
210+
* Qiniu/Http/Error
211+
* ]
200212
* @link http://developer.qiniu.com/docs/v6/api/reference/rs/fetch.html
201213
*/
202214
public function fetch($url, $bucket, $key)
203215
{
216+
204217
$resource = \Qiniu\base64_urlSafeEncode($url);
205218
$to = \Qiniu\entry($bucket, $key);
206219
$path = '/fetch/' . $resource . '/to/' . $to;
207-
list($_, $error) = $this->ioPost($path);
208-
return $error;
220+
return $this->ioPost($path);
209221
}
210222

211223
/**

tests/Qiniu/Tests/BucketTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,20 @@ public function testPrefetch()
116116

117117
public function testFetch()
118118
{
119-
$error = $this->bucketManager->fetch(
119+
list($ret, $error) = $this->bucketManager->fetch(
120120
'http://developer.qiniu.com/docs/v6/sdk/php-sdk.html',
121121
$this->bucketName,
122122
'fetch.html'
123123
);
124+
$this->assertArrayHasKey('hash', $ret);
125+
$this->assertNull($error);
126+
127+
list($ret, $error) = $this->bucketManager->fetch(
128+
'http://developer.qiniu.com/docs/v6/sdk/php-sdk.html',
129+
$this->bucketName,
130+
''
131+
);
132+
$this->assertArrayHasKey('key', $ret);
124133
$this->assertNull($error);
125134
}
126135

0 commit comments

Comments
 (0)