Skip to content

Commit 45259d5

Browse files
committed
Merge pull request #16 from rwifeng/rsf
Rsf
2 parents 0a1d25f + 0492bb7 commit 45259d5

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

qiniu/rsf.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
require_once("http.php");
4+
5+
/**
6+
* 1. 首次请求 marker = ""
7+
* 2. 无论 err 值如何,均应该先看 items 是否有内容
8+
* 3. 如果后续没有更多数据,err 返回 EOF,markerOut 返回 ""(但不通过该特征来判断是否结束)
9+
*/
10+
function Qiniu_RSF_ListPrefix($self, $bucket, $prefix, $marker, $limit) // => ($items, $markerOut, $err)
11+
{
12+
global $QINIU_RSF_HOST;
13+
$query = array("bucket" => $bucket);
14+
if (!empty($prefix)) {
15+
$query["prefix"] = $prefix;
16+
}
17+
if (!empty($marker)) {
18+
$query["marker"] = $marker;
19+
}
20+
if (!empty($limit)) {
21+
$query["limit"] = $limit;
22+
}
23+
24+
$url = $QINIU_RSF_HOST . "/list?" . http_build_query($query);
25+
list($ret, $err) = Qiniu_Client_Call($self, $url);
26+
27+
$items = $ret['items'];
28+
if (!isset($ret['marker'])) {
29+
$markerOut = '';
30+
$err = new Qiniu_Error(400, 'EOF');
31+
} else {
32+
$markerOut = $ret['marker'];
33+
}
34+
35+
return array($items, $markerOut, $err);
36+
}
37+

tests/RsfTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
require_once("bootstrap.php");
4+
5+
class RsfTest extends PHPUnit_Framework_TestCase
6+
{
7+
public $client;
8+
public $bucket;
9+
10+
public function setUp()
11+
{
12+
initKeys();
13+
$this->client = new Qiniu_MacHttpClient(null);
14+
$this->bucket = getenv('QINIU_BUCKET_NAME');
15+
$this->key = getenv('QINIU_KEY_NAME');
16+
}
17+
18+
public function testListPrefix()
19+
{
20+
echo $this->bucket;
21+
list($items, $markerOut, $err) = Qiniu_RSF_ListPrefix($this->client, $this->bucket, null, null, null);
22+
$this->assertEquals($err->Err, 'EOF');
23+
$this->assertEquals($markerOut, '');
24+
25+
list($items, $markerOut, $err) = Qiniu_RSF_ListPrefix($this->client, $this->bucket, null, null, 1);
26+
$this->assertFalse($markerOut === '');
27+
28+
list($items, $markerOut, $err) = Qiniu_RSF_ListPrefix($this->client, $this->bucket, $this->key, null, null);
29+
$this->assertLessThanOrEqual(1, count($items));
30+
}
31+
}

tests/bootstrap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
require_once("../qiniu/fop.php");
44
require_once("../qiniu/rs_utils.php");
5+
require_once("../qiniu/rsf.php");
56

67
$accessKey = getenv("QINIU_ACCESS_KEY");
78
$secretKey = getenv("QINIU_SECRET_KEY");

0 commit comments

Comments
 (0)