Skip to content

Commit bfccb98

Browse files
committed
feat rename bucket -> service
- 去除空间名相关描述,统一为服务 - 暂时保留兼容 `Config::bucketName` 属性
1 parent 72791e1 commit bfccb98

File tree

8 files changed

+32
-26
lines changed

8 files changed

+32
-26
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ require_once('vendor/autoload.php'); // 只针对使用 composer 安装
6161

6262
use Upyun\Upyun;
6363
use Upyun\Config;
64-
$bucketConfig = new Config('yourBucketName', 'yourOperatorName', 'yourOperatorPwd');
65-
$client = new Upyun($bucketConfig);
64+
$serviceConfig = new Config('yourServiceName', 'yourOperatorName', 'yourOperatorPwd');
65+
$client = new Upyun($serviceConfig);
6666
```
6767

6868
详细文档见 [doc.md](doc.md),以下为部分简单示例

doc.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
## Upyun
2626

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

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

@@ -490,7 +490,7 @@ array(
490490
'path' => array('/v2.mp4'),
491491
'signature' => '4042c1f07f546d28',
492492
'status_code' => 200,
493-
'bucket_name' => 'your_storage_bucket',
493+
'service' => 'your_storage_service',
494494
'description' => 'OK',
495495
'task_id' => '9d9c32b63a1034834e77672c6f51f661',
496496
'timestamp' => 1472010684

src/Upyun/Api/Form.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ class Form extends Rest
1111
public function upload($path, $stream, $params)
1212
{
1313
$params['save-key'] = $path;
14-
$params['bucket'] = $this->config->bucketName;
14+
$params['service'] = $this->config->serviceName;
1515
if (!isset($params['expiration'])) {
1616
$params['expiration'] = time() + 30 * 60 * 60; // 30 分钟
1717
}
1818

1919
$policy = Util::base64Json($params);
2020
$method = 'POST';
21-
$signature = Signature::getBodySignature($this->config, $method, '/' . $params['bucket'], null, $policy);
21+
$signature = Signature::getBodySignature($this->config, $method, '/' . $params['service'], null, $policy);
2222
$client = new Client([
2323
'timeout' => $this->config->timeout,
2424
]);

src/Upyun/Api/Pretreat.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function process($source, $tasks)
3232
]);
3333

3434
$params = array(
35-
'service' => $this->config->bucketName,
35+
'service' => $this->config->serviceName,
3636
'notify_url' => $this->config->processNotifyUrl,
3737
'source' => $source,
3838
'tasks' => $encodedTasks,
@@ -61,7 +61,7 @@ public function query($taskIds, $path)
6161
]);
6262

6363
$params = array(
64-
'service' => $this->config->bucketName,
64+
'service' => $this->config->serviceName,
6565
'task_ids' => implode(',', $taskIds)
6666
);
6767
$path = $path . '?' . http_build_query($params);

src/Upyun/Api/Rest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Rest
2929
public function __construct(Config $config)
3030
{
3131
$this->config = $config;
32-
$this->endpoint = $config->getProtocol() . Config::$restApiEndPoint . '/' . $config->bucketName;
32+
$this->endpoint = $config->getProtocol() . Config::$restApiEndPoint . '/' . $config->serviceName;
3333
}
3434

3535
public function request($method, $storagePath)

src/Upyun/Config.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,14 @@
99
class Config
1010
{
1111
/**
12-
* @var string 服务名称
12+
* @var string 服务名称,将会被弃用
1313
*/
1414
public $bucketName;
15+
16+
/**
17+
* @var string 服务名称
18+
*/
19+
public $serviceName;
1520
/**
1621
* @var string 操作员名
1722
*/
@@ -86,9 +91,10 @@ class Config
8691
*/
8792
const ED_PURGE = 'http://purge.upyun.com/purge/';
8893

89-
public function __construct($bucketName, $operatorName, $operatorPassword)
94+
public function __construct($serviceName, $operatorName, $operatorPassword)
9095
{
91-
$this->bucketName = $bucketName;
96+
$this->serviceName = $serviceName;
97+
$this->bucketName = $serviceName;
9298
$this->operatorName = $operatorName;
9399
$this->setOperatorPassword($operatorPassword);
94100
$this->useSsl = false;

src/Upyun/Signature.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,50 +23,50 @@ class Signature
2323
/**
2424
* 获取 Header 签名需要的请求头
2525
*
26-
* @param Config $bucketConfig
26+
* @param Config $serviceConfig
2727
* @param $method 请求方法
2828
* @param $path 请求路径
2929
* @param $contentMd5 文件内容 md5
3030
*
3131
* @return array
3232
*/
33-
public static function getHeaderSign($bucketConfig, $method, $path, $contentMd5 = null)
33+
public static function getHeaderSign($serviceConfig, $method, $path, $contentMd5 = null)
3434
{
3535
$gmtDate = gmdate('D, d M Y H:i:s \G\M\T');
3636

3737
$policy = null;
38-
$sign = self::getBodySignature($bucketConfig, $method, $path, $gmtDate, $policy, $contentMd5);
38+
$sign = self::getBodySignature($serviceConfig, $method, $path, $gmtDate, $policy, $contentMd5);
3939

4040
$headers = array(
4141
'Authorization' => $sign,
4242
'Date' => $gmtDate,
43-
'User-agent' => 'Php-Sdk/' . $bucketConfig->getVersion()
43+
'User-agent' => 'Php-Sdk/' . $serviceConfig->getVersion()
4444
);
4545
return $headers;
4646
}
4747

4848
/**
4949
* 获取请求缓存刷新接口需要的签名头
5050
*
51-
* @param Config $bucketConfig
51+
* @param Config $serviceConfig
5252
* @param $urlString
5353
*
5454
* @return array
5555
*/
56-
public static function getPurgeSignHeader(Config $bucketConfig, $urlString)
56+
public static function getPurgeSignHeader(Config $serviceConfig, $urlString)
5757
{
5858
$gmtDate = gmdate('D, d M Y H:i:s \G\M\T');
59-
$sign = md5("$urlString&{$bucketConfig->bucketName}&$gmtDate&{$bucketConfig->operatorPassword}");
59+
$sign = md5("$urlString&{$serviceConfig->serviceName}&$gmtDate&{$serviceConfig->operatorPassword}");
6060
return array(
61-
'Authorization' => "UpYun {$bucketConfig->bucketName}:{$bucketConfig->operatorName}:$sign",
61+
'Authorization' => "UpYun {$serviceConfig->serviceName}:{$serviceConfig->operatorName}:$sign",
6262
'Date' => $gmtDate,
63-
'User-agent' => 'Php-Sdk/' . $bucketConfig->getVersion() . ' (purge api)'
63+
'User-agent' => 'Php-Sdk/' . $serviceConfig->getVersion() . ' (purge api)'
6464
);
6565
}
6666

6767
/**
6868
* 获取表单 API 需要的签名,依据 body 签名规则计算
69-
* @param Config $bucketConfig
69+
* @param Config $serviceConfig
7070
* @param $method 请求方法
7171
* @param $uri 请求路径
7272
* @param $date 请求时间
@@ -75,7 +75,7 @@ public static function getPurgeSignHeader(Config $bucketConfig, $urlString)
7575
*
7676
* @return array
7777
*/
78-
public static function getBodySignature(Config $bucketConfig, $method, $uri, $date = null, $policy = null, $contentMd5 = null)
78+
public static function getBodySignature(Config $serviceConfig, $method, $uri, $date = null, $policy = null, $contentMd5 = null)
7979
{
8080
$data = array(
8181
$method,
@@ -92,7 +92,7 @@ public static function getBodySignature(Config $bucketConfig, $method, $uri, $da
9292
if ($contentMd5) {
9393
$data[] = $contentMd5;
9494
}
95-
$signature = base64_encode(hash_hmac('sha1', implode('&', $data), $bucketConfig->operatorPassword, true));
96-
return 'UPYUN ' . $bucketConfig->operatorName . ':' . $signature;
95+
$signature = base64_encode(hash_hmac('sha1', implode('&', $data), $serviceConfig->operatorPassword, true));
96+
return 'UPYUN ' . $serviceConfig->operatorName . ':' . $signature;
9797
}
9898
}

src/Upyun/Upyun.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ public function queryProcessStatus($taskIds)
366366
* 'path' => array('/v2.mp4'),
367367
* 'signature' => '4042c1f07f546d28',
368368
* 'status_code' => 200,
369-
* 'bucket_name' => 'your_storage_bucket',
369+
* 'service_name' => 'your_storage_service',
370370
* 'description' => 'OK',
371371
* 'task_id' => '9d9c32b63a1034834e77672c6f51f661',
372372
* 'timestamp' => 1472010684

0 commit comments

Comments
 (0)