Passed
Branch master (edefdc)
by xiaohui
04:15
created
sdk/Utils/UploadPolicy.php 1 patch
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -5,47 +5,47 @@
 block discarded – undo
5 5
 
6 6
 class UploadPolicy
7 7
 {
8
-    /*如下属性是必须的[The following attributes are required]*/
9
-    public $namespace;                              // 多媒体服务的空间名[media namespace name]
10
-    public $bucket;                                 // OSS的空间名[media bucket name]
11
-    public $insertOnly;                             // 是否可覆盖[upload mode. it's not allowd uploading the same name files]
12
-    public $expiration;                             // 过期时间[expiration time, unix time, in milliseconds]
8
+	/*如下属性是必须的[The following attributes are required]*/
9
+	public $namespace;                              // 多媒体服务的空间名[media namespace name]
10
+	public $bucket;                                 // OSS的空间名[media bucket name]
11
+	public $insertOnly;                             // 是否可覆盖[upload mode. it's not allowd uploading the same name files]
12
+	public $expiration;                             // 过期时间[expiration time, unix time, in milliseconds]
13 13
 
14
-    /*如下属性是可选的[The following attributes are optional]*/
15
-    public $detectMime = Conf::DETECT_MIME_TRUE;                             // 是否进行类型检测[is auto detecte media file mime type, default is true]
16
-    public $dir;                                    // 路径[media file dir, magic vars and custom vars are supported]
17
-    public $name;                                   // 上传到服务端的文件名[media file name, magic vars and custom vars are supported]
18
-    public $sizeLimit;                              // 文件大小限制[upload size limited, in bytes]
19
-    public $mimeLimit;                              // 文件类型限制[upload mime type limited]
20
-    public $callbackUrl;                            // 回调URL [callback urls, ip address is recommended]
21
-    public $callbackHost;                           // 回调时Host [callback host]
22
-    public $callbackBody;                           // 回调时Body [callback body, magic vars and custom vars are supported]
23
-    public $callbackBodyType;                       // 回调时Body类型 [callback body type, default is 'application/x-www-form-urlencoded; charset=utf-8']
24
-    public $returnUrl;                              // 上传完成之后,303跳转的Url [return url, when return code is 303]
25
-    public $returnBody;                             // 上传完成返回体 [return body, magic vars and custom vars are supported]
26
-    public $mediaEncode;                            // 上传音视频时,可以指定转码策略[media encode policy after upload task has been completed. it's json string]
14
+	/*如下属性是可选的[The following attributes are optional]*/
15
+	public $detectMime = Conf::DETECT_MIME_TRUE;                             // 是否进行类型检测[is auto detecte media file mime type, default is true]
16
+	public $dir;                                    // 路径[media file dir, magic vars and custom vars are supported]
17
+	public $name;                                   // 上传到服务端的文件名[media file name, magic vars and custom vars are supported]
18
+	public $sizeLimit;                              // 文件大小限制[upload size limited, in bytes]
19
+	public $mimeLimit;                              // 文件类型限制[upload mime type limited]
20
+	public $callbackUrl;                            // 回调URL [callback urls, ip address is recommended]
21
+	public $callbackHost;                           // 回调时Host [callback host]
22
+	public $callbackBody;                           // 回调时Body [callback body, magic vars and custom vars are supported]
23
+	public $callbackBodyType;                       // 回调时Body类型 [callback body type, default is 'application/x-www-form-urlencoded; charset=utf-8']
24
+	public $returnUrl;                              // 上传完成之后,303跳转的Url [return url, when return code is 303]
25
+	public $returnBody;                             // 上传完成返回体 [return body, magic vars and custom vars are supported]
26
+	public $mediaEncode;                            // 上传音视频时,可以指定转码策略[media encode policy after upload task has been completed. it's json string]
27 27
 
28
-    public function __construct($option)
29
-    {
30
-        if (!isset($option['expiration']) || !$option['expiration']) {
31
-            $option['expiration'] = -1;
32
-        }
28
+	public function __construct($option)
29
+	{
30
+		if (!isset($option['expiration']) || !$option['expiration']) {
31
+			$option['expiration'] = -1;
32
+		}
33 33
 
34
-        foreach ($option as $attribute => $value) {
35
-            $this->{$attribute} = $value;
36
-        }
37
-    }
34
+		foreach ($option as $attribute => $value) {
35
+			$this->{$attribute} = $value;
36
+		}
37
+	}
38 38
 
39
-    public function toArray()
40
-    {
41
-        return (array) $this;
42
-        $array = [];
43
-        foreach ($this as $attribute => $value) {
44
-            if ($value !== null) {
45
-                $array[$attribute] = $value;
46
-            }
47
-        }
39
+	public function toArray()
40
+	{
41
+		return (array) $this;
42
+		$array = [];
43
+		foreach ($this as $attribute => $value) {
44
+			if ($value !== null) {
45
+				$array[$attribute] = $value;
46
+			}
47
+		}
48 48
 
49
-        return $array;
50
-    }
49
+		return $array;
50
+	}
51 51
 }
Please login to merge, or discard this patch.
sdk/Conf/Conf.php 1 patch
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -3,39 +3,39 @@
 block discarded – undo
3 3
 
4 4
 class Conf
5 5
 {
6
-    const CHARSET = "UTF-8";
7
-    const SDK_VERSION = '2.0.3';
6
+	const CHARSET = "UTF-8";
7
+	const SDK_VERSION = '2.0.3';
8 8
 
9
-    const UPLOAD_HOST_MEDIA = "https://upload.media.aliyun.com";        //文件上传的地址
10
-    const MANAGE_HOST_MEDIA = "https://rs.media.aliyun.com";            //服务管理的地址
11
-    const MANAGE_API_VERSION = "3.0";        //资源管理接口版本
12
-    const SCAN_PORN_VERSION = "3.1";        //黄图扫描接口版本
13
-    const MEDIA_ENCODE_VERSION = "3.0";        //媒体转码接口版本
9
+	const UPLOAD_HOST_MEDIA = "https://upload.media.aliyun.com";        //文件上传的地址
10
+	const MANAGE_HOST_MEDIA = "https://rs.media.aliyun.com";            //服务管理的地址
11
+	const MANAGE_API_VERSION = "3.0";        //资源管理接口版本
12
+	const SCAN_PORN_VERSION = "3.1";        //黄图扫描接口版本
13
+	const MEDIA_ENCODE_VERSION = "3.0";        //媒体转码接口版本
14 14
 
15
-    const UPLOAD_API_UPLOAD = "/api/proxy/upload";
16
-    const UPLOAD_API_BLOCK_INIT = "/api/proxy/blockInit";
17
-    const UPLOAD_API_BLOCK_UPLOAD = "/api/proxy/blockUpload";
18
-    const UPLOAD_API_BLOCK_COMPLETE = "/api/proxy/blockComplete";
19
-    const UPLOAD_API_BLOCK_CANCEL = "/api/proxy/blockCancel";
15
+	const UPLOAD_API_UPLOAD = "/api/proxy/upload";
16
+	const UPLOAD_API_BLOCK_INIT = "/api/proxy/blockInit";
17
+	const UPLOAD_API_BLOCK_UPLOAD = "/api/proxy/blockUpload";
18
+	const UPLOAD_API_BLOCK_COMPLETE = "/api/proxy/blockComplete";
19
+	const UPLOAD_API_BLOCK_CANCEL = "/api/proxy/blockCancel";
20 20
 
21
-    const TYPE_TOP = "TOP";
22
-    const TYPE_CLOUD = "CLOUD";
21
+	const TYPE_TOP = "TOP";
22
+	const TYPE_CLOUD = "CLOUD";
23 23
 
24
-    const DETECT_MIME_TRUE = 1;            //检测MimeType
25
-    const DETECT_MIME_NONE = 0;            //不检测MimeType
26
-    const INSERT_ONLY_TRUE = 1;            //文件上传不可覆盖
27
-    const INSERT_ONLY_NONE = 0;            //文件上传可覆盖
24
+	const DETECT_MIME_TRUE = 1;            //检测MimeType
25
+	const DETECT_MIME_NONE = 0;            //不检测MimeType
26
+	const INSERT_ONLY_TRUE = 1;            //文件上传不可覆盖
27
+	const INSERT_ONLY_NONE = 0;            //文件上传可覆盖
28 28
 
29
-    const MIN_OBJ_SIZE = 102400;        //1024*100;
30
-    const HTTP_TIMEOUT = 30;            //http的超时时间:30s
31
-    const HTTP_RETRY = 1;                //http失败后重试:1
29
+	const MIN_OBJ_SIZE = 102400;        //1024*100;
30
+	const HTTP_TIMEOUT = 30;            //http的超时时间:30s
31
+	const HTTP_RETRY = 1;                //http失败后重试:1
32 32
 
33
-    const BLOCK_MIN_SIZE = 102400;        //文件分片最小值:1024*100; 100K
34
-    const BLOCK_DEFF_SIZE = 2097152;    //文件分片默认值:1024*1024*2; 2M
35
-    const BLOCK_MAX_SIZE = 10485760;    //文件分片最大值:1024*1024*10; 10M
33
+	const BLOCK_MIN_SIZE = 102400;        //文件分片最小值:1024*100; 100K
34
+	const BLOCK_DEFF_SIZE = 2097152;    //文件分片默认值:1024*1024*2; 2M
35
+	const BLOCK_MAX_SIZE = 10485760;    //文件分片最大值:1024*1024*10; 10M
36 36
 
37
-    const CURL_ERR_LOG = "curl_error.log";    //curl请求时的错误日志信息
37
+	const CURL_ERR_LOG = "curl_error.log";    //curl请求时的错误日志信息
38 38
 
39
-    const RUN_LEVEL_RELEASE = 1;        //release级别
40
-    const RUN_LEVEL_DEBUG = 2;            //debug级别
39
+	const RUN_LEVEL_RELEASE = 1;        //release级别
40
+	const RUN_LEVEL_DEBUG = 2;            //debug级别
41 41
 }
Please login to merge, or discard this patch.
src/WantuFileServiceProvider.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -10,22 +10,22 @@
 block discarded – undo
10 10
 
11 11
 class WantuFileServiceProvider extends ServiceProvider
12 12
 {
13
-    public function boot()
14
-    {
15
-        app('filesystem')->extend('wantu', function ($app, $config) {
16
-            $adapter = new WantuFileAdapter(
17
-                $config['access_key'],
18
-                $config['secret_key'],
19
-                $config['namespace'],
20
-                $config['domain']
21
-            );
22
-            $flysystem = new Filesystem($adapter, new Config(['disable_asserts' => true]));
23
-            // $flysystem->addPlugin(new FetchFile());
24
-            $flysystem->addPlugin(new UploadToken());
25
-            $flysystem->addPlugin(new GetUrl());
26
-            // $flysystem->addPlugin(new PrivateDownloadUrl());
27
-            // $flysystem->addPlugin(new RefreshFile());
28
-            return $flysystem;
29
-        });
30
-    }
13
+	public function boot()
14
+	{
15
+		app('filesystem')->extend('wantu', function ($app, $config) {
16
+			$adapter = new WantuFileAdapter(
17
+				$config['access_key'],
18
+				$config['secret_key'],
19
+				$config['namespace'],
20
+				$config['domain']
21
+			);
22
+			$flysystem = new Filesystem($adapter, new Config(['disable_asserts' => true]));
23
+			// $flysystem->addPlugin(new FetchFile());
24
+			$flysystem->addPlugin(new UploadToken());
25
+			$flysystem->addPlugin(new GetUrl());
26
+			// $flysystem->addPlugin(new PrivateDownloadUrl());
27
+			// $flysystem->addPlugin(new RefreshFile());
28
+			return $flysystem;
29
+		});
30
+	}
31 31
 }
Please login to merge, or discard this patch.
src/Plugins/UploadToken.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -5,13 +5,13 @@
 block discarded – undo
5 5
 
6 6
 class UploadToken extends AbstractPlugin
7 7
 {
8
-    public function getMethod()
9
-    {
10
-        return 'getUploadToken';
11
-    }
8
+	public function getMethod()
9
+	{
10
+		return 'getUploadToken';
11
+	}
12 12
 
13
-    public function handle($option = null)
14
-    {
15
-        return $this->filesystem->getAdapter()->getUploadToken($option);
16
-    }
13
+	public function handle($option = null)
14
+	{
15
+		return $this->filesystem->getAdapter()->getUploadToken($option);
16
+	}
17 17
 }
Please login to merge, or discard this patch.
src/Plugins/GetUrl.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -5,12 +5,12 @@
 block discarded – undo
5 5
 
6 6
 class GetUrl extends AbstractPlugin
7 7
 {
8
-    public function getMethod()
9
-    {
10
-        return 'getUrl';
11
-    }
12
-    public function handle($path)
13
-    {
14
-        return $this->filesystem->getAdapter()->getUrl($path);
15
-    }
8
+	public function getMethod()
9
+	{
10
+		return 'getUrl';
11
+	}
12
+	public function handle($path)
13
+	{
14
+		return $this->filesystem->getAdapter()->getUrl($path);
15
+	}
16 16
 }
Please login to merge, or discard this patch.
src/WantuFileAdapter.php 1 patch
Indentation   +467 added lines, -467 removed lines patch added patch discarded remove patch
@@ -12,471 +12,471 @@
 block discarded – undo
12 12
 
13 13
 class WantuFileAdapter extends AbstractAdapter
14 14
 {
15
-    use NotSupportingVisibilityTrait;
16
-
17
-    /**
18
-     * @var Client|null
19
-     */
20
-    private $client = null;
21
-
22
-    /**
23
-     * @var string
24
-     */
25
-    private $namespace = null;
26
-
27
-    /**
28
-     * @var string
29
-     */
30
-    private $domain = null;
31
-
32
-    /**
33
-     * QiniuAdapter constructor.
34
-     *
35
-     * @param string $accessKey
36
-     * @param string $secretKey
37
-     * @param string $namespace
38
-     */
39
-    public function __construct($accessKey, $secretKey, $namespace, $origin)
40
-    {
41
-        $client = new Client($accessKey, $secretKey, $namespace);
42
-        $this->setClient($client, $namespace, $origin);
43
-    }
44
-
45
-    public function setClient(Client $client, $namespace, $origin)
46
-    {
47
-        $this->client = $client;
48
-        $this->namespace = $namespace;
49
-        $this->domain = $origin;
50
-    }
51
-
52
-    /**
53
-     * Write a new file.
54
-     *
55
-     * @param string $path
56
-     * @param string $contents
57
-     * @param Config $config   Config object
58
-     *
59
-     * @return array|false false on failure file meta data on success
60
-     */
61
-    public function write($path, $contents, Config $config)
62
-    {
63
-        $uploadPolicy = new UploadPolicy([
64
-            'namespace' => $this->namespace,
65
-            'dir' => preg_replace('/^\./', '', dirname($path)),
66
-            'name' => last(explode("/", $path)),
67
-        ]);
68
-
69
-        return $this->client->uploadData($contents, $uploadPolicy);
70
-    }
71
-
72
-    /**
73
-     * Write a new file using a stream.
74
-     *
75
-     * @param string   $path
76
-     * @param resource $resource
77
-     * @param Config   $config   Config object
78
-     *
79
-     * @return array|false false on failure file meta data on success
80
-     */
81
-    public function writeStream($path, $resource, Config $config)
82
-    {
83
-        $contents = '';
84
-
85
-        while (!feof($resource)) {
86
-            $contents .= fread($resource, 1024);
87
-        }
88
-
89
-        $response = $this->write($path, $contents, $config);
90
-
91
-        if (false === $response) {
92
-            return $response;
93
-        }
94
-
95
-        return compact('path');
96
-    }
97
-
98
-    /**
99
-     * Update a file.
100
-     *
101
-     * @param string $path
102
-     * @param string $contents
103
-     * @param Config $config   Config object
104
-     *
105
-     * @return array|false false on failure file meta data on success
106
-     */
107
-    public function update($path, $contents, Config $config)
108
-    {
109
-        $this->delete($path);
110
-
111
-        return $this->write($path, $contents, $config);
112
-    }
113
-
114
-    /**
115
-     * Update a file using a stream.
116
-     *
117
-     * @param string   $path
118
-     * @param resource $resource
119
-     * @param Config   $config   Config object
120
-     *
121
-     * @return array|false false on failure file meta data on success
122
-     */
123
-    public function updateStream($path, $resource, Config $config)
124
-    {
125
-        $this->delete($path);
126
-
127
-        return $this->writeStream($path, $resource, $config);
128
-    }
129
-
130
-    public function put($path, $contents, Config $config)
131
-    {
132
-        return $this->write($path, $contents, $config);
133
-    }
134
-
135
-    public function putStream($path, $resource, Config $config)
136
-    {
137
-        return $this->write($path, $resource, $config);
138
-    }
139
-
140
-    /**
141
-     * Rename a file.
142
-     *
143
-     * @param string $path
144
-     * @param string $newpath
145
-     *
146
-     * @return bool
147
-     */
148
-    public function rename($path, $newpath)
149
-    {
150
-        return $this->client->renameFile($this->namespace, preg_replace('/^\./', '', dirname($path)), last(explode("/", $path)), preg_replace('/^\./', '', dirname($newpath)), last(explode("/", $newpath)));
151
-    }
152
-
153
-    /**
154
-     * Copy a file.
155
-     *
156
-     * @param string $path
157
-     * @param string $newpath
158
-     *
159
-     * @return bool
160
-     */
161
-    public function copy($path, $newpath)
162
-    {
163
-    }
164
-
165
-    /**
166
-     * Delete a file.
167
-     *
168
-     * @param string $path
169
-     *
170
-     * @return bool
171
-     */
172
-    public function delete($path)
173
-    {
174
-        return $this->client->deleteFile($this->namespace, preg_replace('/^\./', '', dirname($path)), last(explode("/", $path)));
175
-    }
176
-
177
-    /**
178
-     * Delete a directory.
179
-     *
180
-     * @param string $dirname
181
-     *
182
-     * @return bool
183
-     */
184
-    public function deleteDir($dirname)
185
-    {
186
-        return $this->client->deleteDir($this->namespace, $dirname);
187
-    }
188
-
189
-    /**
190
-     * Create a directory.
191
-     *
192
-     * @param string $dirname directory name
193
-     * @param Config $config
194
-     *
195
-     * @return array|false
196
-     */
197
-    public function createDir($dirname, Config $config)
198
-    {
199
-        return $this->client->createDir($this->namespace, $dirname);
200
-    }
201
-
202
-    /**
203
-     * Check whether a file exists.
204
-     *
205
-     * @param string $path
206
-     *
207
-     * @return array|bool|null
208
-     */
209
-    public function has($path)
210
-    {
211
-        if (Str::endsWith($path, "/")) {
212
-            return $this->client->existsFolder($this->namespace,  preg_replace('/^\./' , '', dirname( $path)));
213
-        } else {
214
-            return $this->client->existsFile($this->namespace, preg_replace('/^\./', '', dirname($path)), last(explode("/", $path)));
215
-        }
216
-    }
217
-
218
-
219
-    /**
220
-     * Read a file.
221
-     *
222
-     * @param string $path
223
-     *
224
-     * @return array|false
225
-     */
226
-    public function read($path)
227
-    {
228
-        $contents = file_get_contents($this->getUrl($path));
229
-        return compact('contents', 'path');
230
-    }
231
-
232
-    /**
233
-     * Read a file as a stream.
234
-     *
235
-     * @param string $path
236
-     *
237
-     * @return array|false
238
-     */
239
-    public function readStream($path)
240
-    {
241
-    }
242
-
243
-    /**
244
-     * List contents of a directory.
245
-     *
246
-     * @param string $directory
247
-     * @param bool   $recursive
248
-     *
249
-     * @return array
250
-     */
251
-    public function listContents($directory = '', $recursive = false)
252
-    {
253
-        return $this->client->listFiles($this->namespace, $directory, 1, 1000);
254
-    }
255
-
256
-    /**
257
-     * Get all the meta data of a file or directory.
258
-     *
259
-     * @param string $path
260
-     *
261
-     * @return array|false
262
-     */
263
-    public function getMetadata($path)
264
-    {
265
-        return $this->client->getFileInfo($this->namespace, preg_replace('/^\./', '', dirname($path)), last(explode("/", $path)));
266
-    }
267
-
268
-    /**
269
-     * Get the size of a file.
270
-     *
271
-     * @param string $path
272
-     *
273
-     * @return array|false
274
-     */
275
-    public function getSize($path)
276
-    {
277
-    }
278
-
279
-
280
-    /**
281
-     * Fetch url to bucket.
282
-     *
283
-     * @param string $path
284
-     * @param string $url
285
-     *
286
-     * @return array|false
287
-     */
288
-    public function fetch($path, $url)
289
-    {
290
-    }
291
-
292
-    /**
293
-     * Get private file download url.
294
-     *
295
-     * @param string $path
296
-     * @param int    $expires
297
-     *
298
-     * @return string
299
-     */
300
-    public function privateDownloadUrl($path, $expires = 3600)
301
-    {
302
-    }
303
-
304
-    /**
305
-     * Refresh file cache.
306
-     *
307
-     * @param string|array $path
308
-     *
309
-     * @return array
310
-     */
311
-    public function refresh($path)
312
-    {
313
-    }
314
-
315
-
316
-    /**
317
-     * Get the mime-type of a file.
318
-     *
319
-     * @param string $path
320
-     *
321
-     * @return array|false
322
-     */
323
-    public function getMimeType($path)
324
-    {
325
-    }
326
-
327
-
328
-    /**
329
-     * Get the timestamp of a file.
330
-     *
331
-     * @param string $path
332
-     *
333
-     * @return array|false
334
-     */
335
-    public function getTimestamp($path)
336
-    {
337
-    }
338
-
339
-
340
-    /**
341
-     * @param \Qiniu\Storage\BucketManager $manager
342
-     *
343
-     * @return $this
344
-     */
345
-    public function setBucketManager(BucketManager $manager)
346
-    {
347
-    }
348
-
349
-
350
-    /**
351
-     * @param \Qiniu\Storage\UploadManager $manager
352
-     *
353
-     * @return $this
354
-     */
355
-    public function setUploadManager(UploadManager $manager)
356
-    {
357
-    }
358
-
359
-
360
-    /**
361
-     * @param \Qiniu\Auth $manager
362
-     *
363
-     * @return $this
364
-     */
365
-    public function setAuthManager(Auth $manager)
366
-    {
367
-    }
368
-
369
-    /**
370
-     * @param CdnManager $manager
371
-     *
372
-     * @return $this
373
-     */
374
-    public function setCdnManager(CdnManager $manager)
375
-    {
376
-    }
377
-
378
-
379
-    /**
380
-     * @return \Qiniu\Storage\BucketManager
381
-     */
382
-    public function getBucketManager()
383
-    {
384
-        return $this->bucketManager ?: $this->bucketManager = new BucketManager($this->getAuthManager());
385
-    }
386
-
387
-    /**
388
-     * @return \Qiniu\Auth
389
-     */
390
-    public function getAuthManager()
391
-    {
392
-        return $this->authManager ?: $this->authManager = new Auth($this->accessKey, $this->secretKey);
393
-    }
394
-
395
-    /**
396
-     * @return \Qiniu\Storage\UploadManager
397
-     */
398
-    public function getUploadManager()
399
-    {
400
-        return $this->uploadManager ?: $this->uploadManager = new UploadManager();
401
-    }
402
-
403
-    /**
404
-     * @return \Qiniu\Cdn\CdnManager
405
-     */
406
-    public function getCdnManager()
407
-    {
408
-        return $this->cdnManager ?: $this->cdnManager = new CdnManager($this->getAuthManager());
409
-    }
410
-
411
-    /**
412
-     * @return string
413
-     */
414
-    public function getBucket()
415
-    {
416
-        return $this->bucket;
417
-    }
418
-
419
-    /**
420
-     * Get the upload token.
421
-     *
422
-     * @param string|null $key
423
-     * @param int         $ttl
424
-     * @param string|null $policy
425
-     * @param string|null $strictPolice
426
-     *
427
-     * @return string
428
-     */
429
-    public function getUploadToken($option = null)
430
-    {
431
-        if ($option === null) {
432
-            $option = ['name' => null, 'ttl' => 3600, ];
433
-        } else if (!isset($option['ttl']) || !$option['ttl']) {
434
-            $option['ttl'] = 3600;
435
-        }
436
-
437
-        return $this->client->getUploadToken(collect([
438
-            'expiration' => Carbon::now()->addSeconds($option['ttl'])->timestamp * 1000,
439
-            'insertOnly' => Conf::INSERT_ONLY_TRUE
440
-        ])->merge(collect($option)->except(['ttl',])));
441
-    }
442
-
443
-    /**
444
-     * @param array $stats
445
-     *
446
-     * @return array
447
-     */
448
-    protected function normalizeFileInfo(array $stats)
449
-    {
450
-        return [
451
-            'type' => 'file',
452
-            'path' => $stats['key'],
453
-            'timestamp' => floor($stats['putTime'] / 10000000),
454
-            'size' => $stats['fsize'],
455
-        ];
456
-    }
457
-
458
-    /**
459
-     * Get resource url.
460
-     *
461
-     * @param string $path
462
-     *
463
-     * @return string
464
-     */
465
-    public function getUrl($path)
466
-    {
467
-        return $this->normalizeHost($this->domain) . ltrim($path, '/');
468
-    }
469
-
470
-    /**
471
-     * @param string $domain
472
-     *
473
-     * @return string
474
-     */
475
-    protected function normalizeHost($domain)
476
-    {
477
-        if (0 !== stripos($domain, 'https://') && 0 !== stripos($domain, 'http://')) {
478
-            $domain = "http://{$domain}";
479
-        }
480
-        return rtrim($domain, '/') . '/';
481
-    }
15
+	use NotSupportingVisibilityTrait;
16
+
17
+	/**
18
+	 * @var Client|null
19
+	 */
20
+	private $client = null;
21
+
22
+	/**
23
+	 * @var string
24
+	 */
25
+	private $namespace = null;
26
+
27
+	/**
28
+	 * @var string
29
+	 */
30
+	private $domain = null;
31
+
32
+	/**
33
+	 * QiniuAdapter constructor.
34
+	 *
35
+	 * @param string $accessKey
36
+	 * @param string $secretKey
37
+	 * @param string $namespace
38
+	 */
39
+	public function __construct($accessKey, $secretKey, $namespace, $origin)
40
+	{
41
+		$client = new Client($accessKey, $secretKey, $namespace);
42
+		$this->setClient($client, $namespace, $origin);
43
+	}
44
+
45
+	public function setClient(Client $client, $namespace, $origin)
46
+	{
47
+		$this->client = $client;
48
+		$this->namespace = $namespace;
49
+		$this->domain = $origin;
50
+	}
51
+
52
+	/**
53
+	 * Write a new file.
54
+	 *
55
+	 * @param string $path
56
+	 * @param string $contents
57
+	 * @param Config $config   Config object
58
+	 *
59
+	 * @return array|false false on failure file meta data on success
60
+	 */
61
+	public function write($path, $contents, Config $config)
62
+	{
63
+		$uploadPolicy = new UploadPolicy([
64
+			'namespace' => $this->namespace,
65
+			'dir' => preg_replace('/^\./', '', dirname($path)),
66
+			'name' => last(explode("/", $path)),
67
+		]);
68
+
69
+		return $this->client->uploadData($contents, $uploadPolicy);
70
+	}
71
+
72
+	/**
73
+	 * Write a new file using a stream.
74
+	 *
75
+	 * @param string   $path
76
+	 * @param resource $resource
77
+	 * @param Config   $config   Config object
78
+	 *
79
+	 * @return array|false false on failure file meta data on success
80
+	 */
81
+	public function writeStream($path, $resource, Config $config)
82
+	{
83
+		$contents = '';
84
+
85
+		while (!feof($resource)) {
86
+			$contents .= fread($resource, 1024);
87
+		}
88
+
89
+		$response = $this->write($path, $contents, $config);
90
+
91
+		if (false === $response) {
92
+			return $response;
93
+		}
94
+
95
+		return compact('path');
96
+	}
97
+
98
+	/**
99
+	 * Update a file.
100
+	 *
101
+	 * @param string $path
102
+	 * @param string $contents
103
+	 * @param Config $config   Config object
104
+	 *
105
+	 * @return array|false false on failure file meta data on success
106
+	 */
107
+	public function update($path, $contents, Config $config)
108
+	{
109
+		$this->delete($path);
110
+
111
+		return $this->write($path, $contents, $config);
112
+	}
113
+
114
+	/**
115
+	 * Update a file using a stream.
116
+	 *
117
+	 * @param string   $path
118
+	 * @param resource $resource
119
+	 * @param Config   $config   Config object
120
+	 *
121
+	 * @return array|false false on failure file meta data on success
122
+	 */
123
+	public function updateStream($path, $resource, Config $config)
124
+	{
125
+		$this->delete($path);
126
+
127
+		return $this->writeStream($path, $resource, $config);
128
+	}
129
+
130
+	public function put($path, $contents, Config $config)
131
+	{
132
+		return $this->write($path, $contents, $config);
133
+	}
134
+
135
+	public function putStream($path, $resource, Config $config)
136
+	{
137
+		return $this->write($path, $resource, $config);
138
+	}
139
+
140
+	/**
141
+	 * Rename a file.
142
+	 *
143
+	 * @param string $path
144
+	 * @param string $newpath
145
+	 *
146
+	 * @return bool
147
+	 */
148
+	public function rename($path, $newpath)
149
+	{
150
+		return $this->client->renameFile($this->namespace, preg_replace('/^\./', '', dirname($path)), last(explode("/", $path)), preg_replace('/^\./', '', dirname($newpath)), last(explode("/", $newpath)));
151
+	}
152
+
153
+	/**
154
+	 * Copy a file.
155
+	 *
156
+	 * @param string $path
157
+	 * @param string $newpath
158
+	 *
159
+	 * @return bool
160
+	 */
161
+	public function copy($path, $newpath)
162
+	{
163
+	}
164
+
165
+	/**
166
+	 * Delete a file.
167
+	 *
168
+	 * @param string $path
169
+	 *
170
+	 * @return bool
171
+	 */
172
+	public function delete($path)
173
+	{
174
+		return $this->client->deleteFile($this->namespace, preg_replace('/^\./', '', dirname($path)), last(explode("/", $path)));
175
+	}
176
+
177
+	/**
178
+	 * Delete a directory.
179
+	 *
180
+	 * @param string $dirname
181
+	 *
182
+	 * @return bool
183
+	 */
184
+	public function deleteDir($dirname)
185
+	{
186
+		return $this->client->deleteDir($this->namespace, $dirname);
187
+	}
188
+
189
+	/**
190
+	 * Create a directory.
191
+	 *
192
+	 * @param string $dirname directory name
193
+	 * @param Config $config
194
+	 *
195
+	 * @return array|false
196
+	 */
197
+	public function createDir($dirname, Config $config)
198
+	{
199
+		return $this->client->createDir($this->namespace, $dirname);
200
+	}
201
+
202
+	/**
203
+	 * Check whether a file exists.
204
+	 *
205
+	 * @param string $path
206
+	 *
207
+	 * @return array|bool|null
208
+	 */
209
+	public function has($path)
210
+	{
211
+		if (Str::endsWith($path, "/")) {
212
+			return $this->client->existsFolder($this->namespace,  preg_replace('/^\./' , '', dirname( $path)));
213
+		} else {
214
+			return $this->client->existsFile($this->namespace, preg_replace('/^\./', '', dirname($path)), last(explode("/", $path)));
215
+		}
216
+	}
217
+
218
+
219
+	/**
220
+	 * Read a file.
221
+	 *
222
+	 * @param string $path
223
+	 *
224
+	 * @return array|false
225
+	 */
226
+	public function read($path)
227
+	{
228
+		$contents = file_get_contents($this->getUrl($path));
229
+		return compact('contents', 'path');
230
+	}
231
+
232
+	/**
233
+	 * Read a file as a stream.
234
+	 *
235
+	 * @param string $path
236
+	 *
237
+	 * @return array|false
238
+	 */
239
+	public function readStream($path)
240
+	{
241
+	}
242
+
243
+	/**
244
+	 * List contents of a directory.
245
+	 *
246
+	 * @param string $directory
247
+	 * @param bool   $recursive
248
+	 *
249
+	 * @return array
250
+	 */
251
+	public function listContents($directory = '', $recursive = false)
252
+	{
253
+		return $this->client->listFiles($this->namespace, $directory, 1, 1000);
254
+	}
255
+
256
+	/**
257
+	 * Get all the meta data of a file or directory.
258
+	 *
259
+	 * @param string $path
260
+	 *
261
+	 * @return array|false
262
+	 */
263
+	public function getMetadata($path)
264
+	{
265
+		return $this->client->getFileInfo($this->namespace, preg_replace('/^\./', '', dirname($path)), last(explode("/", $path)));
266
+	}
267
+
268
+	/**
269
+	 * Get the size of a file.
270
+	 *
271
+	 * @param string $path
272
+	 *
273
+	 * @return array|false
274
+	 */
275
+	public function getSize($path)
276
+	{
277
+	}
278
+
279
+
280
+	/**
281
+	 * Fetch url to bucket.
282
+	 *
283
+	 * @param string $path
284
+	 * @param string $url
285
+	 *
286
+	 * @return array|false
287
+	 */
288
+	public function fetch($path, $url)
289
+	{
290
+	}
291
+
292
+	/**
293
+	 * Get private file download url.
294
+	 *
295
+	 * @param string $path
296
+	 * @param int    $expires
297
+	 *
298
+	 * @return string
299
+	 */
300
+	public function privateDownloadUrl($path, $expires = 3600)
301
+	{
302
+	}
303
+
304
+	/**
305
+	 * Refresh file cache.
306
+	 *
307
+	 * @param string|array $path
308
+	 *
309
+	 * @return array
310
+	 */
311
+	public function refresh($path)
312
+	{
313
+	}
314
+
315
+
316
+	/**
317
+	 * Get the mime-type of a file.
318
+	 *
319
+	 * @param string $path
320
+	 *
321
+	 * @return array|false
322
+	 */
323
+	public function getMimeType($path)
324
+	{
325
+	}
326
+
327
+
328
+	/**
329
+	 * Get the timestamp of a file.
330
+	 *
331
+	 * @param string $path
332
+	 *
333
+	 * @return array|false
334
+	 */
335
+	public function getTimestamp($path)
336
+	{
337
+	}
338
+
339
+
340
+	/**
341
+	 * @param \Qiniu\Storage\BucketManager $manager
342
+	 *
343
+	 * @return $this
344
+	 */
345
+	public function setBucketManager(BucketManager $manager)
346
+	{
347
+	}
348
+
349
+
350
+	/**
351
+	 * @param \Qiniu\Storage\UploadManager $manager
352
+	 *
353
+	 * @return $this
354
+	 */
355
+	public function setUploadManager(UploadManager $manager)
356
+	{
357
+	}
358
+
359
+
360
+	/**
361
+	 * @param \Qiniu\Auth $manager
362
+	 *
363
+	 * @return $this
364
+	 */
365
+	public function setAuthManager(Auth $manager)
366
+	{
367
+	}
368
+
369
+	/**
370
+	 * @param CdnManager $manager
371
+	 *
372
+	 * @return $this
373
+	 */
374
+	public function setCdnManager(CdnManager $manager)
375
+	{
376
+	}
377
+
378
+
379
+	/**
380
+	 * @return \Qiniu\Storage\BucketManager
381
+	 */
382
+	public function getBucketManager()
383
+	{
384
+		return $this->bucketManager ?: $this->bucketManager = new BucketManager($this->getAuthManager());
385
+	}
386
+
387
+	/**
388
+	 * @return \Qiniu\Auth
389
+	 */
390
+	public function getAuthManager()
391
+	{
392
+		return $this->authManager ?: $this->authManager = new Auth($this->accessKey, $this->secretKey);
393
+	}
394
+
395
+	/**
396
+	 * @return \Qiniu\Storage\UploadManager
397
+	 */
398
+	public function getUploadManager()
399
+	{
400
+		return $this->uploadManager ?: $this->uploadManager = new UploadManager();
401
+	}
402
+
403
+	/**
404
+	 * @return \Qiniu\Cdn\CdnManager
405
+	 */
406
+	public function getCdnManager()
407
+	{
408
+		return $this->cdnManager ?: $this->cdnManager = new CdnManager($this->getAuthManager());
409
+	}
410
+
411
+	/**
412
+	 * @return string
413
+	 */
414
+	public function getBucket()
415
+	{
416
+		return $this->bucket;
417
+	}
418
+
419
+	/**
420
+	 * Get the upload token.
421
+	 *
422
+	 * @param string|null $key
423
+	 * @param int         $ttl
424
+	 * @param string|null $policy
425
+	 * @param string|null $strictPolice
426
+	 *
427
+	 * @return string
428
+	 */
429
+	public function getUploadToken($option = null)
430
+	{
431
+		if ($option === null) {
432
+			$option = ['name' => null, 'ttl' => 3600, ];
433
+		} else if (!isset($option['ttl']) || !$option['ttl']) {
434
+			$option['ttl'] = 3600;
435
+		}
436
+
437
+		return $this->client->getUploadToken(collect([
438
+			'expiration' => Carbon::now()->addSeconds($option['ttl'])->timestamp * 1000,
439
+			'insertOnly' => Conf::INSERT_ONLY_TRUE
440
+		])->merge(collect($option)->except(['ttl',])));
441
+	}
442
+
443
+	/**
444
+	 * @param array $stats
445
+	 *
446
+	 * @return array
447
+	 */
448
+	protected function normalizeFileInfo(array $stats)
449
+	{
450
+		return [
451
+			'type' => 'file',
452
+			'path' => $stats['key'],
453
+			'timestamp' => floor($stats['putTime'] / 10000000),
454
+			'size' => $stats['fsize'],
455
+		];
456
+	}
457
+
458
+	/**
459
+	 * Get resource url.
460
+	 *
461
+	 * @param string $path
462
+	 *
463
+	 * @return string
464
+	 */
465
+	public function getUrl($path)
466
+	{
467
+		return $this->normalizeHost($this->domain) . ltrim($path, '/');
468
+	}
469
+
470
+	/**
471
+	 * @param string $domain
472
+	 *
473
+	 * @return string
474
+	 */
475
+	protected function normalizeHost($domain)
476
+	{
477
+		if (0 !== stripos($domain, 'https://') && 0 !== stripos($domain, 'http://')) {
478
+			$domain = "http://{$domain}";
479
+		}
480
+		return rtrim($domain, '/') . '/';
481
+	}
482 482
 }
Please login to merge, or discard this patch.