From 1e5177b086e5941dca6d96645abd97c4e7478e2f Mon Sep 17 00:00:00 2001 From: Alone88 Date: Thu, 16 Dec 2021 20:09:09 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20guzzle7=20=E7=9A=84?= =?UTF-8?q?=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 9 +++++++-- src/Upyun/Api/Rest.php | 2 +- src/Upyun/Api/SyncVideo.php | 4 ++-- src/Upyun/Signature.php | 10 +++++----- src/Upyun/Uploader.php | 8 ++++---- src/Upyun/Upyun.php | 4 ++-- 6 files changed, 21 insertions(+), 16 deletions(-) diff --git a/composer.json b/composer.json index 6431520..9eee64b 100644 --- a/composer.json +++ b/composer.json @@ -7,9 +7,10 @@ "homepage": "https://github.com/upyun/php-sdk/", "license": "MIT", "require": { - "php": ">=5.5.0", + "php": "^7.2.5 || ^8.0", "ext-curl": "*", - "guzzlehttp/guzzle": "~6.0" + "guzzlehttp/guzzle": "~7.0", + "ext-json": "*" }, "require-dev": { "phpunit/phpunit": "~4.0", @@ -38,6 +39,10 @@ { "name": "sabakugaara", "email": "senellise@gmail.com" + }, + { + "name": "alapi", + "email": "im@alone88.cn" } ] } diff --git a/src/Upyun/Api/Rest.php b/src/Upyun/Api/Rest.php index be4b0a0..13f16b3 100644 --- a/src/Upyun/Api/Rest.php +++ b/src/Upyun/Api/Rest.php @@ -47,7 +47,7 @@ public function request($method, $storagePath) */ public function withFile($file) { - $stream = Psr7\stream_for($file); + $stream = Psr7\Utils::streamFor($file); $this->file = $stream; return $this; diff --git a/src/Upyun/Api/SyncVideo.php b/src/Upyun/Api/SyncVideo.php index 39d1972..c99732b 100644 --- a/src/Upyun/Api/SyncVideo.php +++ b/src/Upyun/Api/SyncVideo.php @@ -36,7 +36,7 @@ public function process($params, $path) { 'json' => $params ]); - $body = $response->getBody()->getContents(); + $body = (string)$response->getBody(); return json_decode($body, true); } -} \ No newline at end of file +} diff --git a/src/Upyun/Signature.php b/src/Upyun/Signature.php index 0fb68fe..0870436 100644 --- a/src/Upyun/Signature.php +++ b/src/Upyun/Signature.php @@ -67,13 +67,13 @@ public static function getPurgeSignHeader(Config $serviceConfig, $urlString) /** * 获取表单 API 需要的签名,依据 body 签名规则计算 * @param Config $serviceConfig - * @param $method 请求方法 - * @param $uri 请求路径 - * @param $date 请求时间 + * @param $method string 请求方法 + * @param $uri string 请求路径 + * @param $date string 请求时间 * @param $policy - * @param $contentMd5 请求 body 的 md5 + * @param $contentMd5 string 请求 body 的 md5 * - * @return array + * @return string */ public static function getBodySignature(Config $serviceConfig, $method, $uri, $date = null, $policy = null, $contentMd5 = null) { diff --git a/src/Upyun/Uploader.php b/src/Upyun/Uploader.php index 95e6f2f..ab3b91c 100644 --- a/src/Upyun/Uploader.php +++ b/src/Upyun/Uploader.php @@ -24,7 +24,7 @@ public function __construct(Config $config) public function upload($path, $file, $params, $withAsyncProcess) { - $stream = Psr7\stream_for($file); + $stream = Psr7\Utils::streamFor($file); $size = $stream->getSize(); $useBlock = $this->needUseBlock($size); @@ -87,7 +87,7 @@ private function pointUpload($path, $stream, $params) 'X-Upyun-Multi-Uuid' => $uuid, 'X-Upyun-Part-Id' => $partId )) - ->withFile(Psr7\stream_for($fileBlock)) + ->withFile(Psr7\Utils::streamFor($fileBlock)) ->send(); if ($res->getStatusCode() !== 204) { @@ -146,7 +146,7 @@ private function concurrentPointUpload($path, $stream, $params) ->withHeaders(array_merge(array( 'X-Upyun-Multi-Disorder' => 'true', 'X-Upyun-Multi-Stage' => 'initiate', - 'X-Upyun-Multi-Type' => Psr7\mimetype_from_filename($path), + 'X-Upyun-Multi-Type' => Psr7\MimeType::fromFilename($path), 'X-Upyun-Multi-Length' => $stream->getSize(), ), $headers)) ->send(); @@ -167,7 +167,7 @@ private function concurrentPointUpload($path, $stream, $params) 'X-Upyun-Multi-Uuid' => $uuid, 'X-Upyun-Part-Id' => $i )) - ->withFile(Psr7\stream_for($fileBlock)) + ->withFile(Psr7\Utils::streamFor($fileBlock)) ->toRequest(); } }; diff --git a/src/Upyun/Upyun.php b/src/Upyun/Upyun.php index e74c6c7..fcbd10b 100644 --- a/src/Upyun/Upyun.php +++ b/src/Upyun/Upyun.php @@ -154,7 +154,7 @@ public function read($path, $saveHandler = null, $params = array()) if (! isset($params['x-upyun-list-iter'])) { if (is_resource($saveHandler)) { - Psr7\copy_to_stream($response->getBody(), Psr7\stream_for($saveHandler)); + Psr7\Utils::copyToStream($response->getBody(), Psr7\Utils::streamFor($saveHandler)); return true; } else { return $response->getBody()->getContents(); @@ -351,7 +351,7 @@ public function purge($urls) 'headers' => Signature::getPurgeSignHeader($this->config, $urlString), 'form_params' => ['purge' => $urlString] ]); - $result = json_decode($response->getBody()->getContents(), true); + $result = json_decode((string)$response->getBody(), true); return $result['invalid_domain_of_url']; } From 02bbbd5555f1f38d264ce4f17ee2e97ea63d12f9 Mon Sep 17 00:00:00 2001 From: Alone88 Date: Thu, 16 Dec 2021 20:24:33 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E5=8C=85=E5=90=8D?= =?UTF-8?q?=EF=BC=8C=E6=8F=90=E4=BA=A4=E5=88=86=E6=94=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8eda96a..e880056 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ SDK 包含如下功能 建议使用速度很快的国内[全量镜像](https://pkg.phpcomposer.com/#how-to-use-packagist-mirror)([又拍云赞助](https://pkg.phpcomposer.com/#donation)) ``` -composer require upyun/sdk +composer require alapi/upyun-sdk ``` 2.如果不适应 `composer` 管理,可以直接下载[压缩包](https://github.com/upyun/php-sdk/releases)(注意需要下载 `php-sdk-版本号.zip` 格式的 zip 压缩包,不是 Source code 源码压缩包),解压后,项目中添加如下代码: diff --git a/composer.json b/composer.json index 9eee64b..94e6ef4 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "upyun/sdk", + "name": "alapi/upyun-sdk", "description": "UPYUN sdk for php", "keywords": ["UPYUN", "sdk"], "type": "library",