diff --git a/CHANGELOG-2.0.md b/CHANGELOG-2.0.md index 4e89cf8b1..97a89bb43 100644 --- a/CHANGELOG-2.0.md +++ b/CHANGELOG-2.0.md @@ -1,5 +1,9 @@ # v2.0.3 - TBD +## Added + +- [#2097](https://github.com/hyperf/hyperf/pull/2097) Added TencentCloud COS for `hyperf/filesystem`. + # v2.0.2 - 2020-07-13 ## Added diff --git a/composer.json b/composer.json index 018c1d1a6..6bc9d609f 100644 --- a/composer.json +++ b/composer.json @@ -63,6 +63,7 @@ "nikic/fast-route": "^1.3", "nikic/php-parser": "^4.1", "overtrue/flysystem-qiniu": "^1.0", + "overtrue/flysystem-cos": "^2.0", "php-amqplib/php-amqplib": "^2.7", "php-di/php-di": "^6.0", "php-di/phpdoc-reader": "^2.0.1", diff --git a/docs/zh-cn/filesystem.md b/docs/zh-cn/filesystem.md index b2354058b..c9966e987 100644 --- a/docs/zh-cn/filesystem.md +++ b/docs/zh-cn/filesystem.md @@ -16,6 +16,8 @@ composer require hyperf/guzzle composer require overtrue/flysystem-qiniu # 使用内存适配器时执行 composer require league/flysystem-memory +# 使用腾讯云 COS 适配器时执行 +composer require overtrue/flysystem-cos ``` 安装完成后,执行 @@ -128,7 +130,7 @@ return [ ## 注意事项 -1. S3 存储请确认安装 `hyperf/guzzle` 组件以提供协程化支持。阿里云、七牛云存储请[开启 Curl Hook](/zh-cn/coroutine?id=swoole-runtime-hook-level)来使用协程。因 Curl Hook 的参数支持性问题,请使用 Swoole 4.4.13 以上版本。 +1. S3 存储请确认安装 `hyperf/guzzle` 组件以提供协程化支持。阿里云、七牛云、腾讯云云存储请[开启 Curl Hook](/zh-cn/coroutine?id=swoole-runtime-hook-level)来使用协程。因 Curl Hook 的参数支持性问题,请使用 Swoole 4.4.13 以上版本。 2. minIO, ceph radosgw 等私有对象存储方案均支持 S3 协议,可以使用 S3 适配器。 3. 使用 Local 驱动时,根目录是配置好的地址,而不是操作系统的根目录。例如,Local 驱动 `root` 设置为 `/var/www`, 则本地磁盘上的 `/var/www/public/file.txt` 通过 flysystem API 访问时应使用 `/public/file.txt` 或 `public/file.txt` 。 4. 以阿里云 OSS 为例,1 核 1 进程读操作性能对比: @@ -241,6 +243,21 @@ return [ 'bucket' => env('QINIU_BUCKET'), 'domain' => env('QINIU_DOMAIN'), ], + 'cos' => [ + 'driver' => \Hyperf\Filesystem\Adapter\CosAdapterFactory::class, + 'region' => env('COS_REGION'), + 'credentials' => [ + 'appId' => env('COS_APPID'), + 'secretId' => env('COS_SECRET_ID'), + 'secretKey' => env('COS_SECRET_KEY'), + ], + 'bucket' => env('COS_BUCKET'), + 'read_from_cdn' => false, + // 'timeout' => 60, + // 'connect_timeout' => 60, + // 'cdn' => '', + // 'scheme' => 'https', + ], ], ]; ``` diff --git a/src/filesystem/composer.json b/src/filesystem/composer.json index 76640f6d3..dc707a189 100644 --- a/src/filesystem/composer.json +++ b/src/filesystem/composer.json @@ -34,6 +34,7 @@ "league/flysystem-aws-s3-v3": "^1.0", "league/flysystem-memory": "^1.0", "overtrue/flysystem-qiniu": "^1.0", + "overtrue/flysystem-cos": "^2.0", "phpstan/phpstan": "^0.10.5", "xxtime/flysystem-aliyun-oss": "^1.5" }, @@ -42,7 +43,8 @@ "league/flysystem-memory": "required to use memory adapter", "hyperf/guzzle": "required to use s3 adapter", "league/flysystem-aws-s3-v3": "required to use s3 adapter", - "overtrue/flysystem-qiniu": "required to use qiniu adapter" + "overtrue/flysystem-qiniu": "required to use qiniu adapter", + "overtrue/flysystem-cos": "required to use cos adapter" }, "config": { "sort-packages": true diff --git a/src/filesystem/publish/file.php b/src/filesystem/publish/file.php index b22788b80..cc6bf9e67 100644 --- a/src/filesystem/publish/file.php +++ b/src/filesystem/publish/file.php @@ -75,5 +75,20 @@ return [ 'bucket' => env('QINIU_BUCKET'), 'domain' => env('QINBIU_DOMAIN'), ], + 'cos' => [ + 'driver' => \Hyperf\Filesystem\Adapter\CosAdapterFactory::class, + 'region' => env('COS_REGION'), + 'credentials' => [ + 'appId' => env('COS_APPID'), + 'secretId' => env('COS_SECRET_ID'), + 'secretKey' => env('COS_SECRET_KEY'), + ], + 'bucket' => env('COS_BUCKET'), + 'read_from_cdn' => false, + // 'timeout' => 60, + // 'connect_timeout' => 60, + // 'cdn' => '', + // 'scheme' => 'https', + ], ], ]; diff --git a/src/filesystem/src/Adapter/CosAdapterFactory.php b/src/filesystem/src/Adapter/CosAdapterFactory.php new file mode 100644 index 000000000..9684aab7e --- /dev/null +++ b/src/filesystem/src/Adapter/CosAdapterFactory.php @@ -0,0 +1,24 @@ +