Skip to content

Commit

Permalink
feat rename bucket -> service
Browse files Browse the repository at this point in the history
- 去除空间名相关描述,统一为服务
- 暂时保留兼容 `Config::bucketName` 属性
  • Loading branch information
sabakugaara committed Aug 15, 2017
1 parent 72791e1 commit bfccb98
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 26 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ require_once('vendor/autoload.php'); // 只针对使用 composer 安装

use Upyun\Upyun;
use Upyun\Config;
$bucketConfig = new Config('yourBucketName', 'yourOperatorName', 'yourOperatorPwd');
$client = new Upyun($bucketConfig);
$serviceConfig = new Config('yourServiceName', 'yourOperatorName', 'yourOperatorPwd');
$client = new Upyun($serviceConfig);
```

详细文档见 [doc.md](doc.md),以下为部分简单示例
Expand Down
4 changes: 2 additions & 2 deletions doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
## Upyun

`Upyun\Upyun` 类实现了又拍云云存储和云处理的所有接口,通过该类可以实现文件上传、下载;图片视频等多媒体资源云处理。
本文档中,提到的"服务"是指又拍云文件加速回又拍云源类型的服务(即原先的存储类空间)。
本文档中,提到的"服务"是指又拍云文件加速回又拍云源类型的服务(即原先的存储类服务)。

* 命名空间: `\Upyun\Upyun`

Expand Down Expand Up @@ -490,7 +490,7 @@ array(
'path' => array('/v2.mp4'),
'signature' => '4042c1f07f546d28',
'status_code' => 200,
'bucket_name' => 'your_storage_bucket',
'service' => 'your_storage_service',
'description' => 'OK',
'task_id' => '9d9c32b63a1034834e77672c6f51f661',
'timestamp' => 1472010684
Expand Down
4 changes: 2 additions & 2 deletions src/Upyun/Api/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ class Form extends Rest
public function upload($path, $stream, $params)
{
$params['save-key'] = $path;
$params['bucket'] = $this->config->bucketName;
$params['service'] = $this->config->serviceName;
if (!isset($params['expiration'])) {
$params['expiration'] = time() + 30 * 60 * 60; // 30 分钟
}

$policy = Util::base64Json($params);
$method = 'POST';
$signature = Signature::getBodySignature($this->config, $method, '/' . $params['bucket'], null, $policy);
$signature = Signature::getBodySignature($this->config, $method, '/' . $params['service'], null, $policy);
$client = new Client([
'timeout' => $this->config->timeout,
]);
Expand Down
4 changes: 2 additions & 2 deletions src/Upyun/Api/Pretreat.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function process($source, $tasks)
]);

$params = array(
'service' => $this->config->bucketName,
'service' => $this->config->serviceName,
'notify_url' => $this->config->processNotifyUrl,
'source' => $source,
'tasks' => $encodedTasks,
Expand Down Expand Up @@ -61,7 +61,7 @@ public function query($taskIds, $path)
]);

$params = array(
'service' => $this->config->bucketName,
'service' => $this->config->serviceName,
'task_ids' => implode(',', $taskIds)
);
$path = $path . '?' . http_build_query($params);
Expand Down
2 changes: 1 addition & 1 deletion src/Upyun/Api/Rest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Rest
public function __construct(Config $config)
{
$this->config = $config;
$this->endpoint = $config->getProtocol() . Config::$restApiEndPoint . '/' . $config->bucketName;
$this->endpoint = $config->getProtocol() . Config::$restApiEndPoint . '/' . $config->serviceName;
}

public function request($method, $storagePath)
Expand Down
12 changes: 9 additions & 3 deletions src/Upyun/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@
class Config
{
/**
* @var string 服务名称
* @var string 服务名称,将会被弃用
*/
public $bucketName;

/**
* @var string 服务名称
*/
public $serviceName;
/**
* @var string 操作员名
*/
Expand Down Expand Up @@ -86,9 +91,10 @@ class Config
*/
const ED_PURGE = 'http://purge.upyun.com/purge/';

public function __construct($bucketName, $operatorName, $operatorPassword)
public function __construct($serviceName, $operatorName, $operatorPassword)
{
$this->bucketName = $bucketName;
$this->serviceName = $serviceName;
$this->bucketName = $serviceName;
$this->operatorName = $operatorName;
$this->setOperatorPassword($operatorPassword);
$this->useSsl = false;
Expand Down
26 changes: 13 additions & 13 deletions src/Upyun/Signature.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,50 +23,50 @@ class Signature
/**
* 获取 Header 签名需要的请求头
*
* @param Config $bucketConfig
* @param Config $serviceConfig
* @param $method 请求方法
* @param $path 请求路径
* @param $contentMd5 文件内容 md5
*
* @return array
*/
public static function getHeaderSign($bucketConfig, $method, $path, $contentMd5 = null)
public static function getHeaderSign($serviceConfig, $method, $path, $contentMd5 = null)
{
$gmtDate = gmdate('D, d M Y H:i:s \G\M\T');

$policy = null;
$sign = self::getBodySignature($bucketConfig, $method, $path, $gmtDate, $policy, $contentMd5);
$sign = self::getBodySignature($serviceConfig, $method, $path, $gmtDate, $policy, $contentMd5);

$headers = array(
'Authorization' => $sign,
'Date' => $gmtDate,
'User-agent' => 'Php-Sdk/' . $bucketConfig->getVersion()
'User-agent' => 'Php-Sdk/' . $serviceConfig->getVersion()
);
return $headers;
}

/**
* 获取请求缓存刷新接口需要的签名头
*
* @param Config $bucketConfig
* @param Config $serviceConfig
* @param $urlString
*
* @return array
*/
public static function getPurgeSignHeader(Config $bucketConfig, $urlString)
public static function getPurgeSignHeader(Config $serviceConfig, $urlString)
{
$gmtDate = gmdate('D, d M Y H:i:s \G\M\T');
$sign = md5("$urlString&{$bucketConfig->bucketName}&$gmtDate&{$bucketConfig->operatorPassword}");
$sign = md5("$urlString&{$serviceConfig->serviceName}&$gmtDate&{$serviceConfig->operatorPassword}");
return array(
'Authorization' => "UpYun {$bucketConfig->bucketName}:{$bucketConfig->operatorName}:$sign",
'Authorization' => "UpYun {$serviceConfig->serviceName}:{$serviceConfig->operatorName}:$sign",
'Date' => $gmtDate,
'User-agent' => 'Php-Sdk/' . $bucketConfig->getVersion() . ' (purge api)'
'User-agent' => 'Php-Sdk/' . $serviceConfig->getVersion() . ' (purge api)'
);
}

/**
* 获取表单 API 需要的签名,依据 body 签名规则计算
* @param Config $bucketConfig
* @param Config $serviceConfig
* @param $method 请求方法
* @param $uri 请求路径
* @param $date 请求时间
Expand All @@ -75,7 +75,7 @@ public static function getPurgeSignHeader(Config $bucketConfig, $urlString)
*
* @return array
*/
public static function getBodySignature(Config $bucketConfig, $method, $uri, $date = null, $policy = null, $contentMd5 = null)
public static function getBodySignature(Config $serviceConfig, $method, $uri, $date = null, $policy = null, $contentMd5 = null)
{
$data = array(
$method,
Expand All @@ -92,7 +92,7 @@ public static function getBodySignature(Config $bucketConfig, $method, $uri, $da
if ($contentMd5) {
$data[] = $contentMd5;
}
$signature = base64_encode(hash_hmac('sha1', implode('&', $data), $bucketConfig->operatorPassword, true));
return 'UPYUN ' . $bucketConfig->operatorName . ':' . $signature;
$signature = base64_encode(hash_hmac('sha1', implode('&', $data), $serviceConfig->operatorPassword, true));
return 'UPYUN ' . $serviceConfig->operatorName . ':' . $signature;
}
}
2 changes: 1 addition & 1 deletion src/Upyun/Upyun.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ public function queryProcessStatus($taskIds)
* 'path' => array('/v2.mp4'),
* 'signature' => '4042c1f07f546d28',
* 'status_code' => 200,
* 'bucket_name' => 'your_storage_bucket',
* 'service_name' => 'your_storage_service',
* 'description' => 'OK',
* 'task_id' => '9d9c32b63a1034834e77672c6f51f661',
* 'timestamp' => 1472010684
Expand Down

0 comments on commit bfccb98

Please sign in to comment.