Skip to content

Commit 20cfc81

Browse files
committed
Merge branch 'totoleo-master'
- 自动创建目录参数调整为默认开启 - 去除兼容 api: rmDir deleteFile readDir getWritedFileInfo 这些可以使用 delete getList 代替
2 parents eecf092 + dc38731 commit 20cfc81

File tree

7 files changed

+270
-313
lines changed

7 files changed

+270
-313
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
.DS_Store
2-
test.php
32
vendor/
43
composer.lock
4+
.idea/

composer.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
{
2-
"name": "upyun/php-sdk",
2+
"name": "upyun/sdk",
33
"description": "UPYUN sdk for php",
44
"keywords": ["UPYUN", "sdk"],
55
"type": "library",
6+
"minimum-stability": "stable",
67
"homepage": "https://github.com/upyun/php-sdk/",
78
"license": "MIT",
89
"require": {
9-
"php": ">=5.3.0"
10+
"php": ">=5.3.0",
11+
"ext-curl": "*"
1012
},
1113
"require-dev": {
1214
"phpunit/phpunit": "~4.0"
@@ -19,6 +21,14 @@
1921
{
2022
"name": "lvtongda",
2123
"email": "riyao.lyu@gmail.com"
24+
},
25+
{
26+
"name": "totoleo",
27+
"email": "totoleo@163.com"
28+
},
29+
{
30+
"name": "sabakugaara",
31+
"email": "senellise@gmail.com"
2232
}
2333
],
2434
"autoload": {

examples/get_list.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
<?php
2-
require_once('../upyun.class.php');
3-
4-
$upyun = new UpYun('bucket', 'user', 'pwd');
2+
require_once(dirname(__DIR__).'/vendor/autoload.php');
3+
$config = array(
4+
'user_name' => 'tester',
5+
'pwd' => 'grjxv2mxELR3',
6+
'bucket' => 'sdkimg',
7+
'picture_path' => dirname(__FILE__) . '/assets/sample.jpeg'
8+
);
9+
$upyun = new UpYun($config['bucket'], $config['user_name'], $config['pwd']);
510

611
try {
712
echo "=========获取目录文件列表\r\n";

examples/write_file.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
<?php
2-
require_once('../upyun.class.php');
3-
4-
$upyun = new UpYun('bucket', 'user', 'pwd');
2+
require_once(dirname(__DIR__).'/vendor/autoload.php');
3+
$config = array(
4+
'user_name' => 'tester',
5+
'pwd' => 'grjxv2mxELR3',
6+
'bucket' => 'sdkimg',
7+
'picture_path' => dirname(__FILE__) . '/assets/sample.jpeg'
8+
);
9+
$upyun = new UpYun($config['bucket'], $config['user_name'], $config['pwd']);
510

611
try {
712
echo "=========直接上传文件\r\n";
8-
$fh = fopen('sample.jpeg', 'rb');
13+
$fh = fopen(__DIR__.'/sample.jpeg', 'rb');
914
$rsp = $upyun->writeFile('/demo/sample_normal.jpeg', $fh, True); // 上传图片,自动创建目录
1015
fclose($fh);
1116
var_dump($rsp);
1217
echo "=========DONE\n\r\n";
1318

1419
echo "=========设置MD5校验文件完整性\r\n";
1520
$opts = array(
16-
UpYun::CONTENT_MD5 => md5(file_get_contents("sample.jpeg"))
21+
UpYun::CONTENT_MD5 => md5(file_get_contents(__DIR__.'/sample.jpeg'))
1722
);
18-
$fh = fopen('sample.jpeg', 'rb');
23+
$fh = fopen(__DIR__.'/sample.jpeg', 'rb');
1924
$rsp = $upyun->writeFile('/demo/sample_md5.jpeg', $fh, True, $opts); // 上传图片,自动创建目录
2025
fclose($fh);
2126
var_dump($rsp);
@@ -28,7 +33,7 @@
2833
UpYun::X_GMKERL_QUALITY => 95, // 缩略图压缩质量
2934
UpYun::X_GMKERL_UNSHARP => True // 是否进行锐化处理
3035
);
31-
$fh = fopen('sample.jpeg', 'rb');
36+
$fh = fopen(__DIR__.'/sample.jpeg', 'rb');
3237
$rsp = $upyun->writeFile('/demo/sample_thumb_1.jpeg', $fh, True, $opts); // 上传图片,自动创建目录
3338
fclose($fh);
3439
var_dump($rsp);
@@ -38,7 +43,7 @@
3843
$opts = array(
3944
UpYun::X_GMKERL_THUMBNAIL => 'thumbtype'
4045
);
41-
$fh = fopen('sample.jpeg', 'rb');
46+
$fh = fopen(__DIR__.'/sample.jpeg', 'rb');
4247
$rsp = $upyun->writeFile('/demo/sample_thumb_2.jpeg', $fh, True, $opts); // 上传图片,自动创建目录
4348
fclose($fh);
4449
var_dump($rsp);

tests/bootstrap.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
2-
require_once './tests/config.php';
3-
require_once './upyun.class.php';
2+
require_once dirname(__DIR__) . '/vendor/autoload.php';
3+
require_once __DIR__ . '/config.php';
44

55
define('USER_NAME', $config['user_name']);
66
define('PWD', $config['pwd']);
77
define('BUCKET', $config['bucket']);
88

9-
define('PIC_PATH' , $config['picture_path']);
9+
define('PIC_PATH', $config['picture_path']);

tests/upyunTest.php

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,41 @@
33
class unyunTest extends PHPUnit_Framework_TestCase
44
{
55

6-
public function setUp(){
6+
/**
7+
* @var UpYun
8+
*/
9+
private $upyun;
10+
11+
public function setUp()
12+
{
713
$this->upyun = new UpYun(BUCKET, USER_NAME, PWD, UpYun::ED_TELECOM, 600);
814
}
915

10-
public function testMakeDir(){
16+
public function testMakeDir()
17+
{
1118
$rsp = $this->upyun->makeDir('/demo/');
1219
$this->assertTrue(true);
1320
}
21+
1422
/**
15-
* 直接上传文件
16-
*/
23+
* 直接上传文件
24+
*/
1725
public function testDirectUpload()
1826
{
1927
$fh = fopen(PIC_PATH, 'rb');
2028
$rsp = $this->upyun->writeFile('/demo/sample_normal.jpeg', $fh, True); // 上传图片,自动创建目录
2129
fclose($fh);
22-
$this->assertTrue(true , is_array($rsp));
30+
$this->assertTrue(true, is_array($rsp));
2331
}
32+
2433
/**
25-
* 直接生成缩略图,不保存原图片,仅对图片文件有效
26-
*/
27-
public function testWriteFile1(){
34+
* 直接生成缩略图,不保存原图片,仅对图片文件有效
35+
*/
36+
public function testWriteFile1()
37+
{
2838
$opts = array(
29-
UpYun::X_GMKERL_TYPE => 'square', // 缩略图类型
30-
UpYun::X_GMKERL_VALUE => 150, // 缩略图大小
39+
UpYun::X_GMKERL_TYPE => 'square', // 缩略图类型
40+
UpYun::X_GMKERL_VALUE => 150, // 缩略图大小
3141
UpYun::X_GMKERL_QUALITY => 95, // 缩略图压缩质量
3242
UpYun::X_GMKERL_UNSHARP => True // 是否进行锐化处理
3343
);
@@ -36,39 +46,36 @@ public function testWriteFile1(){
3646
fclose($fh);
3747
$this->assertTrue(is_array($rsp));
3848
}
49+
3950
/**
40-
* 按照预先设置的缩略图类型生成缩略图类型生成缩略图,不保存原图,仅对图片空间有效
41-
*/
42-
public function testWriteFile2(){
43-
$opts = array(
44-
UpYun::X_GMKERL_THUMBNAIL => 'thumbtype'
45-
);
46-
$fh = fopen(PIC_PATH, 'rb');
47-
$rsp = $this->upyun->writeFile('/demo/sample_thumb_2.jpeg', $fh, True, $opts); // 上传图片,自动创建目录
48-
fclose($fh);
49-
$this->assertTrue(is_array($rsp));
50-
}
51-
/**
52-
* 获取空间的使用情况
53-
*/
54-
public function testUsage(){
51+
* 获取空间的使用情况
52+
*/
53+
public function testUsage()
54+
{
5555
$rsp = $this->upyun->getFolderUsage('/demo/');
56-
$this->assertTrue(is_float($rsp));
56+
$this->assertTrue(is_string($rsp));
5757
}
58+
5859
/**
59-
* 获取指定文件的目录信息
60-
*/
61-
public function testFileInfo(){
62-
$rsp = $this->upyun->getFolderUsage('/demo/sample_normal.jpeg');
63-
$this->assertTrue(is_float($rsp));
60+
* 获取指定文件的目录信息
61+
*/
62+
public function testFileInfo()
63+
{
64+
$rsp = $this->upyun->getFileInfo('/demo/sample_normal.jpeg');
65+
$this->assertArrayHasKey('x-upyun-file-type',$rsp);
66+
$this->assertArrayHasKey('x-upyun-file-size',$rsp);
67+
$this->assertArrayHasKey('x-upyun-file-date',$rsp);
6468
}
69+
6570
/**
66-
* 获取目录文件列表
67-
*/
68-
public function testList(){
71+
* 获取目录文件列表
72+
*/
73+
public function testList()
74+
{
6975
$rsp = $this->upyun->getList('/demo/');
7076
$this->assertTrue(is_array($rsp));
7177
}
78+
7279
/**
7380
* 删除空间目录
7481
* @expectedException \Exception
@@ -83,7 +90,8 @@ public function testDelete()
8390
/**
8491
* 获取错误请求的 X-Request-Id
8592
*/
86-
public function testXRequestId(){
93+
public function testXRequestId()
94+
{
8795
$rsp = $this->upyun->getList('/demo/');
8896
$x_id = $this->upyun->getXRequestId();
8997
$this->assertEquals(strlen($x_id), 32);

0 commit comments

Comments
 (0)