Skip to content

Commit e6c6c91

Browse files
committed
add rsf
1 parent ef5dc9f commit e6c6c91

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

qiniu/rsf.php

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

tests/RsfTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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_RSF_Client(null);
14+
$this->bucket = getenv('QINIU_BUCKET_NAME');
15+
$this->key = getenv('QINIU_KEY_NAME');
16+
}
17+
18+
19+
//$bucket, $prefix, $marker, $limit
20+
public function testListPrefix()
21+
{
22+
echo $this->bucket;
23+
list($ret, $err) = $this->client->ListPrefix($this->bucket, null, null, null);
24+
$this->assertEquals($err->Err, 'EOF');
25+
26+
list($ret, $err) = $this->client->ListPrefix($this->bucket, null, null, 1);
27+
$this->assertArrayHasKey('marker', $ret);
28+
29+
list($ret, $err) = $this->client->ListPrefix($this->bucket, $this->key, null, null);
30+
$this->assertLessThanOrEqual(1, count($ret['items']));
31+
}
32+
}

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)