Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #319

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
# Qiniu Cloud SDK for PHP
[![doxygen.io](http://doxygen.io/github.com/qiniu/php-sdk/?status.svg)](http://doxygen.io/github.com/qiniu/php-sdk/)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](LICENSE)
[![Build Status](https://travis-ci.org/qiniu/php-sdk.svg)](https://travis-ci.org/qiniu/php-sdk)
[![GitHub release](https://img.shields.io/github/v/tag/qiniu/php-sdk.svg?label=release)](https://github.com/qiniu/php-sdk/releases)
[![Latest Stable Version](https://img.shields.io/packagist/v/qiniu/php-sdk.svg)](https://packagist.org/packages/qiniu/php-sdk)
[![Total Downloads](https://img.shields.io/packagist/dt/qiniu/php-sdk.svg)](https://packagist.org/packages/qiniu/php-sdk)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/qiniu/php-sdk/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/qiniu/php-sdk/?branch=master)
[![Code Coverage](https://scrutinizer-ci.com/g/qiniu/php-sdk/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/qiniu/php-sdk/?branch=master)
[![Coverage Status](https://codecov.io/gh/qiniu/php-sdk/branch/master/graph/badge.svg)](https://codecov.io/gh/qiniu/php-sdk)
[![Join Chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/qiniu/php-sdk?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![@qiniu on weibo](http://img.shields.io/badge/weibo-%40qiniutek-blue.svg)](http://weibo.com/qiniutek)


## 安装

* 通过composer,这是推荐的方式,可以使用composer.json 声明依赖,或者运行下面的命令。SDK 包已经放到这里 [`qiniu/php-sdk`][install-packagist] 。
* 推荐使用 `composer` 进行安装。可以使用 composer.json 声明依赖,或者运行下面的命令。SDK 包已经放到这里 [`qiniu/php-sdk`][install-packagist] 。
```bash
$ composer require qiniu/php-sdk
```
* 直接下载安装,SDK 没有依赖其他第三方库,但需要参照 composer的autoloader,增加一个自己的autoloader程序
* 直接下载安装,SDK 没有依赖其他第三方库,但需要参照 composer 的 autoloader,增加一个自己的 autoloader 程序

## 运行环境

Expand All @@ -31,10 +32,10 @@ $ composer require qiniu/php-sdk
use Qiniu\Storage\UploadManager;
use Qiniu\Auth;
...
$upManager = new UploadManager();
$uploadMgr = new UploadManager();
$auth = new Auth($accessKey, $secretKey);
$token = $auth->uploadToken($bucketName);
list($ret, $error) = $upManager->put($token, 'formput', 'hello world');
$token = $auth->uploadToken($bucket);
list($ret, $error) = $uploadMgr->putFile($token, 'key', 'filePath');
...
```

Expand All @@ -46,7 +47,7 @@ $ ./vendor/bin/phpunit tests/Qiniu/Tests/

## 常见问题

- $error保留了请求响应的信息,失败情况下ret 为none, 将$error可以打印出来,提交给我们。
- `$error` 保留了请求响应的信息,失败情况下 `ret` 为 `none`, 将 `$error` 可以打印出来,提交给我们。
- API 的使用 demo 可以参考 [单元测试](https://github.com/qiniu/php-sdk/blob/master/tests)。

## 代码贡献
Expand All @@ -60,12 +61,12 @@ $ ./vendor/bin/phpunit tests/Qiniu/Tests/
## 联系我们

- 如果需要帮助,请提交工单(在portal右侧点击咨询和建议提交工单,或者直接向 [email protected] 发送邮件)
- 如果有什么问题,可以到问答社区提问,[问答社区](http://qiniu.segmentfault.com/)
- 更详细的文档,见[官方文档站](http://developer.qiniu.com/)
- 如果发现了bug, 欢迎提交 [issue](https://github.com/qiniu/php-sdk/issues)
- 如果有什么问题,可以到问答社区提问,[问答社区](https://qiniu.segmentfault.com/)
- 更详细的文档,见[官方文档站](https://developer.qiniu.com/)
- 如果发现了 bug, 欢迎提交 [issue](https://github.com/qiniu/php-sdk/issues)
- 如果有功能需求,欢迎提交 [issue](https://github.com/qiniu/php-sdk/issues)
- 如果要提交代码,欢迎提交 pull request
- 欢迎关注我们的[微信](http://www.qiniu.com/#weixin) [微博](http://weibo.com/qiniutek),及时获取动态信息。
- 欢迎关注我们的[微信](https://www.qiniu.com/#weixin) [微博](https://weibo.com/qiniutek),及时获取动态信息。

## 代码许可

Expand Down
2 changes: 1 addition & 1 deletion examples/rs_batch_move.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

$keyPairs = array();
foreach ($keys as $key) {
$keyPairs[$key . "_copy"] = $key . "_move";
$keyPairs[$key] = $key . "_move";
}

$srcBucket = $bucket;
Expand Down
2 changes: 1 addition & 1 deletion examples/rs_change_type.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
$config = new \Qiniu\Config();
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);

$fileType = 1;//0 表示普通存储,1表示低频存储
$fileType = 1;//0 表示普通存储,1表示低频存储,2表示归档存储

$err = $bucketManager->changeType($bucket, $key, $fileType);
if ($err) {
Expand Down
20 changes: 20 additions & 0 deletions examples/rs_restore_file.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
require_once __DIR__ . '/../autoload.php';

use \Qiniu\Auth;

$accessKey = getenv('QINIU_ACCESS_KEY');
$secretKey = getenv('QINIU_SECRET_KEY');
$bucket = getenv('QINIU_TEST_BUCKET');

$key = "qiniu.mp4";
$auth = new Auth($accessKey, $secretKey);
$config = new \Qiniu\Config();
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);

$day = 1;// 解冻有效时长,取值范围 1~7

$err = $bucketManager->restoreFile($bucket, $key, $day);
if ($err) {
print_r($err);
}
29 changes: 27 additions & 2 deletions src/Qiniu/Storage/BucketManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,15 @@ public function listbuckets(
* 创建空间
*
* @param $name 创建的空间名
* BucketName不满足以上要求返回400 (the specified bucket is not valid)
* 如果BucketName已经被使用,返回614(bucket exists)
* @param $region 创建的区域,默认华东
*
* @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error
*/

public function createBucket($name, $region = 'z0')
{
$path = '/mkbucketv2/'.$name.'/region/' . $region;
$path = '/mkbucketv3/'.$name.'/region/' . $region;
return $this->rsPost($path, null);
}

Expand Down Expand Up @@ -795,6 +797,23 @@ public function changeType($bucket, $key, $fileType)
return $error;
}

/**
* 修改指定资源的存储类型
*
* @param $bucket 待操作资源所在空间
* @param $key 待操作资源文件名
* @param $day 解冻有效时长,取值范围 1~7,解冻存在等待时间
* @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error
* @link https://developer.qiniu.com/kodo/api/6380/restore-archive
*/
public function restoreFile($bucket, $key, $day)
{
$resource = \Qiniu\entry($bucket, $key);
$path = '/restoreAr/' . $resource . '/freezeAfterDays/' . $day;
list(, $error) = $this->rsPostV2($path, null);
return $error;
}

/**
* 修改文件的存储状态,即禁用状态和启用状态间的的互相转换
*
Expand Down Expand Up @@ -1010,6 +1029,12 @@ private function ucPostV2($path, $body)
return $this->postV2($url, $body);
}

private function rsPostV2($path, $body)
{
$url = $this->getRsHost() . $path;
return $this->postV2($url, $body);
}

private function postV2($url, $body)
{
$headers = $this->auth->authorizationV2($url, 'POST', $body, 'application/json');
Expand Down