Skip to content

Commit fe399c4

Browse files
committed
- 优化服务
1 parent 27c58aa commit fe399c4

File tree

10 files changed

+95
-97
lines changed

10 files changed

+95
-97
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## v6.0.130 / 2020-11-26
2+
- 优化服务
3+
14
## v6.0.129 / 2020-11-26
25
- 优化服务
36

src/common.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
/**
2626
* 定义当前版本
2727
*/
28-
const VERSION = '6.0.129';
28+
const VERSION = '6.0.130';
2929

3030
if (!function_exists('get_ip_info')) {
3131
/**

src/service/aliyun/OssService.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,16 @@ public function bucket(string $bucket): self
7979
/**
8080
* @param string $object
8181
* @param string $filePath
82-
* @return string|null
82+
* @return bool
8383
*/
84-
public function upload(string $object, string $filePath): ?string
84+
public function upload(string $object, string $filePath): bool
8585
{
8686
try {
8787
$ossClient = new OssClient($this->accessKeyId, $this->accessKeySecret, $this->endpoint);
88-
return $ossClient->uploadFile($this->bucket, $object, $filePath);
88+
$ossClient->uploadFile($this->bucket, $object, $filePath);
89+
return true;
8990
} catch (OssException $e) {
90-
return $e->getMessage();
91+
return false;
9192
}
9293
}
9394
}

src/service/baidu/BosService.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ public function bucket(string $bucket)
7979
/**
8080
* @param string $object
8181
* @param string $filePath
82-
* @return mixed
82+
* @return bool
8383
* @throws Exception
8484
*/
85-
public function upload(string $object, string $filePath)
85+
public function upload(string $object, string $filePath): bool
8686
{
8787
// 设置BosClient的Access Key ID、Secret Access Key和ENDPOINT
8888
$BOS_TEST_CONFIG = array(
@@ -94,6 +94,7 @@ public function upload(string $object, string $filePath)
9494
);
9595
$client = new BosClient($BOS_TEST_CONFIG);
9696
// 从文件中直接上传Object
97-
return $client->putObjectFromFile($this->bucket, $object, $filePath);
97+
$client->putObjectFromFile($this->bucket, $object, $filePath);
98+
return true;
9899
}
99100
}

src/service/huaweicloud/ObsService.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ public function bucket(string $bucket): self
7878
/**
7979
* @param string $object
8080
* @param string $filePath
81-
* @return bool|\Obs\Internal\Common\Model
81+
* @return bool
8282
*/
83-
public function upload(string $object, string $filePath)
83+
public function upload(string $object, string $filePath): bool
8484
{
8585
// 创建ObsClient实例
8686
$obsClient = new ObsClient([
@@ -94,7 +94,7 @@ public function upload(string $object, string $filePath)
9494
'SourceFile' => $filePath // localfile为待上传的本地文件路径,需要指定到具体的文件名
9595
]);
9696
if (isset($resp['RequestId'])) {
97-
return $resp;
97+
return true;
9898
}
9999

100100
return false;

src/service/ksyun/Ks3Service.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ public function upload(string $object, string $filePath): ?bool
106106
]
107107
];
108108
try {
109-
return $client->putObjectByFile($args);
109+
$client->putObjectByFile($args);
110+
return true;
110111
} catch (Ks3ServiceException $e) {
111112
return false;
112113
}

src/service/ksyun/bin/Ks3Client.class.php

Lines changed: 68 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,31 @@
55

66
//检测API路径
77
if (!defined("KS3_API_PATH")) {
8-
define("KS3_API_PATH", __DIR__);
8+
define("KS3_API_PATH", __DIR__);
99
}
1010
//是否使用VHOST
1111
if (!defined("KS3_API_VHOST")) {
12-
define("KS3_API_VHOST", FALSE);
12+
define("KS3_API_VHOST", FALSE);
1313
}
1414
//是否开启日志(写入日志文件)
1515
if (!defined("KS3_API_LOG")) {
16-
define("KS3_API_LOG", FALSE);
16+
define("KS3_API_LOG", FALSE);
1717
}
1818
//是否显示日志(直接输出日志)
1919
if (!defined("KS3_API_DISPLAY_LOG")) {
20-
define("KS3_API_DISPLAY_LOG", FALSE);
20+
define("KS3_API_DISPLAY_LOG", FALSE);
2121
}
2222
//定义日志目录(默认是该项目log下)
2323
if (!defined("KS3_API_LOG_PATH")) {
24-
define("KS3_API_LOG_PATH", "");
24+
define("KS3_API_LOG_PATH", "");
2525
}
2626
//是否使用HTTPS
2727
if (!defined("KS3_API_USE_HTTPS")) {
28-
define("KS3_API_USE_HTTPS", FALSE);
28+
define("KS3_API_USE_HTTPS", FALSE);
2929
}
3030
//是否开启curl debug模式
3131
if (!defined("KS3_API_DEBUG_MODE")) {
32-
define("KS3_API_DEBUG_MODE", FALSE);
32+
define("KS3_API_DEBUG_MODE", FALSE);
3333
}
3434
define("KS3_API_Author", "lijunwei@kingsoft.com");
3535
define("KS3_API_Version", "1.2");
@@ -68,7 +68,6 @@ class Ks3Client
6868
private $accessKey;
6969
private $secretKey;
7070
private $endpoint;
71-
private $log;
7271

7372
public function __construct($accessKey = NULL, $secretKey = NULL, $endpoint = NULL)
7473
{
@@ -81,48 +80,47 @@ public function __construct($accessKey = NULL, $secretKey = NULL, $endpoint = NU
8180
$this->endpoint = $endpoint;
8281

8382
$this->signers = array();
84-
$this->log = new Logger();
8583
}
8684

87-
/**
88-
* 方法列表:(具体使用请参考readme.md)
89-
* listBuckets,罗列bucket
90-
* deleteBucket,删除bucket
91-
* deleteBucketCORS,删除bucket跨域配置
92-
* createBucket,新建bucket
93-
* setBucketAcl,设置bucket访问权限
94-
* setBucketCORS,设置bucket跨域配置
95-
* setBucketLogging,设置bucket日志配置
96-
* listObjects,罗列object
97-
* getBucketAcl,获取bucket访问权限
98-
* getBucketCORS,获取bucket跨域配置
99-
* getBucketLocation,获取bucket地点配置
100-
* getBucketLogging,获取bucket日志配置
101-
* bucketExists,判断bucket是否存在
102-
* listMutipartUploads,罗列当前bucket下尚未结束的分块上传
103-
* putObjectByContent,上传文件
104-
* putObjectByFile,上传文件
105-
* setObjectAcl,设置object访问权限
106-
* copyObject,复制object
107-
* getObjectMeta,获取object元数据
108-
* objectExists,判断object是否存在
109-
* deleteObject,删除object
110-
* deleteObjects,删除多个object
111-
* getObject,下载object
112-
* getObjectAcl,获取object访问权限
113-
* initMultipartUpload,初始化分块上传
114-
* uploadPart,上传块
115-
* abortMultipartUpload,终止分块上传
116-
* listParts,罗列已经上传的块
117-
* completeMultipartUpload,完成分块上传
118-
* generatePresignedUrl,生成文件外链
119-
* putAdp,添加异步数据处理任务
120-
* getAdp,查询异步数据处理任务
121-
* @param $method
122-
* @param array $args
123-
* @return ResponseCore|string|string[]|null
124-
* @throws Exception
125-
*/
85+
/**
86+
* 方法列表:(具体使用请参考readme.md)
87+
* listBuckets,罗列bucket
88+
* deleteBucket,删除bucket
89+
* deleteBucketCORS,删除bucket跨域配置
90+
* createBucket,新建bucket
91+
* setBucketAcl,设置bucket访问权限
92+
* setBucketCORS,设置bucket跨域配置
93+
* setBucketLogging,设置bucket日志配置
94+
* listObjects,罗列object
95+
* getBucketAcl,获取bucket访问权限
96+
* getBucketCORS,获取bucket跨域配置
97+
* getBucketLocation,获取bucket地点配置
98+
* getBucketLogging,获取bucket日志配置
99+
* bucketExists,判断bucket是否存在
100+
* listMutipartUploads,罗列当前bucket下尚未结束的分块上传
101+
* putObjectByContent,上传文件
102+
* putObjectByFile,上传文件
103+
* setObjectAcl,设置object访问权限
104+
* copyObject,复制object
105+
* getObjectMeta,获取object元数据
106+
* objectExists,判断object是否存在
107+
* deleteObject,删除object
108+
* deleteObjects,删除多个object
109+
* getObject,下载object
110+
* getObjectAcl,获取object访问权限
111+
* initMultipartUpload,初始化分块上传
112+
* uploadPart,上传块
113+
* abortMultipartUpload,终止分块上传
114+
* listParts,罗列已经上传的块
115+
* completeMultipartUpload,完成分块上传
116+
* generatePresignedUrl,生成文件外链
117+
* putAdp,添加异步数据处理任务
118+
* getAdp,查询异步数据处理任务
119+
* @param $method
120+
* @param array $args
121+
* @return ResponseCore|string|string[]|null
122+
* @throws Exception
123+
*/
126124
public function __call($method, $args = array())
127125
{
128126
$holder = new MessageHolder();
@@ -137,10 +135,9 @@ public function __call($method, $args = array())
137135
$ex = $e;
138136
}
139137
$holder->msg .= "------------------Logging End-------------------------\r\n";
140-
$this->log->info($holder->msg);
141138
if ($ex != NULL) {
142-
throw $ex;
143-
}
139+
throw $ex;
140+
}
144141
return $result;
145142
}
146143

@@ -167,8 +164,8 @@ private function invoke($method, $args = array(), $holder, $location = NULL)
167164
} else {
168165
$request->bucket = $args["Bucket"];
169166
}
170-
$position = $api["objectPostion"] ?? "Key";
171-
if (empty($args[$position])) {
167+
$position = $api["objectPostion"] ?? "Key";
168+
if (empty($args[$position])) {
172169
if ($api["needObject"]) {
173170
throw new Ks3ClientException($method . " this api need " . $position);
174171
}
@@ -192,11 +189,10 @@ private function invoke($method, $args = array(), $holder, $location = NULL)
192189
$request->method = $api["method"];
193190
}
194191
if (KS3_API_USE_HTTPS) {
195-
$request->scheme = "https://";
196-
}
197-
else {
198-
$request->scheme = "http://";
199-
}
192+
$request->scheme = "https://";
193+
} else {
194+
$request->scheme = "http://";
195+
}
200196
$request->endpoint = $this->endpoint;
201197
//add subresource
202198
if (!empty($api["subResource"])) {
@@ -231,16 +227,16 @@ private function invoke($method, $args = array(), $holder, $location = NULL)
231227
break;
232228
}
233229

234-
$curIndexArg = $curIndexArg[$value1];
235-
}
230+
$curIndexArg = $curIndexArg[$value1];
231+
}
236232
}
237233
if (!empty($curIndexArg) && $add) {
238234
$request->addQueryParams($curkey, $curIndexArg);
239235
continue;
240236
}
241237
if ($required) {
242-
throw new Ks3ClientException($method . " param " . $value . " is required");
243-
}
238+
throw new Ks3ClientException($method . " param " . $value . " is required");
239+
}
244240
}
245241
}
246242
if (isset($api["body"])) {
@@ -286,12 +282,12 @@ private function invoke($method, $args = array(), $holder, $location = NULL)
286282
if ($signer === NULL || !($signer instanceof QueryAuthSigner)) {
287283
$url = $request->toUrl($this->endpoint);
288284
if ($location != NULL) {
289-
$url = $location;
290-
}
285+
$url = $location;
286+
}
291287
$httpRequest = new RequestCore($url);
292288
if (KS3_API_DEBUG_MODE === TRUE) {
293-
$httpRequest->debug_mode = TRUE;
294-
}
289+
$httpRequest->debug_mode = TRUE;
290+
}
295291
$httpRequest->set_method($request->method);
296292
foreach ($request->headers as $key => $value) {
297293
$httpRequest->add_header($key, $value);
@@ -351,14 +347,14 @@ private function invoke($method, $args = array(), $holder, $location = NULL)
351347
return $data;
352348
}
353349

354-
$url = $request->toUrl($this->endpoint);
355-
$holder->msg .= $url . "\r\n";
356-
return $url;
357-
}
350+
$url = $request->toUrl($this->endpoint);
351+
$holder->msg .= $url . "\r\n";
352+
return $url;
353+
}
358354

359355
//用于生产表单上传时的签名信息
360356
public function postObject($bucket, $postFormData = array(), $unknowValueFormFiled = array(), $filename = NULL, $expire = 18000): array
361-
{
357+
{
362358
$policy = array();
363359

364360
$expireTime = Utils::iso8601(time() + $expire);
@@ -386,6 +382,4 @@ public function postObject($bucket, $postFormData = array(), $unknowValueFormFil
386382
$result["KSSAccessKeyId"] = $this->accessKey;
387383
return $result;
388384
}
389-
}
390-
391-
385+
}

src/service/qiniu/KodoService.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ public function bucket(string $bucket): self
7070
/**
7171
* @param string $object
7272
* @param string $filePath
73-
* @return bool|mixed
73+
* @return bool
7474
* @throws Exception
7575
*/
76-
public function upload(string $object, string $filePath)
76+
public function upload(string $object, string $filePath): bool
7777
{
7878
// 初始化签权对象
7979
$auth = new Auth($this->accessKey, $this->secretKey);
@@ -83,11 +83,7 @@ public function upload(string $object, string $filePath)
8383
$uploadMgr = new UploadManager();
8484
// 调用 UploadManager 的 putFile 方法进行文件的上传。
8585
[$ret, $err] = $uploadMgr->putFile($token, $object, $filePath);
86-
if ($err !== null) {
87-
return false;
88-
}
89-
90-
return $ret;
86+
return !($err !== null);
9187

9288
}
9389
}

src/service/tencent/CosService.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,12 @@ public function upload(string $object, string $filePath): bool
9393
$key = $object;
9494
$file = fopen($filePath, "rb");
9595
if ($file) {
96-
return $cosClient->putObject([
96+
$cosClient->putObject([
9797
'Bucket' => $this->bucket,
9898
'Key' => $key,
9999
'Body' => $file
100100
]);
101+
return true;
101102
}
102103

103104
return false;

src/service/upyun/UssService.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,15 @@ public function operatorPassword(string $operatorPassword)
7070
/**
7171
* @param string $object
7272
* @param string $filePath
73-
* @return array|bool
73+
* @return bool
7474
* @throws Exception
7575
*/
76-
public function upload(string $object, string $filePath)
76+
public function upload(string $object, string $filePath): bool
7777
{
7878
$serviceConfig = new Config($this->serviceName, $this->operatorName, $this->operatorPassword);
7979
$client = new Upyun($serviceConfig);
8080
$file = fopen($filePath, 'r');
81-
return $client->write($object, $file);
81+
$client->write($object, $file);
82+
return true;
8283
}
8384
}

0 commit comments

Comments
 (0)