From b4838a3fed13dd40d41d5af73a9b584b747b2ffd Mon Sep 17 00:00:00 2001 From: zgldh Date: Thu, 17 Feb 2022 19:47:47 +0800 Subject: [PATCH] Migrate getDriver to getAdapter --- README.md | 46 +++++++++++++------------- src/QiniuFilesystemServiceProvider.php | 15 --------- src/QiniuStorage.php | 30 ++++++++--------- 3 files changed, 38 insertions(+), 53 deletions(-) diff --git a/README.md b/README.md index 84521ef3..d075f82b 100755 --- a/README.md +++ b/README.md @@ -102,42 +102,42 @@ $disk->url('a.png'); //返回文件的URL $disk->url(['path' => 'a.png', 'domainType' => 'default']); //返回文件的URL - $disk->getDriver()->uploadToken(); //获取上传Token - $disk->getDriver()->uploadToken('file.jpg'); //获取上传Token + $disk->getAdapter()->uploadToken(); //获取上传Token + $disk->getAdapter()->uploadToken('file.jpg'); //获取上传Token - $disk->getDriver()->withUploadToken($token); // 使用自定义的 uploadToken 进行上传, + $disk->getAdapter()->withUploadToken($token); // 使用自定义的 uploadToken 进行上传, $disk->put('file.jpg',$content); // 则本次的 put 操作,将使用上述的 $token 进行上传。 // 常用于自动触发持久化处理 https://github.com/qiniu/php-sdk/blob/master/examples/upload_and_pfop.php - $disk->getDriver()->downloadUrl('file.jpg'); //获取下载地址 - $disk->getDriver()->downloadUrl('file.jpg') + $disk->getAdapter()->downloadUrl('file.jpg'); //获取下载地址 + $disk->getAdapter()->downloadUrl('file.jpg') ->setDownload('foo.jpg'); //获取下载地址,文件名为 foo.jpg - $disk->getDriver()->downloadUrl('file.jpg', 'https'); //获取HTTPS下载地址 - $disk->getDriver()->privateDownloadUrl('file.jpg'); //获取私有bucket下载地址 - $disk->getDriver()->privateDownloadUrl('file.jpg?attname=foo.jpg'); + $disk->getAdapter()->downloadUrl('file.jpg', 'https'); //获取HTTPS下载地址 + $disk->getAdapter()->privateDownloadUrl('file.jpg'); //获取私有bucket下载地址 + $disk->getAdapter()->privateDownloadUrl('file.jpg?attname=foo.jpg'); //获取私有bucket下载地址,文件名为 foo.jpg - $disk->getDriver()->privateDownloadUrl('file.jpg', 'https');//获取私有bucket的HTTPS下载地址 - $disk->getDriver()->privateDownloadUrl('file.jpg', + $disk->getAdapter()->privateDownloadUrl('file.jpg', 'https');//获取私有bucket的HTTPS下载地址 + $disk->getAdapter()->privateDownloadUrl('file.jpg', [ 'domain'=>'https', 'expires'=>3600 ]); //获取私有bucket的HTTPS下载地址。超时 3600 秒。 - $disk->getDriver()->avInfo('file.mp3'); //获取多媒体文件信息 - $disk->getDriver()->imageInfo('file.jpg'); //获取图片信息 - $disk->getDriver()->imageExif('file.jpg'); //获取图片EXIF信息 - $disk->getDriver()->imagePreviewUrl('file.jpg','imageView2/0/w/100/h/200'); //获取图片预览URL - $disk->getDriver()->privateImagePreviewUrl('file.jpg','imageView2/0/w/100/h/200'); //获取私有bucket图片预览URL - $disk->getDriver()->verifyCallback('application/x-www-form-urlencoded', $request->header('Authorization'), 'callback url', $request->getContent());//验证回调内容是否合法 - $disk->getDriver()->persistentFop('file.flv','avthumb/m3u8/segtime/40/vcodec/libx264/s/320x240'); //执行持久化数据处理 - $disk->getDriver()->persistentFop('file.flv','fop','队列名'); //使用私有队列执行持久化数据处理 - $disk->getDriver()->persistentStatus($persistent_fop_id); //查看持久化数据处理的状态。 - $disk->getDriver()->fetch('http://abc.com/foo.jpg', 'bar.jpg'); //调用fetch将 foo.jpg 数据以 bar.jpg 的名字储存起来。 - $disk->getDriver()->qetag(); //得到最后一次执行 put, copy, append 等写入操作后,得到的hash值。详见 https://github.com/qiniu/qetag - $disk->getDriver()->lastReturn(); //得到最后一次执行 put, copy, append 等写入操作后,得到的返回值。 + $disk->getAdapter()->avInfo('file.mp3'); //获取多媒体文件信息 + $disk->getAdapter()->imageInfo('file.jpg'); //获取图片信息 + $disk->getAdapter()->imageExif('file.jpg'); //获取图片EXIF信息 + $disk->getAdapter()->imagePreviewUrl('file.jpg','imageView2/0/w/100/h/200'); //获取图片预览URL + $disk->getAdapter()->privateImagePreviewUrl('file.jpg','imageView2/0/w/100/h/200'); //获取私有bucket图片预览URL + $disk->getAdapter()->verifyCallback('application/x-www-form-urlencoded', $request->header('Authorization'), 'callback url', $request->getContent());//验证回调内容是否合法 + $disk->getAdapter()->persistentFop('file.flv','avthumb/m3u8/segtime/40/vcodec/libx264/s/320x240'); //执行持久化数据处理 + $disk->getAdapter()->persistentFop('file.flv','fop','队列名'); //使用私有队列执行持久化数据处理 + $disk->getAdapter()->persistentStatus($persistent_fop_id); //查看持久化数据处理的状态。 + $disk->getAdapter()->fetch('http://abc.com/foo.jpg', 'bar.jpg'); //调用fetch将 foo.jpg 数据以 bar.jpg 的名字储存起来。 + $disk->getAdapter()->qetag(); //得到最后一次执行 put, copy, append 等写入操作后,得到的hash值。详见 https://github.com/qiniu/qetag + $disk->getAdapter()->lastReturn(); //得到最后一次执行 put, copy, append 等写入操作后,得到的返回值。 ``` -第二种用法 (就是省略了一个getDriver) +第二种用法 (就是省略了一个getAdapter) ```php diff --git a/src/QiniuFilesystemServiceProvider.php b/src/QiniuFilesystemServiceProvider.php index 1d0e33b3..e66eb3ce 100644 --- a/src/QiniuFilesystemServiceProvider.php +++ b/src/QiniuFilesystemServiceProvider.php @@ -47,21 +47,6 @@ function ($app, $config) { isset($config['hotlink_prevention_key']) ? $config['hotlink_prevention_key'] : null ); $file_system = new Filesystem($qiniu_adapter); - $file_system->addPlugin(new PrivateDownloadUrl()); - $file_system->addPlugin(new DownloadUrl()); - $file_system->addPlugin(new AvInfo()); - $file_system->addPlugin(new ImageInfo()); - $file_system->addPlugin(new ImageExif()); - $file_system->addPlugin(new ImagePreviewUrl()); - $file_system->addPlugin(new PersistentFop()); - $file_system->addPlugin(new PersistentStatus()); - $file_system->addPlugin(new UploadToken()); - $file_system->addPlugin(new PrivateImagePreviewUrl()); - $file_system->addPlugin(new VerifyCallback()); - $file_system->addPlugin(new Fetch()); - $file_system->addPlugin(new Qetag()); - $file_system->addPlugin(new WithUploadToken()); - $file_system->addPlugin(new LastReturn()); return new FilesystemAdapter($file_system, $qiniu_adapter, $config); } diff --git a/src/QiniuStorage.php b/src/QiniuStorage.php index e5fddb34..35109372 100644 --- a/src/QiniuStorage.php +++ b/src/QiniuStorage.php @@ -160,7 +160,7 @@ public function deleteDirectory($key) */ public function uploadToken($key = null, $expires = 3600, $policy = null, $strictPolicy = true) { - return $this->storage->getDriver()->uploadToken($key, $expires, $policy, $strictPolicy); + return $this->storage->getAdapter()->uploadToken($key, $expires, $policy, $strictPolicy); } /** @@ -170,7 +170,7 @@ public function uploadToken($key = null, $expires = 3600, $policy = null, $stric */ public function withUploadToken($token) { - $this->storage->getDriver()->withUploadToken($token); + $this->storage->getAdapter()->withUploadToken($token); } /** @@ -180,7 +180,7 @@ public function withUploadToken($token) */ public function downloadUrl($key, $domainType = 'default') { - return $this->storage->getDriver()->downloadUrl($key, $domainType); + return $this->storage->getAdapter()->downloadUrl($key, $domainType); } /** @@ -190,7 +190,7 @@ public function downloadUrl($key, $domainType = 'default') */ public function privateDownloadUrl($key, $domainType = 'default') { - return $this->storage->getDriver()->privateDownloadUrl($key, $domainType); + return $this->storage->getAdapter()->privateDownloadUrl($key, $domainType); } /** @@ -200,7 +200,7 @@ public function privateDownloadUrl($key, $domainType = 'default') */ public function avInfo($key) { - return $this->storage->getDriver()->avInfo($key); + return $this->storage->getAdapter()->avInfo($key); } /** @@ -210,7 +210,7 @@ public function avInfo($key) */ public function imageInfo($key) { - return $this->storage->getDriver()->imageInfo($key); + return $this->storage->getAdapter()->imageInfo($key); } /** @@ -220,7 +220,7 @@ public function imageInfo($key) */ public function imageExif($key) { - return $this->storage->getDriver()->imageExif($key); + return $this->storage->getAdapter()->imageExif($key); } /** @@ -231,7 +231,7 @@ public function imageExif($key) */ public function imagePreviewUrl($key, $opts) { - return $this->storage->getDriver()->imagePreviewUrl($key, $opts); + return $this->storage->getAdapter()->imagePreviewUrl($key, $opts); } /** @@ -242,7 +242,7 @@ public function imagePreviewUrl($key, $opts) */ public function privateImagePreviewUrl($key, $opts) { - return $this->storage->getDriver()->privateImagePreviewUrl($key, $opts); + return $this->storage->getAdapter()->privateImagePreviewUrl($key, $opts); } /** @@ -256,7 +256,7 @@ public function privateImagePreviewUrl($key, $opts) */ public function persistentFop($key, $opts, $pipline = null, $force = false, $notify_url = null) { - return $this->storage->getDriver()->persistentFop($key, $opts, $pipline, $force, $notify_url); + return $this->storage->getAdapter()->persistentFop($key, $opts, $pipline, $force, $notify_url); } /** @@ -266,7 +266,7 @@ public function persistentFop($key, $opts, $pipline = null, $force = false, $not */ public function persistentStatus($id) { - return $this->storage->getDriver()->persistentStatus($id); + return $this->storage->getAdapter()->persistentStatus($id); } /** @@ -276,7 +276,7 @@ public function persistentStatus($id) */ public function verifyCallback($contentType, $originAuthorization, $url, $body) { - return $this->storage->getDriver()->verifyCallback($contentType, $originAuthorization, $url, $body); + return $this->storage->getAdapter()->verifyCallback($contentType, $originAuthorization, $url, $body); } /** @@ -287,7 +287,7 @@ public function verifyCallback($contentType, $originAuthorization, $url, $body) */ public function fetch($url, $key) { - return $this->storage->getDriver()->fetch($url, $key); + return $this->storage->getAdapter()->fetch($url, $key); } /** @@ -296,7 +296,7 @@ public function fetch($url, $key) */ public function qetag() { - return $this->storage->getDriver()->qetag(); + return $this->storage->getAdapter()->qetag(); } /** @@ -305,6 +305,6 @@ public function qetag() */ public function lastReturn() { - return $this->storage->getDriver()->getLastReturn(); + return $this->storage->getAdapter()->getLastReturn(); } }