diff --git a/README.md b/README.md index dfb92c9..6ad57dd 100644 --- a/README.md +++ b/README.md @@ -21,14 +21,19 @@

+## 目录 +- laravel >= 9 `composer require "iidestiny/laravel-filesystem-oss:^3"` +- laravel < 9 `composer require "iidestiny/laravel-filesystem-oss:^2"` + ## 扩展包要求 -- PHP >= 7.0 +- PHP >= 8.02 +- Laravel >= 9 ## 安装命令 ```shell -$ composer require "iidestiny/laravel-filesystem-oss" -vvv +$ composer require "iidestiny/laravel-filesystem-oss:^3" -vvv ``` ## 配置 @@ -86,22 +91,6 @@ $disk = Storage::disk('oss'); // 上传 $disk->put('avatars/filename.jpg', $fileContents); - -// 检查文件是否存在 -$exists = $disk->has('file.jpg'); - -// 获取文件修改时间 -$time = $disk->lastModified('file1.jpg'); -$time = $disk->getTimestamp('file1.jpg'); - -// 拷贝文件 -$disk->copy('old/file1.jpg', 'new/file1.jpg'); - -// 移动文件也可改名 -$disk->move('old/file1.jpg', 'new/file1.jpg'); - -// 获取文件内容 -$contents = $disk->read('folder/my_file.txt'); ``` 以上方法可在 [laravel-filesystem-doc](https://laravel.com/docs/5.5/filesystem) 查阅 @@ -110,16 +99,13 @@ $contents = $disk->read('folder/my_file.txt'); ```php // 获取文件访问地址「公共读的 bucket 才生效」 -$url = $disk->getUrl('folder/my_file.txt'); +$url = $disk->getAdapter()->getUrl('folder/my_file.txt'); // 设置文件访问有效期「$timeout 为多少秒过期」「私有 bucket 才可看见效果」 -$url = $disk->signUrl('cat.png', $timeout, ['x-oss-process' => 'image/circle,r_100']); - -// 和 signurl 功能一样,区别在于 $expiration 是未来过期时间如:2019-05-05 17:50:32 时链接失效 -$url = $disk->getTemporaryUrl('file.md', $expiration); +$url = $disk->getAdapter()->getTemporaryUrl('cat.png', $timeout, ['x-oss-process' => 'image/circle,r_100']); // 可切换其他 bucket「需要在 config 配置文件中配置 buckets」 -$exists = $disk->bucket('test')->has('file.jpg'); +$exists = $disk->getAdapter()->bucket('test')->xxx('file.jpg'); ``` ## 获取官方完整 OSS 处理能力 @@ -129,7 +115,7 @@ $exists = $disk->bucket('test')->has('file.jpg'); ```php // 获取完整处理能力 -$kernel = $disk->kernel(); +$kernel = $disk->getAdapter()->ossKernel(); // 例如:防盗链功能 $refererConfig = new RefererConfig(); @@ -155,7 +141,7 @@ oss 直传有三种方式,当前扩展包使用的是最完整的 [服务端 * 3. 回调自定义参数,oss 回传应用服务器时会带上 * 4. 当前直传配置链接有效期 */ -$config = $disk->signatureConfig($prefix = '/', $callBackUrl = '', $customData = [], $expire = 30); +$config = $disk->getAdapter()->signatureConfig($prefix = '/', $callBackUrl = '', $customData = [], $expire = 30); ``` ## 直传回调验签 @@ -169,8 +155,8 @@ $config = $disk->signatureConfig($prefix = '/', $callBackUrl = '', $customData = ```php // 验签,就是如此简单 // $verify 验签结果,$data 回调数据 -list($verify, $data) = $disk->verify(); -// [$verify, $data] = $disk->verify(); // php 7.1 + +list($verify, $data) = $disk->getAdapter()->verify(); +// [$verify, $data] = $disk->getAdapter()->verify(); // php 7.1 + if (!$verify) { // 验证失败处理,此时 $data 为验签失败提示信息 diff --git a/composer.json b/composer.json index 4471238..d726577 100644 --- a/composer.json +++ b/composer.json @@ -1,25 +1,28 @@ { - "name": "iidestiny/laravel-filesystem-oss", - "description": "Oss storage filesystem for Laravel.", - "license": "MIT", - "authors": [{ - "name": "iidestiny", - "email": "iidestiny@vip.qq.com" - }], - "require": { - "php": "^7.0|^8.0", - "iidestiny/flysystem-oss": "~2.0" - }, - "autoload": { - "psr-4": { - "Iidestiny\\LaravelFilesystemOss\\": "src" + "name": "iidestiny/laravel-filesystem-oss", + "description": "Oss storage filesystem for Laravel.", + "license": "MIT", + "authors": [ + { + "name": "iidestiny", + "email": "iidestiny@vip.qq.com" + } + ], + "require": { + "php": "^8.0.2", + "iidestiny/flysystem-oss": "^4.0", + "laravel/framework": "^9.0" + }, + "autoload": { + "psr-4": { + "Iidestiny\\LaravelFilesystemOss\\": "src" + } + }, + "extra": { + "laravel": { + "providers": [ + "Iidestiny\\LaravelFilesystemOss\\OssStorageServiceProvider" + ] + } } - }, - "extra": { - "laravel": { - "providers": [ - "Iidestiny\\LaravelFilesystemOss\\OssStorageServiceProvider" - ] - } - } } diff --git a/src/OssStorageServiceProvider.php b/src/OssStorageServiceProvider.php index 897271d..7a16ee6 100644 --- a/src/OssStorageServiceProvider.php +++ b/src/OssStorageServiceProvider.php @@ -12,13 +12,7 @@ namespace Iidestiny\LaravelFilesystemOss; use Iidestiny\Flysystem\Oss\OssAdapter; -use Iidestiny\Flysystem\Oss\Plugins\FileUrl; -use Iidestiny\Flysystem\Oss\Plugins\Kernel; -use Iidestiny\Flysystem\Oss\Plugins\SignUrl; -use Iidestiny\Flysystem\Oss\Plugins\TemporaryUrl; -use Iidestiny\Flysystem\Oss\Plugins\SignatureConfig; -use Iidestiny\Flysystem\Oss\Plugins\SetBucket; -use Iidestiny\Flysystem\Oss\Plugins\Verify; +use Illuminate\Filesystem\FilesystemAdapter; use Illuminate\Support\ServiceProvider; use League\Flysystem\Filesystem; @@ -38,7 +32,8 @@ public function boot() { app('filesystem')->extend('oss', function ($app, $config) { $root = $config['root'] ?? null; - $buckets = isset($config['buckets'])?$config['buckets']:[]; + $buckets = $config['buckets'] ?? []; + $adapter = new OssAdapter( $config['access_key'], $config['secret_key'], @@ -49,17 +44,7 @@ public function boot() $buckets ); - $filesystem = new Filesystem($adapter); - - $filesystem->addPlugin(new FileUrl()); - $filesystem->addPlugin(new SignUrl()); - $filesystem->addPlugin(new TemporaryUrl()); - $filesystem->addPlugin(new SignatureConfig()); - $filesystem->addPlugin(new SetBucket()); - $filesystem->addPlugin(new Verify()); - $filesystem->addPlugin(new Kernel()); - - return $filesystem; + return new FilesystemAdapter(new Filesystem($adapter), $adapter, $config); }); }