Passed
Push — master ( 103d2b...e57950 )
by xiaohui
02:15
created
src/WantuFileServiceProvider.php 2 patches
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.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@
 block discarded – undo
12 12
 {
13 13
     public function boot()
14 14
     {
15
-        app('filesystem')->extend('wantu', function ($app, $config) {
15
+        app('filesystem')->extend('wantu', function($app, $config) {
16 16
             $adapter = new WantuFileAdapter(
17 17
                 $config['access_key'],
18 18
                 $config['secret_key'],
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 2 patches
Indentation   +385 added lines, -385 removed lines patch added patch discarded remove patch
@@ -12,389 +12,389 @@
 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
-     * @param string $accessKey
34
-     * @param string $secretKey
35
-     * @param string $namespace
36
-     */
37
-    public function __construct($accessKey, $secretKey, $namespace, $origin)
38
-    {
39
-        $client = new Client($accessKey, $secretKey, $namespace);
40
-        $this->setClient($client, $namespace, $origin);
41
-    }
42
-
43
-    public function setClient(Client $client, $namespace, $origin)
44
-    {
45
-        $this->client = $client;
46
-        $this->namespace = $namespace;
47
-        $this->domain = $origin;
48
-    }
49
-
50
-    /**
51
-     * Write a new file.
52
-     *
53
-     * @param string $path
54
-     * @param string $contents
55
-     * @param Config $config   Config object
56
-     *
57
-     * @return array|false false on failure file meta data on success
58
-     */
59
-    public function write($path, $contents, Config $config)
60
-    {
61
-        $uploadPolicy = new UploadPolicy([
62
-            'namespace' => $this->namespace,
63
-            'dir' => preg_replace('/^\./', '', dirname($path)),
64
-            'name' => last(explode("/", $path)),
65
-        ]);
66
-
67
-        return $this->client->uploadData($contents, $uploadPolicy);
68
-    }
69
-
70
-    /**
71
-     * Write a new file using a stream.
72
-     *
73
-     * @param string   $path
74
-     * @param resource $resource
75
-     * @param Config   $config   Config object
76
-     *
77
-     * @return array|false false on failure file meta data on success
78
-     */
79
-    public function writeStream($path, $resource, Config $config)
80
-    {
81
-        $contents = '';
82
-
83
-        while (!feof($resource)) {
84
-            $contents .= fread($resource, 1024);
85
-        }
86
-
87
-        $response = $this->write($path, $contents, $config);
88
-
89
-        if (false === $response) {
90
-            return $response;
91
-        }
92
-
93
-        return compact('path');
94
-    }
95
-
96
-    /**
97
-     * Update a file.
98
-     *
99
-     * @param string $path
100
-     * @param string $contents
101
-     * @param Config $config   Config object
102
-     *
103
-     * @return array|false false on failure file meta data on success
104
-     */
105
-    public function update($path, $contents, Config $config)
106
-    {
107
-        $this->delete($path);
108
-
109
-        return $this->write($path, $contents, $config);
110
-    }
111
-
112
-    /**
113
-     * Update a file using a stream.
114
-     *
115
-     * @param string   $path
116
-     * @param resource $resource
117
-     * @param Config   $config   Config object
118
-     *
119
-     * @return array|false false on failure file meta data on success
120
-     */
121
-    public function updateStream($path, $resource, Config $config)
122
-    {
123
-        $this->delete($path);
124
-
125
-        return $this->writeStream($path, $resource, $config);
126
-    }
127
-
128
-    public function put($path, $contents, Config $config)
129
-    {
130
-        return $this->write($path, $contents, $config);
131
-    }
132
-
133
-    public function putStream($path, $resource, Config $config)
134
-    {
135
-        return $this->write($path, $resource, $config);
136
-    }
137
-
138
-    /**
139
-     * Rename a file.
140
-     *
141
-     * @param string $path
142
-     * @param string $newpath
143
-     *
144
-     * @return bool
145
-     */
146
-    public function rename($path, $newpath)
147
-    {
148
-        return $this->client->renameFile($this->namespace, preg_replace('/^\./', '', dirname($path)), last(explode("/", $path)), preg_replace('/^\./', '', dirname($newpath)), last(explode("/", $newpath)));
149
-    }
150
-
151
-    /**
152
-     * Copy a file.
153
-     *
154
-     * @param string $path
155
-     * @param string $newpath
156
-     *
157
-     * @return bool
158
-     */
159
-    public function copy($path, $newpath)
160
-    {
161
-    }
162
-
163
-    /**
164
-     * Delete a file.
165
-     *
166
-     * @param string $path
167
-     *
168
-     * @return bool
169
-     */
170
-    public function delete($path)
171
-    {
172
-        return $this->client->deleteFile($this->namespace, preg_replace('/^\./', '', dirname($path)), last(explode("/", $path)));
173
-    }
174
-
175
-    /**
176
-     * Delete a directory.
177
-     *
178
-     * @param string $dirname
179
-     *
180
-     * @return bool
181
-     */
182
-    public function deleteDir($dirname)
183
-    {
184
-        return $this->client->deleteDir($this->namespace, $dirname);
185
-    }
186
-
187
-    /**
188
-     * Create a directory.
189
-     *
190
-     * @param string $dirname directory name
191
-     * @param Config $config
192
-     *
193
-     * @return array|false
194
-     */
195
-    public function createDir($dirname, Config $config)
196
-    {
197
-        return $this->client->createDir($this->namespace, $dirname);
198
-    }
199
-
200
-    /**
201
-     * Check whether a file exists.
202
-     *
203
-     * @param string $path
204
-     *
205
-     * @return array|bool|null
206
-     */
207
-    public function has($path)
208
-    {
209
-        if (Str::endsWith($path, "/")) {
210
-            return $this->client->existsFolder($this->namespace, preg_replace('/^\./', '', dirname($path)));
211
-        } else {
212
-            return $this->client->existsFile($this->namespace, preg_replace('/^\./', '', dirname($path)), last(explode("/", $path)));
213
-        }
214
-    }
215
-
216
-
217
-    /**
218
-     * Read a file.
219
-     *
220
-     * @param string $path
221
-     *
222
-     * @return array|false
223
-     */
224
-    public function read($path)
225
-    {
226
-        $contents = file_get_contents($this->getUrl($path));
227
-        return compact('contents', 'path');
228
-    }
229
-
230
-    /**
231
-     * Read a file as a stream.
232
-     *
233
-     * @param string $path
234
-     *
235
-     * @return array|false
236
-     */
237
-    public function readStream($path)
238
-    {
239
-    }
240
-
241
-    /**
242
-     * List contents of a directory.
243
-     *
244
-     * @param string $directory
245
-     * @param bool   $recursive
246
-     *
247
-     * @return array
248
-     */
249
-    public function listContents($directory = '', $recursive = false)
250
-    {
251
-        return $this->client->listFiles($this->namespace, $directory, 1, 1000);
252
-    }
253
-
254
-    /**
255
-     * Get all the meta data of a file or directory.
256
-     *
257
-     * @param string $path
258
-     *
259
-     * @return array|false
260
-     */
261
-    public function getMetadata($path)
262
-    {
263
-        return $this->client->getFileInfo($this->namespace, preg_replace('/^\./', '', dirname($path)), last(explode("/", $path)));
264
-    }
265
-
266
-    /**
267
-     * Get the size of a file.
268
-     *
269
-     * @param string $path
270
-     *
271
-     * @return array|false
272
-     */
273
-    public function getSize($path)
274
-    {
275
-    }
276
-
277
-
278
-    /**
279
-     * Fetch url to bucket.
280
-     *
281
-     * @param string $path
282
-     * @param string $url
283
-     *
284
-     * @return array|false
285
-     */
286
-    public function fetch($path, $url)
287
-    {
288
-    }
289
-
290
-    /**
291
-     * Get private file download url.
292
-     *
293
-     * @param string $path
294
-     * @param int    $expires
295
-     *
296
-     * @return string
297
-     */
298
-    public function privateDownloadUrl($path, $expires = 3600)
299
-    {
300
-    }
301
-
302
-    /**
303
-     * Refresh file cache.
304
-     *
305
-     * @param string|array $path
306
-     *
307
-     * @return array
308
-     */
309
-    public function refresh($path)
310
-    {
311
-    }
312
-
313
-
314
-    /**
315
-     * Get the mime-type of a file.
316
-     *
317
-     * @param string $path
318
-     *
319
-     * @return array|false
320
-     */
321
-    public function getMimeType($path)
322
-    {
323
-    }
324
-
325
-
326
-    /**
327
-     * Get the timestamp of a file.
328
-     *
329
-     * @param string $path
330
-     *
331
-     * @return array|false
332
-     */
333
-    public function getTimestamp($path)
334
-    {
335
-    }
336
-
337
-    /**
338
-     * Get the upload token.
339
-     *
340
-     * @param string|null $key
341
-     * @param int         $ttl
342
-     * @param string|null $policy
343
-     * @param string|null $strictPolice
344
-     *
345
-     * @return string
346
-     */
347
-    public function getUploadToken($option = null)
348
-    {
349
-        if ($option === null) {
350
-            $option = ['name' => null, 'ttl' => 3600, ];
351
-        } elseif (!isset($option['ttl']) || !$option['ttl']) {
352
-            $option['ttl'] = 3600;
353
-        }
354
-
355
-        return $this->client->getUploadToken(collect([
356
-            'expiration' => Carbon::now()->addSeconds($option['ttl'])->timestamp * 1000,
357
-            'insertOnly' => Conf::INSERT_ONLY_TRUE
358
-        ])->merge(collect($option)->except(['ttl',])));
359
-    }
360
-
361
-    /**
362
-     * @param array $stats
363
-     *
364
-     * @return array
365
-     */
366
-    protected function normalizeFileInfo(array $stats)
367
-    {
368
-        return [
369
-            'type' => 'file',
370
-            'path' => $stats['key'],
371
-            'timestamp' => floor($stats['putTime'] / 10000000),
372
-            'size' => $stats['fsize'],
373
-        ];
374
-    }
375
-
376
-    /**
377
-     * Get resource url.
378
-     *
379
-     * @param string $path
380
-     *
381
-     * @return string
382
-     */
383
-    public function getUrl($path)
384
-    {
385
-        return $this->normalizeHost($this->domain) . ltrim($path, '/');
386
-    }
387
-
388
-    /**
389
-     * @param string $domain
390
-     *
391
-     * @return string
392
-     */
393
-    protected function normalizeHost($domain)
394
-    {
395
-        if (0 !== stripos($domain, 'https://') && 0 !== stripos($domain, 'http://')) {
396
-            $domain = "http://{$domain}";
397
-        }
398
-        return rtrim($domain, '/') . '/';
399
-    }
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
+	 * @param string $accessKey
34
+	 * @param string $secretKey
35
+	 * @param string $namespace
36
+	 */
37
+	public function __construct($accessKey, $secretKey, $namespace, $origin)
38
+	{
39
+		$client = new Client($accessKey, $secretKey, $namespace);
40
+		$this->setClient($client, $namespace, $origin);
41
+	}
42
+
43
+	public function setClient(Client $client, $namespace, $origin)
44
+	{
45
+		$this->client = $client;
46
+		$this->namespace = $namespace;
47
+		$this->domain = $origin;
48
+	}
49
+
50
+	/**
51
+	 * Write a new file.
52
+	 *
53
+	 * @param string $path
54
+	 * @param string $contents
55
+	 * @param Config $config   Config object
56
+	 *
57
+	 * @return array|false false on failure file meta data on success
58
+	 */
59
+	public function write($path, $contents, Config $config)
60
+	{
61
+		$uploadPolicy = new UploadPolicy([
62
+			'namespace' => $this->namespace,
63
+			'dir' => preg_replace('/^\./', '', dirname($path)),
64
+			'name' => last(explode("/", $path)),
65
+		]);
66
+
67
+		return $this->client->uploadData($contents, $uploadPolicy);
68
+	}
69
+
70
+	/**
71
+	 * Write a new file using a stream.
72
+	 *
73
+	 * @param string   $path
74
+	 * @param resource $resource
75
+	 * @param Config   $config   Config object
76
+	 *
77
+	 * @return array|false false on failure file meta data on success
78
+	 */
79
+	public function writeStream($path, $resource, Config $config)
80
+	{
81
+		$contents = '';
82
+
83
+		while (!feof($resource)) {
84
+			$contents .= fread($resource, 1024);
85
+		}
86
+
87
+		$response = $this->write($path, $contents, $config);
88
+
89
+		if (false === $response) {
90
+			return $response;
91
+		}
92
+
93
+		return compact('path');
94
+	}
95
+
96
+	/**
97
+	 * Update a file.
98
+	 *
99
+	 * @param string $path
100
+	 * @param string $contents
101
+	 * @param Config $config   Config object
102
+	 *
103
+	 * @return array|false false on failure file meta data on success
104
+	 */
105
+	public function update($path, $contents, Config $config)
106
+	{
107
+		$this->delete($path);
108
+
109
+		return $this->write($path, $contents, $config);
110
+	}
111
+
112
+	/**
113
+	 * Update a file using a stream.
114
+	 *
115
+	 * @param string   $path
116
+	 * @param resource $resource
117
+	 * @param Config   $config   Config object
118
+	 *
119
+	 * @return array|false false on failure file meta data on success
120
+	 */
121
+	public function updateStream($path, $resource, Config $config)
122
+	{
123
+		$this->delete($path);
124
+
125
+		return $this->writeStream($path, $resource, $config);
126
+	}
127
+
128
+	public function put($path, $contents, Config $config)
129
+	{
130
+		return $this->write($path, $contents, $config);
131
+	}
132
+
133
+	public function putStream($path, $resource, Config $config)
134
+	{
135
+		return $this->write($path, $resource, $config);
136
+	}
137
+
138
+	/**
139
+	 * Rename a file.
140
+	 *
141
+	 * @param string $path
142
+	 * @param string $newpath
143
+	 *
144
+	 * @return bool
145
+	 */
146
+	public function rename($path, $newpath)
147
+	{
148
+		return $this->client->renameFile($this->namespace, preg_replace('/^\./', '', dirname($path)), last(explode("/", $path)), preg_replace('/^\./', '', dirname($newpath)), last(explode("/", $newpath)));
149
+	}
150
+
151
+	/**
152
+	 * Copy a file.
153
+	 *
154
+	 * @param string $path
155
+	 * @param string $newpath
156
+	 *
157
+	 * @return bool
158
+	 */
159
+	public function copy($path, $newpath)
160
+	{
161
+	}
162
+
163
+	/**
164
+	 * Delete a file.
165
+	 *
166
+	 * @param string $path
167
+	 *
168
+	 * @return bool
169
+	 */
170
+	public function delete($path)
171
+	{
172
+		return $this->client->deleteFile($this->namespace, preg_replace('/^\./', '', dirname($path)), last(explode("/", $path)));
173
+	}
174
+
175
+	/**
176
+	 * Delete a directory.
177
+	 *
178
+	 * @param string $dirname
179
+	 *
180
+	 * @return bool
181
+	 */
182
+	public function deleteDir($dirname)
183
+	{
184
+		return $this->client->deleteDir($this->namespace, $dirname);
185
+	}
186
+
187
+	/**
188
+	 * Create a directory.
189
+	 *
190
+	 * @param string $dirname directory name
191
+	 * @param Config $config
192
+	 *
193
+	 * @return array|false
194
+	 */
195
+	public function createDir($dirname, Config $config)
196
+	{
197
+		return $this->client->createDir($this->namespace, $dirname);
198
+	}
199
+
200
+	/**
201
+	 * Check whether a file exists.
202
+	 *
203
+	 * @param string $path
204
+	 *
205
+	 * @return array|bool|null
206
+	 */
207
+	public function has($path)
208
+	{
209
+		if (Str::endsWith($path, "/")) {
210
+			return $this->client->existsFolder($this->namespace, preg_replace('/^\./', '', dirname($path)));
211
+		} else {
212
+			return $this->client->existsFile($this->namespace, preg_replace('/^\./', '', dirname($path)), last(explode("/", $path)));
213
+		}
214
+	}
215
+
216
+
217
+	/**
218
+	 * Read a file.
219
+	 *
220
+	 * @param string $path
221
+	 *
222
+	 * @return array|false
223
+	 */
224
+	public function read($path)
225
+	{
226
+		$contents = file_get_contents($this->getUrl($path));
227
+		return compact('contents', 'path');
228
+	}
229
+
230
+	/**
231
+	 * Read a file as a stream.
232
+	 *
233
+	 * @param string $path
234
+	 *
235
+	 * @return array|false
236
+	 */
237
+	public function readStream($path)
238
+	{
239
+	}
240
+
241
+	/**
242
+	 * List contents of a directory.
243
+	 *
244
+	 * @param string $directory
245
+	 * @param bool   $recursive
246
+	 *
247
+	 * @return array
248
+	 */
249
+	public function listContents($directory = '', $recursive = false)
250
+	{
251
+		return $this->client->listFiles($this->namespace, $directory, 1, 1000);
252
+	}
253
+
254
+	/**
255
+	 * Get all the meta data of a file or directory.
256
+	 *
257
+	 * @param string $path
258
+	 *
259
+	 * @return array|false
260
+	 */
261
+	public function getMetadata($path)
262
+	{
263
+		return $this->client->getFileInfo($this->namespace, preg_replace('/^\./', '', dirname($path)), last(explode("/", $path)));
264
+	}
265
+
266
+	/**
267
+	 * Get the size of a file.
268
+	 *
269
+	 * @param string $path
270
+	 *
271
+	 * @return array|false
272
+	 */
273
+	public function getSize($path)
274
+	{
275
+	}
276
+
277
+
278
+	/**
279
+	 * Fetch url to bucket.
280
+	 *
281
+	 * @param string $path
282
+	 * @param string $url
283
+	 *
284
+	 * @return array|false
285
+	 */
286
+	public function fetch($path, $url)
287
+	{
288
+	}
289
+
290
+	/**
291
+	 * Get private file download url.
292
+	 *
293
+	 * @param string $path
294
+	 * @param int    $expires
295
+	 *
296
+	 * @return string
297
+	 */
298
+	public function privateDownloadUrl($path, $expires = 3600)
299
+	{
300
+	}
301
+
302
+	/**
303
+	 * Refresh file cache.
304
+	 *
305
+	 * @param string|array $path
306
+	 *
307
+	 * @return array
308
+	 */
309
+	public function refresh($path)
310
+	{
311
+	}
312
+
313
+
314
+	/**
315
+	 * Get the mime-type of a file.
316
+	 *
317
+	 * @param string $path
318
+	 *
319
+	 * @return array|false
320
+	 */
321
+	public function getMimeType($path)
322
+	{
323
+	}
324
+
325
+
326
+	/**
327
+	 * Get the timestamp of a file.
328
+	 *
329
+	 * @param string $path
330
+	 *
331
+	 * @return array|false
332
+	 */
333
+	public function getTimestamp($path)
334
+	{
335
+	}
336
+
337
+	/**
338
+	 * Get the upload token.
339
+	 *
340
+	 * @param string|null $key
341
+	 * @param int         $ttl
342
+	 * @param string|null $policy
343
+	 * @param string|null $strictPolice
344
+	 *
345
+	 * @return string
346
+	 */
347
+	public function getUploadToken($option = null)
348
+	{
349
+		if ($option === null) {
350
+			$option = ['name' => null, 'ttl' => 3600, ];
351
+		} elseif (!isset($option['ttl']) || !$option['ttl']) {
352
+			$option['ttl'] = 3600;
353
+		}
354
+
355
+		return $this->client->getUploadToken(collect([
356
+			'expiration' => Carbon::now()->addSeconds($option['ttl'])->timestamp * 1000,
357
+			'insertOnly' => Conf::INSERT_ONLY_TRUE
358
+		])->merge(collect($option)->except(['ttl',])));
359
+	}
360
+
361
+	/**
362
+	 * @param array $stats
363
+	 *
364
+	 * @return array
365
+	 */
366
+	protected function normalizeFileInfo(array $stats)
367
+	{
368
+		return [
369
+			'type' => 'file',
370
+			'path' => $stats['key'],
371
+			'timestamp' => floor($stats['putTime'] / 10000000),
372
+			'size' => $stats['fsize'],
373
+		];
374
+	}
375
+
376
+	/**
377
+	 * Get resource url.
378
+	 *
379
+	 * @param string $path
380
+	 *
381
+	 * @return string
382
+	 */
383
+	public function getUrl($path)
384
+	{
385
+		return $this->normalizeHost($this->domain) . ltrim($path, '/');
386
+	}
387
+
388
+	/**
389
+	 * @param string $domain
390
+	 *
391
+	 * @return string
392
+	 */
393
+	protected function normalizeHost($domain)
394
+	{
395
+		if (0 !== stripos($domain, 'https://') && 0 !== stripos($domain, 'http://')) {
396
+			$domain = "http://{$domain}";
397
+		}
398
+		return rtrim($domain, '/') . '/';
399
+	}
400 400
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -355,7 +355,7 @@
 block discarded – undo
355 355
         return $this->client->getUploadToken(collect([
356 356
             'expiration' => Carbon::now()->addSeconds($option['ttl'])->timestamp * 1000,
357 357
             'insertOnly' => Conf::INSERT_ONLY_TRUE
358
-        ])->merge(collect($option)->except(['ttl',])));
358
+        ])->merge(collect($option)->except(['ttl', ])));
359 359
     }
360 360
 
361 361
     /**
Please login to merge, or discard this patch.
sdk/AlibabaImage.php 2 patches
Indentation   +234 added lines, -234 removed lines patch added patch discarded remove patch
@@ -12,238 +12,238 @@
 block discarded – undo
12 12
 
13 13
 class AlibabaImage
14 14
 {
15
-    private $upload_client;
16
-    private $manage_client;
17
-    private $ak;
18
-    private $sk;
19
-    private $namespace;
20
-    private $type; // "TOP"和"CLOUD"两种模式
21
-
22
-    static $RUN_LEVEL = Conf::RUN_LEVEL_RELEASE;    //设置SDK运行级别
23
-
24
-    /**
25
-     * 构造函数
26
-     *
27
-     * @param string $ak 云存储公钥
28
-     * @param string $sk 云存储私钥
29
-     * @param string $type 可选,兼容TOP与tea云的 ak/sk
30
-     * @throws \Exception
31
-     */
32
-    public function __construct($ak, $sk, $namespace, $type = Conf::TYPE_TOP)
33
-    {
34
-        $this->ak = $ak;
35
-        $this->sk = $sk;
36
-        $this->namespace = $namespace;
37
-        $this->type = $type;
38
-        $this->upload_client = new UploadClient($ak, $sk, $type);
39
-        $this->manage_client = new ManageClient($ak, $sk, $type);
40
-    }
41
-
42
-    public function getUploadToken($option)
43
-    {
44
-        if (!isset($option['name']) || !$option['name']) {
45
-            $option['name'] = '${uuid}.${ext}';
46
-        }
47
-        if ($option['name']) {
48
-            $option['dir'] = preg_replace('/^\./', '', dirname($option['name']));
49
-            $option['name'] = last(explode("/", $option['name']));
50
-        }
51
-        $option['namespace'] = $this->namespace;
52
-
53
-        $policy = new UploadPolicy($option);
54
-
55
-        return $this->upload_client->getUploadToken($policy);
56
-    }
57
-
58
-    /**
59
-     * 直接上传文件,适合文件比较小的情况
60
-     */
61
-    public function upload($filePath, UploadPolicy $uploadPolicy, UploadOption $uploadOption = null)
62
-    {
63
-        return $this->upload_client->upload($filePath, $uploadPolicy, $uploadOption);
64
-    }
65
-
66
-    /**
67
-     * 直接上传文件数据,适合数据量比较小的情况
68
-     */
69
-    public function uploadData($data, UploadPolicy $uploadPolicy, UploadOption $uploadOption = null)
70
-    {
71
-        return $this->upload_client->uploadData($data, $uploadPolicy, $uploadOption);
72
-    }
73
-
74
-    /**
75
-     * 创建分片上传任务,指定待上传的文件。即初始化分片上传
76
-     */
77
-    public function multipartInit($filePath, UploadPolicy $uploadPolicy, UploadOption $uploadOption)
78
-    {
79
-        return $this->upload_client->multipartInit($filePath, $uploadPolicy, $uploadOption);
80
-    }
81
-
82
-    /**
83
-     * 创建分片上传任务,指定初始化分片任务的数据,即第一块数据
84
-     */
85
-    public function multipartInitByData($data, UploadPolicy $uploadPolicy, UploadOption $uploadOption)
86
-    {
87
-        return $this->upload_client->multipartInitByData($data, $uploadPolicy, $uploadOption);
88
-    }
89
-
90
-    /**
91
-     * 分片上传,指定待上传的文件。需要指定UploadOption中文件块编号
92
-     */
93
-    public function multipartUpload($filePath, UploadPolicy $uploadPolicy, UploadOption $uploadOption)
94
-    {
95
-        return $this->upload_client->multipartUpload($filePath, $uploadPolicy, $uploadOption);
96
-    }
97
-
98
-    /**
99
-     * 分片上传,指定待上传的数据。需要指定UploadOption中文件块编号
100
-     */
101
-    public function multipartUploadByData($blockData, UploadPolicy $uploadPolicy, UploadOption $uploadOption)
102
-    {
103
-        return $this->upload_client->multipartUploadByData($blockData, $uploadPolicy, $uploadOption);
104
-    }
105
-
106
-    /**
107
-     * 完成分片上传任务。需要指定UploadOption中整个文件的md5值
108
-     */
109
-    public function multipartComplete(UploadPolicy $uploadPolicy, UploadOption $uploadOption)
110
-    {
111
-        return $this->upload_client->multipartComplete($uploadPolicy, $uploadOption);
112
-    }
113
-
114
-    /**
115
-     * 取消分片上传任务。需要保证UploadOption中有分片任务的uploadId和id
116
-     */
117
-    public function multipartCancel(UploadPolicy $uploadPolicy, UploadOption $uploadOption)
118
-    {
119
-        return $this->upload_client->multipartCancel($uploadPolicy, $uploadOption);
120
-    }
121
-
122
-    /**
123
-     * 查看文件是否存在
124
-     */
125
-    public function existsFile($namespace, $dir, $filename)
126
-    {
127
-        return $this->manage_client->existsFile($namespace, $dir, $filename);
128
-    }
129
-
130
-    /**
131
-     * 获取文件的元信息(meta信息)
132
-     */
133
-    public function getFileInfo($namespace, $dir, $filename)
134
-    {
135
-        return $this->manage_client->getFileInfo($namespace, $dir, $filename);
136
-    }
137
-
138
-    /**
139
-     * 重命名文件
140
-     */
141
-    public function renameFile($namespace, $dir, $filename, $newDir, $newName)
142
-    {
143
-        return $this->manage_client->renameFile($namespace, $dir, $filename, $newDir, $newName);
144
-    }
145
-
146
-    /**
147
-     * 获取指定目录下的文件列表。dir为空,表示根目录。page指定页数,pageSize指定每页显示数量
148
-     */
149
-    public function listFiles($namespace, $dir, $page = 1, $pageSize = 100)
150
-    {
151
-        return $this->manage_client->listFiles($namespace, $dir, $page, $pageSize);
152
-    }
153
-
154
-    /**
155
-     * 删除文件
156
-     */
157
-    public function deleteFile($namespace, $dir, $filename)
158
-    {
159
-        return $this->manage_client->deleteFile($namespace, $dir, $filename);
160
-    }
161
-
162
-    /**
163
-     * 查看文件夹是否存在
164
-     */
165
-    public function existsFolder($namespace, $dir)
166
-    {
167
-        return $this->manage_client->existsFolder($namespace, $dir);
168
-    }
169
-
170
-    /**
171
-     * 创建文件夹
172
-     */
173
-    public function createDir($namespace, $dir)
174
-    {
175
-        return $this->manage_client->createDir($namespace, $dir);
176
-    }
177
-
178
-    /**
179
-     * 获取子文件夹列表。dir为空,表示根目录。page指定页数,pageSize指定每页显示数量
180
-     */
181
-    public function listDirs($namespace, $dir, $page = 1, $pageSize = 100)
182
-    {
183
-        return $this->manage_client->listDirs($namespace, $dir, $page, $pageSize);
184
-    }
185
-
186
-    /**
187
-     * 删除文件夹
188
-     */
189
-    public function deleteDir($namespace, $dir)
190
-    {
191
-        return $this->manage_client->deleteDir($namespace, $dir);
192
-    }
193
-
194
-    /**
195
-     * 黄图扫描接口
196
-     */
197
-    public function scanPorn(ManageOption $resInfos)
198
-    {
199
-        return $this->manage_client->scanPorn($resInfos);
200
-    }
201
-
202
-    /**
203
-     * 鉴黄反馈feedback接口
204
-     */
205
-    public function pornFeedback(ManageOption $pornFbInfos)
206
-    {
207
-        return $this->manage_client->pornFeedback($pornFbInfos);
208
-    }
209
-
210
-    /**
211
-     * 多媒体转码接口
212
-     */
213
-    public function mediaEncode(MediaEncodeOption $encodeOption)
214
-    {
215
-        return $this->manage_client->mediaEncode($encodeOption);
216
-    }
217
-
218
-    /**
219
-     * 多媒体转码任务查询接口
220
-     */
221
-    public function mediaEncodeQuery($taskId)
222
-    {
223
-        return $this->manage_client->mediaEncodeQuery($taskId);
224
-    }
225
-
226
-    /**
227
-     * 视频截图接口
228
-     */
229
-    public function videoSnapshot(SnapShotOption $snapshotOption)
230
-    {
231
-        return $this->manage_client->videoSnapshot($snapshotOption);
232
-    }
233
-
234
-    /**
235
-     * 视频截图结果查询接口
236
-     */
237
-    public function vSnapshotQuery($taskId)
238
-    {
239
-        return $this->manage_client->vSnapshotQuery($taskId);
240
-    }
241
-
242
-    /**
243
-     * 广告图扫描接口(beta)
244
-     */
245
-    public function scanAdvertising(ManageOption $resInfos)
246
-    {
247
-        return $this->manage_client->scanAdvertising($resInfos);
248
-    }
15
+	private $upload_client;
16
+	private $manage_client;
17
+	private $ak;
18
+	private $sk;
19
+	private $namespace;
20
+	private $type; // "TOP"和"CLOUD"两种模式
21
+
22
+	static $RUN_LEVEL = Conf::RUN_LEVEL_RELEASE;    //设置SDK运行级别
23
+
24
+	/**
25
+	 * 构造函数
26
+	 *
27
+	 * @param string $ak 云存储公钥
28
+	 * @param string $sk 云存储私钥
29
+	 * @param string $type 可选,兼容TOP与tea云的 ak/sk
30
+	 * @throws \Exception
31
+	 */
32
+	public function __construct($ak, $sk, $namespace, $type = Conf::TYPE_TOP)
33
+	{
34
+		$this->ak = $ak;
35
+		$this->sk = $sk;
36
+		$this->namespace = $namespace;
37
+		$this->type = $type;
38
+		$this->upload_client = new UploadClient($ak, $sk, $type);
39
+		$this->manage_client = new ManageClient($ak, $sk, $type);
40
+	}
41
+
42
+	public function getUploadToken($option)
43
+	{
44
+		if (!isset($option['name']) || !$option['name']) {
45
+			$option['name'] = '${uuid}.${ext}';
46
+		}
47
+		if ($option['name']) {
48
+			$option['dir'] = preg_replace('/^\./', '', dirname($option['name']));
49
+			$option['name'] = last(explode("/", $option['name']));
50
+		}
51
+		$option['namespace'] = $this->namespace;
52
+
53
+		$policy = new UploadPolicy($option);
54
+
55
+		return $this->upload_client->getUploadToken($policy);
56
+	}
57
+
58
+	/**
59
+	 * 直接上传文件,适合文件比较小的情况
60
+	 */
61
+	public function upload($filePath, UploadPolicy $uploadPolicy, UploadOption $uploadOption = null)
62
+	{
63
+		return $this->upload_client->upload($filePath, $uploadPolicy, $uploadOption);
64
+	}
65
+
66
+	/**
67
+	 * 直接上传文件数据,适合数据量比较小的情况
68
+	 */
69
+	public function uploadData($data, UploadPolicy $uploadPolicy, UploadOption $uploadOption = null)
70
+	{
71
+		return $this->upload_client->uploadData($data, $uploadPolicy, $uploadOption);
72
+	}
73
+
74
+	/**
75
+	 * 创建分片上传任务,指定待上传的文件。即初始化分片上传
76
+	 */
77
+	public function multipartInit($filePath, UploadPolicy $uploadPolicy, UploadOption $uploadOption)
78
+	{
79
+		return $this->upload_client->multipartInit($filePath, $uploadPolicy, $uploadOption);
80
+	}
81
+
82
+	/**
83
+	 * 创建分片上传任务,指定初始化分片任务的数据,即第一块数据
84
+	 */
85
+	public function multipartInitByData($data, UploadPolicy $uploadPolicy, UploadOption $uploadOption)
86
+	{
87
+		return $this->upload_client->multipartInitByData($data, $uploadPolicy, $uploadOption);
88
+	}
89
+
90
+	/**
91
+	 * 分片上传,指定待上传的文件。需要指定UploadOption中文件块编号
92
+	 */
93
+	public function multipartUpload($filePath, UploadPolicy $uploadPolicy, UploadOption $uploadOption)
94
+	{
95
+		return $this->upload_client->multipartUpload($filePath, $uploadPolicy, $uploadOption);
96
+	}
97
+
98
+	/**
99
+	 * 分片上传,指定待上传的数据。需要指定UploadOption中文件块编号
100
+	 */
101
+	public function multipartUploadByData($blockData, UploadPolicy $uploadPolicy, UploadOption $uploadOption)
102
+	{
103
+		return $this->upload_client->multipartUploadByData($blockData, $uploadPolicy, $uploadOption);
104
+	}
105
+
106
+	/**
107
+	 * 完成分片上传任务。需要指定UploadOption中整个文件的md5值
108
+	 */
109
+	public function multipartComplete(UploadPolicy $uploadPolicy, UploadOption $uploadOption)
110
+	{
111
+		return $this->upload_client->multipartComplete($uploadPolicy, $uploadOption);
112
+	}
113
+
114
+	/**
115
+	 * 取消分片上传任务。需要保证UploadOption中有分片任务的uploadId和id
116
+	 */
117
+	public function multipartCancel(UploadPolicy $uploadPolicy, UploadOption $uploadOption)
118
+	{
119
+		return $this->upload_client->multipartCancel($uploadPolicy, $uploadOption);
120
+	}
121
+
122
+	/**
123
+	 * 查看文件是否存在
124
+	 */
125
+	public function existsFile($namespace, $dir, $filename)
126
+	{
127
+		return $this->manage_client->existsFile($namespace, $dir, $filename);
128
+	}
129
+
130
+	/**
131
+	 * 获取文件的元信息(meta信息)
132
+	 */
133
+	public function getFileInfo($namespace, $dir, $filename)
134
+	{
135
+		return $this->manage_client->getFileInfo($namespace, $dir, $filename);
136
+	}
137
+
138
+	/**
139
+	 * 重命名文件
140
+	 */
141
+	public function renameFile($namespace, $dir, $filename, $newDir, $newName)
142
+	{
143
+		return $this->manage_client->renameFile($namespace, $dir, $filename, $newDir, $newName);
144
+	}
145
+
146
+	/**
147
+	 * 获取指定目录下的文件列表。dir为空,表示根目录。page指定页数,pageSize指定每页显示数量
148
+	 */
149
+	public function listFiles($namespace, $dir, $page = 1, $pageSize = 100)
150
+	{
151
+		return $this->manage_client->listFiles($namespace, $dir, $page, $pageSize);
152
+	}
153
+
154
+	/**
155
+	 * 删除文件
156
+	 */
157
+	public function deleteFile($namespace, $dir, $filename)
158
+	{
159
+		return $this->manage_client->deleteFile($namespace, $dir, $filename);
160
+	}
161
+
162
+	/**
163
+	 * 查看文件夹是否存在
164
+	 */
165
+	public function existsFolder($namespace, $dir)
166
+	{
167
+		return $this->manage_client->existsFolder($namespace, $dir);
168
+	}
169
+
170
+	/**
171
+	 * 创建文件夹
172
+	 */
173
+	public function createDir($namespace, $dir)
174
+	{
175
+		return $this->manage_client->createDir($namespace, $dir);
176
+	}
177
+
178
+	/**
179
+	 * 获取子文件夹列表。dir为空,表示根目录。page指定页数,pageSize指定每页显示数量
180
+	 */
181
+	public function listDirs($namespace, $dir, $page = 1, $pageSize = 100)
182
+	{
183
+		return $this->manage_client->listDirs($namespace, $dir, $page, $pageSize);
184
+	}
185
+
186
+	/**
187
+	 * 删除文件夹
188
+	 */
189
+	public function deleteDir($namespace, $dir)
190
+	{
191
+		return $this->manage_client->deleteDir($namespace, $dir);
192
+	}
193
+
194
+	/**
195
+	 * 黄图扫描接口
196
+	 */
197
+	public function scanPorn(ManageOption $resInfos)
198
+	{
199
+		return $this->manage_client->scanPorn($resInfos);
200
+	}
201
+
202
+	/**
203
+	 * 鉴黄反馈feedback接口
204
+	 */
205
+	public function pornFeedback(ManageOption $pornFbInfos)
206
+	{
207
+		return $this->manage_client->pornFeedback($pornFbInfos);
208
+	}
209
+
210
+	/**
211
+	 * 多媒体转码接口
212
+	 */
213
+	public function mediaEncode(MediaEncodeOption $encodeOption)
214
+	{
215
+		return $this->manage_client->mediaEncode($encodeOption);
216
+	}
217
+
218
+	/**
219
+	 * 多媒体转码任务查询接口
220
+	 */
221
+	public function mediaEncodeQuery($taskId)
222
+	{
223
+		return $this->manage_client->mediaEncodeQuery($taskId);
224
+	}
225
+
226
+	/**
227
+	 * 视频截图接口
228
+	 */
229
+	public function videoSnapshot(SnapShotOption $snapshotOption)
230
+	{
231
+		return $this->manage_client->videoSnapshot($snapshotOption);
232
+	}
233
+
234
+	/**
235
+	 * 视频截图结果查询接口
236
+	 */
237
+	public function vSnapshotQuery($taskId)
238
+	{
239
+		return $this->manage_client->vSnapshotQuery($taskId);
240
+	}
241
+
242
+	/**
243
+	 * 广告图扫描接口(beta)
244
+	 */
245
+	public function scanAdvertising(ManageOption $resInfos)
246
+	{
247
+		return $this->manage_client->scanAdvertising($resInfos);
248
+	}
249 249
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@
 block discarded – undo
19 19
     private $namespace;
20 20
     private $type; // "TOP"和"CLOUD"两种模式
21 21
 
22
-    static $RUN_LEVEL = Conf::RUN_LEVEL_RELEASE;    //设置SDK运行级别
22
+    static $RUN_LEVEL = Conf::RUN_LEVEL_RELEASE; //设置SDK运行级别
23 23
 
24 24
     /**
25 25
      * 构造函数
Please login to merge, or discard this patch.
sdk/Core/ManageClient.php 2 patches
Indentation   +432 added lines, -432 removed lines patch added patch discarded remove patch
@@ -10,461 +10,461 @@
 block discarded – undo
10 10
 
11 11
 class ManageClient
12 12
 {
13
-    private $manage_host;
14
-    private $ak;
15
-    private $sk;
16
-    private $type;
17
-    public function __construct($ak, $sk, $type = Conf::TYPE_TOP)
18
-    {
19
-        $this->ak = $ak;
20
-        $this->sk = $sk;
21
-        $this->type = $type;
22
-        $this->manage_host = Conf::MANAGE_HOST_MEDIA;
23
-    }
13
+	private $manage_host;
14
+	private $ak;
15
+	private $sk;
16
+	private $type;
17
+	public function __construct($ak, $sk, $type = Conf::TYPE_TOP)
18
+	{
19
+		$this->ak = $ak;
20
+		$this->sk = $sk;
21
+		$this->type = $type;
22
+		$this->manage_host = Conf::MANAGE_HOST_MEDIA;
23
+	}
24 24
 
25
-    /**
26
-     * 文件是否存在
27
-     * @param string $namespace 空间名,必须
28
-     * @param string $dir 路径
29
-     * @param string $filename 文件名
30
-     * @return array
31
-     */
32
-    public function existsFile($namespace, $dir, $filename)
33
-    {
34
-        $resourceInfo = new ResourceInfo($namespace, $dir, $filename);
35
-        list($isValid, $message) = $resourceInfo->checkResourceInfo(true, true);
36
-        if (!$isValid) {
37
-            return $this->_errorResponse("InvalidArgument", $message);
38
-        }
39
-        $resourceId = $resourceInfo->buildResourceId(); //得到资源ID
40
-        $uri = '/' . Conf::MANAGE_API_VERSION . '/files/' . $resourceId . '/exist';
41
-        return $this->_send_request('GET', $uri);
42
-    }
25
+	/**
26
+	 * 文件是否存在
27
+	 * @param string $namespace 空间名,必须
28
+	 * @param string $dir 路径
29
+	 * @param string $filename 文件名
30
+	 * @return array
31
+	 */
32
+	public function existsFile($namespace, $dir, $filename)
33
+	{
34
+		$resourceInfo = new ResourceInfo($namespace, $dir, $filename);
35
+		list($isValid, $message) = $resourceInfo->checkResourceInfo(true, true);
36
+		if (!$isValid) {
37
+			return $this->_errorResponse("InvalidArgument", $message);
38
+		}
39
+		$resourceId = $resourceInfo->buildResourceId(); //得到资源ID
40
+		$uri = '/' . Conf::MANAGE_API_VERSION . '/files/' . $resourceId . '/exist';
41
+		return $this->_send_request('GET', $uri);
42
+	}
43 43
 
44
-    /**
45
-     * 获取文件的元信息(meta信息)
46
-     * @param string $namespace 空间名,必须
47
-     * @param string $dir 路径
48
-     * @param string $filename 文件名
49
-     * @return array
50
-     */
51
-    public function getFileInfo($namespace, $dir, $filename)
52
-    {
53
-        $resourceInfo = new ResourceInfo($namespace, $dir, $filename);
54
-        list($isValid, $message) = $resourceInfo->checkResourceInfo(true, true);
55
-        if (!$isValid) {
56
-            return $this->_errorResponse("InvalidArgument", $message);
57
-        }
58
-        $resourceId = $resourceInfo->buildResourceId(); //得到资源ID
59
-        $uri = '/' . Conf::MANAGE_API_VERSION . '/files/' . $resourceId;
60
-        return $this->_send_request('GET', $uri);
61
-    }
44
+	/**
45
+	 * 获取文件的元信息(meta信息)
46
+	 * @param string $namespace 空间名,必须
47
+	 * @param string $dir 路径
48
+	 * @param string $filename 文件名
49
+	 * @return array
50
+	 */
51
+	public function getFileInfo($namespace, $dir, $filename)
52
+	{
53
+		$resourceInfo = new ResourceInfo($namespace, $dir, $filename);
54
+		list($isValid, $message) = $resourceInfo->checkResourceInfo(true, true);
55
+		if (!$isValid) {
56
+			return $this->_errorResponse("InvalidArgument", $message);
57
+		}
58
+		$resourceId = $resourceInfo->buildResourceId(); //得到资源ID
59
+		$uri = '/' . Conf::MANAGE_API_VERSION . '/files/' . $resourceId;
60
+		return $this->_send_request('GET', $uri);
61
+	}
62 62
 
63
-    /**
64
-     * 重命名文件
65
-     * @param string $namespace 空间名,必须
66
-     * @param string $dir 路径
67
-     * @param string $filename 文件名
68
-     * @param string $newDir 新的路径
69
-     * @param string $newName 新的文件名
70
-     * @return array
71
-     */
72
-    public function renameFile($namespace, $dir, $filename, $newDir, $newName)
73
-    {
74
-        $resourceInfo = new ResourceInfo($namespace, $dir, $filename); //老的资源
75
-        list($isValid, $message) = $resourceInfo->checkResourceInfo(true, true);
76
-        if (!$isValid) {
77
-            return $this->_errorResponse("InvalidArgument", $message);
78
-        }
79
-        $newResourceInfo = new ResourceInfo($namespace, $newDir, $newName); //新的资源
80
-        list($isValid, $message) = $newResourceInfo->checkResourceInfo(true, true);
81
-        if (!$isValid) {
82
-            return $this->_errorResponse("InvalidArgument", $message);
83
-        }
84
-        $resourceId = $resourceInfo->buildResourceId(); //老资源ID
85
-        $newResourceId = $newResourceInfo->buildResourceId(); //新资源ID
86
-        $uri = '/' . Conf::MANAGE_API_VERSION . '/files/' . $resourceId . "/rename/" . $newResourceId;
87
-        return $this->_send_request('POST', $uri);
88
-    }
63
+	/**
64
+	 * 重命名文件
65
+	 * @param string $namespace 空间名,必须
66
+	 * @param string $dir 路径
67
+	 * @param string $filename 文件名
68
+	 * @param string $newDir 新的路径
69
+	 * @param string $newName 新的文件名
70
+	 * @return array
71
+	 */
72
+	public function renameFile($namespace, $dir, $filename, $newDir, $newName)
73
+	{
74
+		$resourceInfo = new ResourceInfo($namespace, $dir, $filename); //老的资源
75
+		list($isValid, $message) = $resourceInfo->checkResourceInfo(true, true);
76
+		if (!$isValid) {
77
+			return $this->_errorResponse("InvalidArgument", $message);
78
+		}
79
+		$newResourceInfo = new ResourceInfo($namespace, $newDir, $newName); //新的资源
80
+		list($isValid, $message) = $newResourceInfo->checkResourceInfo(true, true);
81
+		if (!$isValid) {
82
+			return $this->_errorResponse("InvalidArgument", $message);
83
+		}
84
+		$resourceId = $resourceInfo->buildResourceId(); //老资源ID
85
+		$newResourceId = $newResourceInfo->buildResourceId(); //新资源ID
86
+		$uri = '/' . Conf::MANAGE_API_VERSION . '/files/' . $resourceId . "/rename/" . $newResourceId;
87
+		return $this->_send_request('POST', $uri);
88
+	}
89 89
 
90
-    /**
91
-     * 获取指定目录下的文件列表
92
-     * @param string $namespace 空间名,必须
93
-     * @param string $dir 路径
94
-     * @param number $page 页数
95
-     * @param number $pageSize 每页显示的记录数
96
-     */
97
-    public function listFiles($namespace, $dir, $page = 1, $pageSize = 100)
98
-    {
99
-        $manageOption = new ManageOption($namespace);
100
-        $manageOption->setDir($dir)->setCurrentPage($page)->setPageSize($pageSize);
101
-        list($isValid, $message) = $manageOption->checkResourceInfo(true);
102
-        if ($page <= 0 || $pageSize <= 0) {
103
-            $isValid = false;
104
-            $message = "Invalid parameters page or pageSize";
105
-        }
106
-        if (!$isValid) {
107
-            return $this->_errorResponse("InvalidArgument", $message);
108
-        }
109
-        $queryParas = $manageOption->buildListFilesParas(); //查询query参数
110
-        $uri = '/' . Conf::MANAGE_API_VERSION . '/files?' . $queryParas;
111
-        return $this->_send_request('GET', $uri);
112
-    }
90
+	/**
91
+	 * 获取指定目录下的文件列表
92
+	 * @param string $namespace 空间名,必须
93
+	 * @param string $dir 路径
94
+	 * @param number $page 页数
95
+	 * @param number $pageSize 每页显示的记录数
96
+	 */
97
+	public function listFiles($namespace, $dir, $page = 1, $pageSize = 100)
98
+	{
99
+		$manageOption = new ManageOption($namespace);
100
+		$manageOption->setDir($dir)->setCurrentPage($page)->setPageSize($pageSize);
101
+		list($isValid, $message) = $manageOption->checkResourceInfo(true);
102
+		if ($page <= 0 || $pageSize <= 0) {
103
+			$isValid = false;
104
+			$message = "Invalid parameters page or pageSize";
105
+		}
106
+		if (!$isValid) {
107
+			return $this->_errorResponse("InvalidArgument", $message);
108
+		}
109
+		$queryParas = $manageOption->buildListFilesParas(); //查询query参数
110
+		$uri = '/' . Conf::MANAGE_API_VERSION . '/files?' . $queryParas;
111
+		return $this->_send_request('GET', $uri);
112
+	}
113 113
 
114
-    /**
115
-     * 删除文件
116
-     * @param string $namespace 空间名,必须
117
-     * @param string $dir 路径
118
-     * @param string $filename 文件名
119
-     * @return array
120
-     */
121
-    public function deleteFile($namespace, $dir, $filename)
122
-    {
123
-        $resourceInfo = new ResourceInfo($namespace, $dir, $filename);
124
-        list($isValid, $message) = $resourceInfo->checkResourceInfo(true, true);
125
-        if (!$isValid) {
126
-            return $this->_errorResponse("InvalidArgument", $message);
127
-        }
128
-        $resourceId = $resourceInfo->buildResourceId(); //得到资源ID
129
-        $uri = '/' . Conf::MANAGE_API_VERSION . '/files/' . $resourceId;
130
-        return $this->_send_request('DELETE', $uri);
131
-    }
114
+	/**
115
+	 * 删除文件
116
+	 * @param string $namespace 空间名,必须
117
+	 * @param string $dir 路径
118
+	 * @param string $filename 文件名
119
+	 * @return array
120
+	 */
121
+	public function deleteFile($namespace, $dir, $filename)
122
+	{
123
+		$resourceInfo = new ResourceInfo($namespace, $dir, $filename);
124
+		list($isValid, $message) = $resourceInfo->checkResourceInfo(true, true);
125
+		if (!$isValid) {
126
+			return $this->_errorResponse("InvalidArgument", $message);
127
+		}
128
+		$resourceId = $resourceInfo->buildResourceId(); //得到资源ID
129
+		$uri = '/' . Conf::MANAGE_API_VERSION . '/files/' . $resourceId;
130
+		return $this->_send_request('DELETE', $uri);
131
+	}
132 132
 
133
-    /**
134
-     * 文件夹是否存在
135
-     * @param string $namespace 空间名,必须
136
-     * @param string $dir 路径,即文件夹
137
-     * @return array
138
-     */
139
-    public function existsFolder($namespace, $dir)
140
-    {
141
-        if (empty($namespace) || empty($dir)) {
142
-            return $this->_errorResponse("InvalidArgument", "namespace or dir is empty");
143
-        }
144
-        if (strpos($dir, '/') !== 0) {
145
-            $dir = '/' . $dir;
146
-        }
147
-        $resourceInfo = new ResourceInfo($namespace, $dir);
148
-        $resourceId = $resourceInfo->buildResourceId(); //得到资源ID
149
-        $uri = '/' . Conf::MANAGE_API_VERSION . '/folders/' . $resourceId . '/exist';
150
-        return $this->_send_request('GET', $uri);
151
-    }
133
+	/**
134
+	 * 文件夹是否存在
135
+	 * @param string $namespace 空间名,必须
136
+	 * @param string $dir 路径,即文件夹
137
+	 * @return array
138
+	 */
139
+	public function existsFolder($namespace, $dir)
140
+	{
141
+		if (empty($namespace) || empty($dir)) {
142
+			return $this->_errorResponse("InvalidArgument", "namespace or dir is empty");
143
+		}
144
+		if (strpos($dir, '/') !== 0) {
145
+			$dir = '/' . $dir;
146
+		}
147
+		$resourceInfo = new ResourceInfo($namespace, $dir);
148
+		$resourceId = $resourceInfo->buildResourceId(); //得到资源ID
149
+		$uri = '/' . Conf::MANAGE_API_VERSION . '/folders/' . $resourceId . '/exist';
150
+		return $this->_send_request('GET', $uri);
151
+	}
152 152
 
153
-    /**
154
-     * 创建文件夹
155
-     * @param string $namespace 空间名,必须
156
-     * @param string $dir 路径,即文件夹
157
-     * @return array
158
-     */
159
-    public function createDir($namespace, $dir)
160
-    {
161
-        if (empty($namespace) || empty($dir)) {
162
-            return $this->_errorResponse("InvalidArgument", "namespace or dir is empty");
163
-        }
164
-        if (strpos($dir, '/') !== 0) {
165
-            $dir = '/' . $dir;
166
-        }
167
-        $resourceInfo = new ResourceInfo($namespace, $dir);
168
-        $resourceId = $resourceInfo->buildResourceId(); //得到资源ID
169
-        $uri = '/' . Conf::MANAGE_API_VERSION . '/folders/' . $resourceId;
170
-        return $this->_send_request('POST', $uri);
171
-    }
153
+	/**
154
+	 * 创建文件夹
155
+	 * @param string $namespace 空间名,必须
156
+	 * @param string $dir 路径,即文件夹
157
+	 * @return array
158
+	 */
159
+	public function createDir($namespace, $dir)
160
+	{
161
+		if (empty($namespace) || empty($dir)) {
162
+			return $this->_errorResponse("InvalidArgument", "namespace or dir is empty");
163
+		}
164
+		if (strpos($dir, '/') !== 0) {
165
+			$dir = '/' . $dir;
166
+		}
167
+		$resourceInfo = new ResourceInfo($namespace, $dir);
168
+		$resourceId = $resourceInfo->buildResourceId(); //得到资源ID
169
+		$uri = '/' . Conf::MANAGE_API_VERSION . '/folders/' . $resourceId;
170
+		return $this->_send_request('POST', $uri);
171
+	}
172 172
 
173
-    /**
174
-     * 获取指定目录下的文件夹列表
175
-     * @param string $namespace 空间名,必须
176
-     * @param string $dir 路径,指定目录
177
-     * @param number $page 页数
178
-     * @param number $pageSize 每页显示的记录数
179
-     */
180
-    public function listDirs($namespace, $dir, $page = 1, $pageSize = 100)
181
-    {
182
-        $manageOption = new ManageOption($namespace);
183
-        $manageOption->setDir($dir)->setCurrentPage($page)->setPageSize($pageSize);
184
-        list($isValid, $message) = $manageOption->checkResourceInfo(true);
185
-        if ($page <= 0 || $pageSize <= 0) {
186
-            $isValid = false;
187
-            $message = "Invalid parameters page or pageSize";
188
-        }
189
-        if (!$isValid) {
190
-            return $this->_errorResponse("InvalidArgument", $message);
191
-        }
192
-        $queryParas = $manageOption->buildListFilesParas(); //查询query参数
193
-        $uri = '/' . Conf::MANAGE_API_VERSION . '/folders?' . $queryParas;
194
-        return $this->_send_request('GET', $uri);
195
-    }
173
+	/**
174
+	 * 获取指定目录下的文件夹列表
175
+	 * @param string $namespace 空间名,必须
176
+	 * @param string $dir 路径,指定目录
177
+	 * @param number $page 页数
178
+	 * @param number $pageSize 每页显示的记录数
179
+	 */
180
+	public function listDirs($namespace, $dir, $page = 1, $pageSize = 100)
181
+	{
182
+		$manageOption = new ManageOption($namespace);
183
+		$manageOption->setDir($dir)->setCurrentPage($page)->setPageSize($pageSize);
184
+		list($isValid, $message) = $manageOption->checkResourceInfo(true);
185
+		if ($page <= 0 || $pageSize <= 0) {
186
+			$isValid = false;
187
+			$message = "Invalid parameters page or pageSize";
188
+		}
189
+		if (!$isValid) {
190
+			return $this->_errorResponse("InvalidArgument", $message);
191
+		}
192
+		$queryParas = $manageOption->buildListFilesParas(); //查询query参数
193
+		$uri = '/' . Conf::MANAGE_API_VERSION . '/folders?' . $queryParas;
194
+		return $this->_send_request('GET', $uri);
195
+	}
196 196
 
197
-    /**
198
-     * 删除文件夹
199
-     * @param string $namespace 空间名,必须
200
-     * @param string $dir 路径,即文件夹
201
-     * @return array
202
-     */
203
-    public function deleteDir($namespace, $dir)
204
-    {
205
-        if (empty($namespace) || empty($dir)) {
206
-            return $this->_errorResponse("InvalidArgument", "namespace or dir is empty");
207
-        }
208
-        if (strpos($dir, '/') !== 0) {
209
-            $dir = '/' . $dir;
210
-        }
211
-        $resourceInfo = new ResourceInfo($namespace, $dir);
212
-        $resourceId = $resourceInfo->buildResourceId(); //得到资源ID
213
-        $uri = '/' . Conf::MANAGE_API_VERSION . '/folders/' . $resourceId;
214
-        return $this->_send_request('DELETE', $uri);
215
-    }
216
-    /*######################################华丽的分界线#######################################*/
217
-    /*#######################上面是文件或文件夹的管理,下面是特色服务接口########################*/
218
-    /*########################################################################################*/
219
-    /**黄图扫描接口
197
+	/**
198
+	 * 删除文件夹
199
+	 * @param string $namespace 空间名,必须
200
+	 * @param string $dir 路径,即文件夹
201
+	 * @return array
202
+	 */
203
+	public function deleteDir($namespace, $dir)
204
+	{
205
+		if (empty($namespace) || empty($dir)) {
206
+			return $this->_errorResponse("InvalidArgument", "namespace or dir is empty");
207
+		}
208
+		if (strpos($dir, '/') !== 0) {
209
+			$dir = '/' . $dir;
210
+		}
211
+		$resourceInfo = new ResourceInfo($namespace, $dir);
212
+		$resourceId = $resourceInfo->buildResourceId(); //得到资源ID
213
+		$uri = '/' . Conf::MANAGE_API_VERSION . '/folders/' . $resourceId;
214
+		return $this->_send_request('DELETE', $uri);
215
+	}
216
+	/*######################################华丽的分界线#######################################*/
217
+	/*#######################上面是文件或文件夹的管理,下面是特色服务接口########################*/
218
+	/*########################################################################################*/
219
+	/**黄图扫描接口
220 220
      * @param ManageOption $resInfos 待扫描图片资源
221 221
      * @return array
222 222
      */
223
-    public function scanPorn(ManageOption $resInfos)
224
-    {
225
-        $uri = '/' . Conf::SCAN_PORN_VERSION . '/scanPorn';
226
-        list($isValid, $message, $bodyArray) = $resInfos->checkFilesAndUrls(); //检测并得到黄图扫描所需参数
227
-        if (!$isValid) {
228
-            return $this->_errorResponse("InvalidArgument", $message);
229
-        }
230
-        $httpBody = $this->createHttpBody($bodyArray); //http body字符串信息
231
-        return $this->_send_request('POST', $uri, $httpBody);
232
-    }
223
+	public function scanPorn(ManageOption $resInfos)
224
+	{
225
+		$uri = '/' . Conf::SCAN_PORN_VERSION . '/scanPorn';
226
+		list($isValid, $message, $bodyArray) = $resInfos->checkFilesAndUrls(); //检测并得到黄图扫描所需参数
227
+		if (!$isValid) {
228
+			return $this->_errorResponse("InvalidArgument", $message);
229
+		}
230
+		$httpBody = $this->createHttpBody($bodyArray); //http body字符串信息
231
+		return $this->_send_request('POST', $uri, $httpBody);
232
+	}
233 233
 
234
-    /**
235
-     * 鉴黄反馈feedback接口
236
-     * @param ManageOption $pornFbInfos 反馈信息
237
-     * @return array
238
-     */
239
-    public function pornFeedback(ManageOption $pornFbInfos)
240
-    {
241
-        $uri = '/' . Conf::SCAN_PORN_VERSION . '/feedback';
242
-        list($isValid, $message, $httpBody) = $pornFbInfos->checkPornFeedbackInfos();
243
-        if (!$isValid) {
244
-            return $this->_errorResponse("InvalidArgument", $message);
245
-        }
246
-        return $this->_send_request('POST', $uri, $httpBody);
247
-    }
234
+	/**
235
+	 * 鉴黄反馈feedback接口
236
+	 * @param ManageOption $pornFbInfos 反馈信息
237
+	 * @return array
238
+	 */
239
+	public function pornFeedback(ManageOption $pornFbInfos)
240
+	{
241
+		$uri = '/' . Conf::SCAN_PORN_VERSION . '/feedback';
242
+		list($isValid, $message, $httpBody) = $pornFbInfos->checkPornFeedbackInfos();
243
+		if (!$isValid) {
244
+			return $this->_errorResponse("InvalidArgument", $message);
245
+		}
246
+		return $this->_send_request('POST', $uri, $httpBody);
247
+	}
248 248
 
249
-    /**
250
-     * 多媒体(音视频)转码服务接口
251
-     * @param MediaResOption $encodeOption 转码参数选项
252
-     * @return array
253
-     */
254
-    public function mediaEncode(MediaResOption $encodeOption)
255
-    {
256
-        $uri = '/' . Conf::MEDIA_ENCODE_VERSION . '/mediaEncode';
257
-        list($isValid, $message, $httpBody) = $encodeOption->checkOptionParameters();
258
-        if (!$isValid) {
259
-            return $this->_errorResponse("InvalidArgument", $message);
260
-        }
261
-        return $this->_send_request('POST', $uri, $httpBody);
262
-    }
249
+	/**
250
+	 * 多媒体(音视频)转码服务接口
251
+	 * @param MediaResOption $encodeOption 转码参数选项
252
+	 * @return array
253
+	 */
254
+	public function mediaEncode(MediaResOption $encodeOption)
255
+	{
256
+		$uri = '/' . Conf::MEDIA_ENCODE_VERSION . '/mediaEncode';
257
+		list($isValid, $message, $httpBody) = $encodeOption->checkOptionParameters();
258
+		if (!$isValid) {
259
+			return $this->_errorResponse("InvalidArgument", $message);
260
+		}
261
+		return $this->_send_request('POST', $uri, $httpBody);
262
+	}
263 263
 
264
-    /**
265
-     * 多媒体转码任务查询接口
266
-     * @param string $taskId 转码任务ID
267
-     */
268
-    public function mediaEncodeQuery($taskId)
269
-    {
270
-        if (empty($taskId)) {
271
-            return $this->_errorResponse("InvalidArgument", "taskId is empty");
272
-        }
273
-        $uri = '/' . Conf::MEDIA_ENCODE_VERSION . '/mediaEncodeResult/' . $taskId;
274
-        return $this->_send_request('GET', $uri);
275
-    }
264
+	/**
265
+	 * 多媒体转码任务查询接口
266
+	 * @param string $taskId 转码任务ID
267
+	 */
268
+	public function mediaEncodeQuery($taskId)
269
+	{
270
+		if (empty($taskId)) {
271
+			return $this->_errorResponse("InvalidArgument", "taskId is empty");
272
+		}
273
+		$uri = '/' . Conf::MEDIA_ENCODE_VERSION . '/mediaEncodeResult/' . $taskId;
274
+		return $this->_send_request('GET', $uri);
275
+	}
276 276
 
277
-    /**
278
-     * 视频截图接口
279
-     * @param MediaResOption $snapshotOption 截图参数选项
280
-     * @return array
281
-     */
282
-    public function videoSnapshot(MediaResOption $snapshotOption)
283
-    {
284
-        $uri = '/' . Conf::MANAGE_API_VERSION . '/snapshot';
285
-        list($isValid, $message, $httpBody) = $snapshotOption->checkOptionParameters();
286
-        if (!$isValid) {
287
-            return $this->_errorResponse("InvalidArgument", $message);
288
-        }
289
-        return $this->_send_request('POST', $uri, $httpBody);
290
-    }
277
+	/**
278
+	 * 视频截图接口
279
+	 * @param MediaResOption $snapshotOption 截图参数选项
280
+	 * @return array
281
+	 */
282
+	public function videoSnapshot(MediaResOption $snapshotOption)
283
+	{
284
+		$uri = '/' . Conf::MANAGE_API_VERSION . '/snapshot';
285
+		list($isValid, $message, $httpBody) = $snapshotOption->checkOptionParameters();
286
+		if (!$isValid) {
287
+			return $this->_errorResponse("InvalidArgument", $message);
288
+		}
289
+		return $this->_send_request('POST', $uri, $httpBody);
290
+	}
291 291
 
292
-    /**
293
-     * 视频截图结果查询接口
294
-     * @param string $taskId 转码任务ID
295
-     */
296
-    public function vSnapshotQuery($taskId)
297
-    {
298
-        if (empty($taskId)) {
299
-            return $this->_errorResponse("InvalidArgument", "taskId is empty");
300
-        }
301
-        $uri = '/' . Conf::MANAGE_API_VERSION . '/snapshotResult/' . $taskId;
302
-        return $this->_send_request('GET', $uri);
303
-    }
292
+	/**
293
+	 * 视频截图结果查询接口
294
+	 * @param string $taskId 转码任务ID
295
+	 */
296
+	public function vSnapshotQuery($taskId)
297
+	{
298
+		if (empty($taskId)) {
299
+			return $this->_errorResponse("InvalidArgument", "taskId is empty");
300
+		}
301
+		$uri = '/' . Conf::MANAGE_API_VERSION . '/snapshotResult/' . $taskId;
302
+		return $this->_send_request('GET', $uri);
303
+	}
304 304
 
305
-    /**
306
-     *
307
-     * 广告图扫描接口(beta)
308
-     * @param ManageOption $resInfos 待扫描图片资源
309
-     * @return array
310
-     */
311
-    public function scanAdvertising(ManageOption $resInfos)
312
-    {
313
-        $uri = '/3.1/scanAdvertising';
314
-        list($isValid, $message, $bodyArray) = $resInfos->checkFilesAndUrls(); //检测并得到广告图图扫描所需参数
315
-        if (!$isValid) {
316
-            return $this->_errorResponse("InvalidArgument", $message);
317
-        }
318
-        $httpBody = $this->createHttpBody($bodyArray); //http body字符串信息
319
-        return $this->_send_request('POST', $uri, $httpBody);
320
-    }
305
+	/**
306
+	 *
307
+	 * 广告图扫描接口(beta)
308
+	 * @param ManageOption $resInfos 待扫描图片资源
309
+	 * @return array
310
+	 */
311
+	public function scanAdvertising(ManageOption $resInfos)
312
+	{
313
+		$uri = '/3.1/scanAdvertising';
314
+		list($isValid, $message, $bodyArray) = $resInfos->checkFilesAndUrls(); //检测并得到广告图图扫描所需参数
315
+		if (!$isValid) {
316
+			return $this->_errorResponse("InvalidArgument", $message);
317
+		}
318
+		$httpBody = $this->createHttpBody($bodyArray); //http body字符串信息
319
+		return $this->_send_request('POST', $uri, $httpBody);
320
+	}
321 321
 
322
-    /**
323
-     * 调用curl利用http上传数据
324
-     * @param string $method
325
-     * @param string $uri
326
-     * @param array $bodyArray
327
-     * @param array $headers
328
-     * @return array (isSuccess, ...)
329
-     */
330
-    protected function _send_request($method, $uri, $httpBody = null, $headers = null)
331
-    {
332
-        $success = false;
333
-        $result = null;
334
-        //构建Http请求头
335
-        $_headers = array('Expect:');
336
-        $date = $this->currentMilliSecond(); //得到当前的时间戳,毫秒
337
-        array_push($_headers, "Date: {$date}");
338
-        $authorization = $this->_getAuthorization($uri, $date, $httpBody);  //Http的Body需要加入管理鉴权
339
-        array_push($_headers, "Authorization: {$authorization}");
340
-        array_push($_headers, "User-Agent: {$this->_getUserAgent()}");
341
-        if (!is_null($headers) && is_array($headers)) {
342
-            foreach ($headers as $k => $v) {
343
-                array_push($_headers, "{$k}: {$v}");
344
-            }
345
-        }
346
-        $url = $this->_get_manage_url($uri); //根据管理接口uri拼接成URL
347
-        $ch = curl_init($url);
348
-        try {
349
-            //构建http请求体,并设置header部分属性
350
-            $length = 0;
351
-            if (!empty($httpBody)) {
352
-                $length = @strlen($httpBody);
353
-                curl_setopt($ch, CURLOPT_POSTFIELDS, $httpBody);
354
-                array_push($_headers, "Content-Type: application/x-www-form-urlencoded");
355
-            }
356
-            array_push($_headers, "Content-Length: {$length}");
357
-            curl_setopt($ch, CURLOPT_HEADER, 1);                            //设置头部
358
-            curl_setopt($ch, CURLOPT_HTTPHEADER, $_headers);                //请求头
359
-            curl_setopt($ch, CURLOPT_TIMEOUT, Conf::HTTP_TIMEOUT);      //超时时长
360
-            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);               //连接超时时长
361
-            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //成功,只返回结果,不自动输出任何内容。如果失败返回FALSE
362
-            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
363
-            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);           //自定义请求
364
-            //设置请求方式(GET或POST等)
365
-            if ($method == 'PUT' || $method == 'POST') {
366
-                curl_setopt($ch, CURLOPT_POST, 1);
367
-            } else {
368
-                curl_setopt($ch, CURLOPT_POST, 0);
369
-            }
370
-            //执行请求,然后获取服务端返回
371
-            $response = curl_exec($ch);
372
-            if ($response == false) {
373
-                $result = $this->_errorResponse("curl error", "curl request failed");
374
-                $result['errno'] = curl_errno($ch); //错误码
375
-            } else {
376
-                //解析返回结果,并判断是否上传成功
377
-                $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
378
-                $success = ($http_code == 200) ? true : false;                  //判断是否上传成功
379
-                $resStr = explode("\r\n\r\n", $response);
380
-                $resBody = isset($resStr[1]) ? $resStr[1] : '';
381
-                $resArray = json_decode($resBody, true);                        //解析得到结果
382
-                $result = (empty($resArray)) ? array() : $resArray;
383
-            }
384
-        } catch (Exception $e) {
385
-            $success = false;
386
-            $result = $this->_errorResponse("HTTPRequestException#" . $e->getCode(), $e->getMessage());
387
-        }
388
-        curl_close($ch); //PHP5.3中不支持finally关键字。因此,为了兼容,这里取消finally
389
-        $result['isSuccess'] = $success;
390
-        return $result;
391
-    }
322
+	/**
323
+	 * 调用curl利用http上传数据
324
+	 * @param string $method
325
+	 * @param string $uri
326
+	 * @param array $bodyArray
327
+	 * @param array $headers
328
+	 * @return array (isSuccess, ...)
329
+	 */
330
+	protected function _send_request($method, $uri, $httpBody = null, $headers = null)
331
+	{
332
+		$success = false;
333
+		$result = null;
334
+		//构建Http请求头
335
+		$_headers = array('Expect:');
336
+		$date = $this->currentMilliSecond(); //得到当前的时间戳,毫秒
337
+		array_push($_headers, "Date: {$date}");
338
+		$authorization = $this->_getAuthorization($uri, $date, $httpBody);  //Http的Body需要加入管理鉴权
339
+		array_push($_headers, "Authorization: {$authorization}");
340
+		array_push($_headers, "User-Agent: {$this->_getUserAgent()}");
341
+		if (!is_null($headers) && is_array($headers)) {
342
+			foreach ($headers as $k => $v) {
343
+				array_push($_headers, "{$k}: {$v}");
344
+			}
345
+		}
346
+		$url = $this->_get_manage_url($uri); //根据管理接口uri拼接成URL
347
+		$ch = curl_init($url);
348
+		try {
349
+			//构建http请求体,并设置header部分属性
350
+			$length = 0;
351
+			if (!empty($httpBody)) {
352
+				$length = @strlen($httpBody);
353
+				curl_setopt($ch, CURLOPT_POSTFIELDS, $httpBody);
354
+				array_push($_headers, "Content-Type: application/x-www-form-urlencoded");
355
+			}
356
+			array_push($_headers, "Content-Length: {$length}");
357
+			curl_setopt($ch, CURLOPT_HEADER, 1);                            //设置头部
358
+			curl_setopt($ch, CURLOPT_HTTPHEADER, $_headers);                //请求头
359
+			curl_setopt($ch, CURLOPT_TIMEOUT, Conf::HTTP_TIMEOUT);      //超时时长
360
+			curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);               //连接超时时长
361
+			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //成功,只返回结果,不自动输出任何内容。如果失败返回FALSE
362
+			curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
363
+			curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);           //自定义请求
364
+			//设置请求方式(GET或POST等)
365
+			if ($method == 'PUT' || $method == 'POST') {
366
+				curl_setopt($ch, CURLOPT_POST, 1);
367
+			} else {
368
+				curl_setopt($ch, CURLOPT_POST, 0);
369
+			}
370
+			//执行请求,然后获取服务端返回
371
+			$response = curl_exec($ch);
372
+			if ($response == false) {
373
+				$result = $this->_errorResponse("curl error", "curl request failed");
374
+				$result['errno'] = curl_errno($ch); //错误码
375
+			} else {
376
+				//解析返回结果,并判断是否上传成功
377
+				$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
378
+				$success = ($http_code == 200) ? true : false;                  //判断是否上传成功
379
+				$resStr = explode("\r\n\r\n", $response);
380
+				$resBody = isset($resStr[1]) ? $resStr[1] : '';
381
+				$resArray = json_decode($resBody, true);                        //解析得到结果
382
+				$result = (empty($resArray)) ? array() : $resArray;
383
+			}
384
+		} catch (Exception $e) {
385
+			$success = false;
386
+			$result = $this->_errorResponse("HTTPRequestException#" . $e->getCode(), $e->getMessage());
387
+		}
388
+		curl_close($ch); //PHP5.3中不支持finally关键字。因此,为了兼容,这里取消finally
389
+		$result['isSuccess'] = $success;
390
+		return $result;
391
+	}
392 392
 
393
-    /**
394
-     * 根据$bodyArray构建http请求体。多个字段之间用&号分割
395
-     */
396
-    protected function createHttpBody($bodyArray)
397
-    {
398
-        $bodyStr = '';
399
-        foreach ($bodyArray as $key => $value) {
400
-            $bodyStr .= (empty($bodyStr) ? null : '&'); //添加分隔符
401
-            $bodyStr .= "{$key}=" . urlencode($value);
402
-        }
403
-        return $bodyStr;
404
-    }
393
+	/**
394
+	 * 根据$bodyArray构建http请求体。多个字段之间用&号分割
395
+	 */
396
+	protected function createHttpBody($bodyArray)
397
+	{
398
+		$bodyStr = '';
399
+		foreach ($bodyArray as $key => $value) {
400
+			$bodyStr .= (empty($bodyStr) ? null : '&'); //添加分隔符
401
+			$bodyStr .= "{$key}=" . urlencode($value);
402
+		}
403
+		return $bodyStr;
404
+	}
405 405
 
406
-    /**
407
-     * UserAgent用户代理
408
-     */
409
-    protected function _getUserAgent()
410
-    {
411
-        if ($this->type == "TOP") {
412
-            return "ALIMEDIASDK_PHP_TAE/" . Conf::SDK_VERSION;
413
-        } else {
414
-            return "ALIMEDIASDK_PHP_CLOUD/" . Conf::SDK_VERSION;
415
-        }
416
-    }
406
+	/**
407
+	 * UserAgent用户代理
408
+	 */
409
+	protected function _getUserAgent()
410
+	{
411
+		if ($this->type == "TOP") {
412
+			return "ALIMEDIASDK_PHP_TAE/" . Conf::SDK_VERSION;
413
+		} else {
414
+			return "ALIMEDIASDK_PHP_CLOUD/" . Conf::SDK_VERSION;
415
+		}
416
+	}
417 417
 
418
-    /**
419
-     * 根据管理接口uri拼接成完整的URL
420
-     */
421
-    protected function _get_manage_url($uri)
422
-    {
423
-        return Conf::MANAGE_HOST_MEDIA . $uri;
424
-    }
425
-    protected function _getNamespaceKey()
426
-    {
427
-        if ($this->type == "TOP") {
428
-            return "namespace";
429
-        } else {
430
-            return "bucketName";
431
-        }
432
-    }
418
+	/**
419
+	 * 根据管理接口uri拼接成完整的URL
420
+	 */
421
+	protected function _get_manage_url($uri)
422
+	{
423
+		return Conf::MANAGE_HOST_MEDIA . $uri;
424
+	}
425
+	protected function _getNamespaceKey()
426
+	{
427
+		if ($this->type == "TOP") {
428
+			return "namespace";
429
+		} else {
430
+			return "bucketName";
431
+		}
432
+	}
433 433
 
434
-    /**
435
-     * 获取管理鉴权信息
436
-     */
437
-    protected function _getAuthorization($uri, $date, $httpBody)
438
-    {
439
-        $stringBeforeSign = "{$uri}\n{$httpBody}\n{$date}"; //1.生成待加签的原始字符串
440
-        $signStr = hash_hmac('sha1', $stringBeforeSign, $this->sk); //2.使用SK对字符串计算HMAC-SHA1签名
441
-        $preenCode = $this->ak . ":" . $signStr; //3.将签名与AK进行拼接
442
-        $encodedStr = EncodeUtils::encodeWithURLSafeBase64($preenCode); //4.对拼接后的结果进行URL安全的Base64编码
443
-        $manageToken = "ACL_" . $this->type . " " . $encodedStr; //5.最后为编码结果加上得到管理凭证
444
-        return $manageToken;
445
-    }
434
+	/**
435
+	 * 获取管理鉴权信息
436
+	 */
437
+	protected function _getAuthorization($uri, $date, $httpBody)
438
+	{
439
+		$stringBeforeSign = "{$uri}\n{$httpBody}\n{$date}"; //1.生成待加签的原始字符串
440
+		$signStr = hash_hmac('sha1', $stringBeforeSign, $this->sk); //2.使用SK对字符串计算HMAC-SHA1签名
441
+		$preenCode = $this->ak . ":" . $signStr; //3.将签名与AK进行拼接
442
+		$encodedStr = EncodeUtils::encodeWithURLSafeBase64($preenCode); //4.对拼接后的结果进行URL安全的Base64编码
443
+		$manageToken = "ACL_" . $this->type . " " . $encodedStr; //5.最后为编码结果加上得到管理凭证
444
+		return $manageToken;
445
+	}
446 446
 
447
-    /**
448
-     * 得到当前时间的毫秒数
449
-     */
450
-    protected function currentMilliSecond()
451
-    {
452
-        list($microSec, $stampSec) = explode(' ', microtime());
453
-        $tempMilli =  sprintf('%03s', intval($microSec * 1000));
454
-        $currentMilli = $stampSec . $tempMilli;
455
-        return $currentMilli;
456
-    }
447
+	/**
448
+	 * 得到当前时间的毫秒数
449
+	 */
450
+	protected function currentMilliSecond()
451
+	{
452
+		list($microSec, $stampSec) = explode(' ', microtime());
453
+		$tempMilli =  sprintf('%03s', intval($microSec * 1000));
454
+		$currentMilli = $stampSec . $tempMilli;
455
+		return $currentMilli;
456
+	}
457 457
 
458
-    /**
459
-     * 反馈错误信息
460
-     */
461
-    protected function _errorResponse($code = "UnknownError", $message = "unkonown error", $requestId = null)
462
-    {
463
-        return array(
464
-            "isSuccess" => false,
465
-            "code" => $code,
466
-            "message" => $message,
467
-            "requestId" => $requestId
468
-        );
469
-    }
458
+	/**
459
+	 * 反馈错误信息
460
+	 */
461
+	protected function _errorResponse($code = "UnknownError", $message = "unkonown error", $requestId = null)
462
+	{
463
+		return array(
464
+			"isSuccess" => false,
465
+			"code" => $code,
466
+			"message" => $message,
467
+			"requestId" => $requestId
468
+		);
469
+	}
470 470
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
         $_headers = array('Expect:');
336 336
         $date = $this->currentMilliSecond(); //得到当前的时间戳,毫秒
337 337
         array_push($_headers, "Date: {$date}");
338
-        $authorization = $this->_getAuthorization($uri, $date, $httpBody);  //Http的Body需要加入管理鉴权
338
+        $authorization = $this->_getAuthorization($uri, $date, $httpBody); //Http的Body需要加入管理鉴权
339 339
         array_push($_headers, "Authorization: {$authorization}");
340 340
         array_push($_headers, "User-Agent: {$this->_getUserAgent()}");
341 341
         if (!is_null($headers) && is_array($headers)) {
@@ -354,13 +354,13 @@  discard block
 block discarded – undo
354 354
                 array_push($_headers, "Content-Type: application/x-www-form-urlencoded");
355 355
             }
356 356
             array_push($_headers, "Content-Length: {$length}");
357
-            curl_setopt($ch, CURLOPT_HEADER, 1);                            //设置头部
358
-            curl_setopt($ch, CURLOPT_HTTPHEADER, $_headers);                //请求头
359
-            curl_setopt($ch, CURLOPT_TIMEOUT, Conf::HTTP_TIMEOUT);      //超时时长
360
-            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);               //连接超时时长
357
+            curl_setopt($ch, CURLOPT_HEADER, 1); //设置头部
358
+            curl_setopt($ch, CURLOPT_HTTPHEADER, $_headers); //请求头
359
+            curl_setopt($ch, CURLOPT_TIMEOUT, Conf::HTTP_TIMEOUT); //超时时长
360
+            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); //连接超时时长
361 361
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //成功,只返回结果,不自动输出任何内容。如果失败返回FALSE
362 362
             curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
363
-            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);           //自定义请求
363
+            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); //自定义请求
364 364
             //设置请求方式(GET或POST等)
365 365
             if ($method == 'PUT' || $method == 'POST') {
366 366
                 curl_setopt($ch, CURLOPT_POST, 1);
@@ -375,10 +375,10 @@  discard block
 block discarded – undo
375 375
             } else {
376 376
                 //解析返回结果,并判断是否上传成功
377 377
                 $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
378
-                $success = ($http_code == 200) ? true : false;                  //判断是否上传成功
378
+                $success = ($http_code == 200) ? true : false; //判断是否上传成功
379 379
                 $resStr = explode("\r\n\r\n", $response);
380 380
                 $resBody = isset($resStr[1]) ? $resStr[1] : '';
381
-                $resArray = json_decode($resBody, true);                        //解析得到结果
381
+                $resArray = json_decode($resBody, true); //解析得到结果
382 382
                 $result = (empty($resArray)) ? array() : $resArray;
383 383
             }
384 384
         } catch (Exception $e) {
@@ -450,7 +450,7 @@  discard block
 block discarded – undo
450 450
     protected function currentMilliSecond()
451 451
     {
452 452
         list($microSec, $stampSec) = explode(' ', microtime());
453
-        $tempMilli =  sprintf('%03s', intval($microSec * 1000));
453
+        $tempMilli = sprintf('%03s', intval($microSec * 1000));
454 454
         $currentMilli = $stampSec . $tempMilli;
455 455
         return $currentMilli;
456 456
     }
Please login to merge, or discard this patch.
sdk/Utils/ResourceInfo.php 2 patches
Indentation   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -4,93 +4,93 @@
 block discarded – undo
4 4
 /**文件资源类*/
5 5
 class ResourceInfo
6 6
 {
7
-    /* 以下属性是资源ID所需的属性*/
8
-    protected $namespace;                              //空间名,必须
9
-    protected $dir;                                    //路径
10
-    protected $name;                                   //文件名信息
11
-    /* 以下属性是资源ID所需的属性*/
12
-    /**
13
-     * ResourceOption的构造函数
14
-     */
15
-    public function __construct($namespace, $dir = null, $name = null)
16
-    {
17
-        $this->namespace = $namespace;
18
-        $this->dir = $dir;
19
-        $this->name = $name;
20
-    }
21
-    /**检测资源ID的是否合法。$dirState表示是否检测dir,$nameState表示是否检测filename<p>
7
+	/* 以下属性是资源ID所需的属性*/
8
+	protected $namespace;                              //空间名,必须
9
+	protected $dir;                                    //路径
10
+	protected $name;                                   //文件名信息
11
+	/* 以下属性是资源ID所需的属性*/
12
+	/**
13
+	 * ResourceOption的构造函数
14
+	 */
15
+	public function __construct($namespace, $dir = null, $name = null)
16
+	{
17
+		$this->namespace = $namespace;
18
+		$this->dir = $dir;
19
+		$this->name = $name;
20
+	}
21
+	/**检测资源ID的是否合法。$dirState表示是否检测dir,$nameState表示是否检测filename<p>
22 22
      * 返回格式{$isValid, $message}*/
23
-    public function checkResourceInfo($dirState = false, $nameState = false)
24
-    {
25
-        if (empty($this->namespace)) {
26
-            return array(false, "namespace is empty.[{$this->toString()}]"); // 判断是否设置空间名
27
-        } else {
28
-            return $this->checkFileInfo($dirState, $nameState); // 判断dir和name的合法性
29
-        }
30
-    }
31
-    /**检测文件信息是否合法。$dirState表示是否检测dir,$nameState表示是否检测filename<p>
23
+	public function checkResourceInfo($dirState = false, $nameState = false)
24
+	{
25
+		if (empty($this->namespace)) {
26
+			return array(false, "namespace is empty.[{$this->toString()}]"); // 判断是否设置空间名
27
+		} else {
28
+			return $this->checkFileInfo($dirState, $nameState); // 判断dir和name的合法性
29
+		}
30
+	}
31
+	/**检测文件信息是否合法。$dirState表示是否检测dir,$nameState表示是否检测filename<p>
32 32
      * 返回格式{$isValid, $message}*/
33
-    public function checkFileInfo($dirState = false, $nameState = false)
34
-    {
35
-        if ($nameState && empty($this->name)) {
36
-            return array(false, "file's name is empty.[{$this->toString()}]"); // 1:若需要进行文件名name检测,则判断文件名是否为空
37
-        }
38
-        if ($dirState) {
39
-            if (empty($this->dir)) {
40
-                $this->dir = '/'; // 2:判断路径是否为空,若为空,则默认为根目录'/'
41
-            } elseif (strpos($this->dir, '/') !== 0) {
42
-                $this->dir = '/' . $this->dir; // 3:判断路径是否以'/'开头,若不是,则添加'/'
43
-            }
44
-        }
45
-        return array(true, null);
46
-    }
47
-    /**资源ID(resourceId)的生成*/
48
-    public function buildResourceId()
49
-    {
50
-        $jsonData = array();
51
-        if (!empty($this->namespace)) {
52
-            array_push($jsonData, urldecode($this->namespace));
53
-        }
54
-        if (!empty($this->dir)) {
55
-            array_push($jsonData, urldecode($this->dir));
56
-        }
57
-        if (!empty($this->name)) {
58
-            array_push($jsonData, urldecode($this->name));
59
-        }
60
-        return EncodeUtils::encodeWithURLSafeBase64(json_encode($jsonData, true));
61
-    }
62
-    /**对URL中文进行编码*/
63
-    protected function urlencode_ch($str)
64
-    {
65
-        return preg_replace_callback('/[^\0-\127]+/', function ($match) {
66
-            return urlencode($match[0]);
67
-        }, $str);
68
-    }
69
-    public function toString()
70
-    {
71
-        return "namespace={$this->namespace}, dir={$this->dir}, name={$this->name}";
72
-    }
73
-    public function toArray()
74
-    {
75
-        return array("namespace" => $this->namespace, "dir" => $this->dir, "name" => $this->name);
76
-    }
77
-    /*###################下面是属性的get和set方法###############*/
78
-    /**设置路径*/
79
-    public function setNamespace($namespace)
80
-    {
81
-        $this->namespace = $namespace;
82
-        return $this;
83
-    }
84
-    /**设置路径*/
85
-    public function setDir($dir)
86
-    {
87
-        $this->dir = $dir;
88
-        return $this;
89
-    }
90
-    /**设置文件名*/
91
-    public function setName($filename)
92
-    {
93
-        $this->name = $filename;
94
-        return $this;
95
-    }
33
+	public function checkFileInfo($dirState = false, $nameState = false)
34
+	{
35
+		if ($nameState && empty($this->name)) {
36
+			return array(false, "file's name is empty.[{$this->toString()}]"); // 1:若需要进行文件名name检测,则判断文件名是否为空
37
+		}
38
+		if ($dirState) {
39
+			if (empty($this->dir)) {
40
+				$this->dir = '/'; // 2:判断路径是否为空,若为空,则默认为根目录'/'
41
+			} elseif (strpos($this->dir, '/') !== 0) {
42
+				$this->dir = '/' . $this->dir; // 3:判断路径是否以'/'开头,若不是,则添加'/'
43
+			}
44
+		}
45
+		return array(true, null);
46
+	}
47
+	/**资源ID(resourceId)的生成*/
48
+	public function buildResourceId()
49
+	{
50
+		$jsonData = array();
51
+		if (!empty($this->namespace)) {
52
+			array_push($jsonData, urldecode($this->namespace));
53
+		}
54
+		if (!empty($this->dir)) {
55
+			array_push($jsonData, urldecode($this->dir));
56
+		}
57
+		if (!empty($this->name)) {
58
+			array_push($jsonData, urldecode($this->name));
59
+		}
60
+		return EncodeUtils::encodeWithURLSafeBase64(json_encode($jsonData, true));
61
+	}
62
+	/**对URL中文进行编码*/
63
+	protected function urlencode_ch($str)
64
+	{
65
+		return preg_replace_callback('/[^\0-\127]+/', function ($match) {
66
+			return urlencode($match[0]);
67
+		}, $str);
68
+	}
69
+	public function toString()
70
+	{
71
+		return "namespace={$this->namespace}, dir={$this->dir}, name={$this->name}";
72
+	}
73
+	public function toArray()
74
+	{
75
+		return array("namespace" => $this->namespace, "dir" => $this->dir, "name" => $this->name);
76
+	}
77
+	/*###################下面是属性的get和set方法###############*/
78
+	/**设置路径*/
79
+	public function setNamespace($namespace)
80
+	{
81
+		$this->namespace = $namespace;
82
+		return $this;
83
+	}
84
+	/**设置路径*/
85
+	public function setDir($dir)
86
+	{
87
+		$this->dir = $dir;
88
+		return $this;
89
+	}
90
+	/**设置文件名*/
91
+	public function setName($filename)
92
+	{
93
+		$this->name = $filename;
94
+		return $this;
95
+	}
96 96
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -5,9 +5,9 @@  discard block
 block discarded – undo
5 5
 class ResourceInfo
6 6
 {
7 7
     /* 以下属性是资源ID所需的属性*/
8
-    protected $namespace;                              //空间名,必须
9
-    protected $dir;                                    //路径
10
-    protected $name;                                   //文件名信息
8
+    protected $namespace; //空间名,必须
9
+    protected $dir; //路径
10
+    protected $name; //文件名信息
11 11
     /* 以下属性是资源ID所需的属性*/
12 12
     /**
13 13
      * ResourceOption的构造函数
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
     /**对URL中文进行编码*/
63 63
     protected function urlencode_ch($str)
64 64
     {
65
-        return preg_replace_callback('/[^\0-\127]+/', function ($match) {
65
+        return preg_replace_callback('/[^\0-\127]+/', function($match) {
66 66
             return urlencode($match[0]);
67 67
         }, $str);
68 68
     }
Please login to merge, or discard this patch.
sdk/Utils/MimeTypes.php 1 patch
Indentation   +133 added lines, -133 removed lines patch added patch discarded remove patch
@@ -3,138 +3,138 @@
 block discarded – undo
3 3
 
4 4
 class MimeTypes
5 5
 {
6
-    public static $mime_types = array(
7
-        '3gp' => 'video/3gpp', 'ai' => 'application/postscript',
8
-        'aif' => 'audio/x-aiff', 'aifc' => 'audio/x-aiff',
9
-        'aiff' => 'audio/x-aiff', 'asc' => 'text/plain',
10
-        'atom' => 'application/atom+xml', 'au' => 'audio/basic',
11
-        'avi' => 'video/x-msvideo', 'bcpio' => 'application/x-bcpio',
12
-        'bin' => 'application/octet-stream', 'bmp' => 'image/bmp',
13
-        'cdf' => 'application/x-netcdf', 'cgm' => 'image/cgm',
14
-        'class' => 'application/octet-stream',
15
-        'cpio' => 'application/x-cpio',
16
-        'cpt' => 'application/mac-compactpro',
17
-        'csh' => 'application/x-csh', 'css' => 'text/css',
18
-        'dcr' => 'application/x-director', 'dif' => 'video/x-dv',
19
-        'dir' => 'application/x-director', 'djv' => 'image/vnd.djvu',
20
-        'djvu' => 'image/vnd.djvu',
21
-        'dll' => 'application/octet-stream',
22
-        'dmg' => 'application/octet-stream',
23
-        'dms' => 'application/octet-stream',
24
-        'doc' => 'application/msword', 'dtd' => 'application/xml-dtd',
25
-        'dv' => 'video/x-dv', 'dvi' => 'application/x-dvi',
26
-        'dxr' => 'application/x-director',
27
-        'eps' => 'application/postscript', 'etx' => 'text/x-setext',
28
-        'exe' => 'application/octet-stream',
29
-        'ez' => 'application/andrew-inset', 'flv' => 'video/x-flv',
30
-        'gif' => 'image/gif', 'gram' => 'application/srgs',
31
-        'grxml' => 'application/srgs+xml',
32
-        'gtar' => 'application/x-gtar', 'gz' => 'application/x-gzip',
33
-        'hdf' => 'application/x-hdf',
34
-        'hqx' => 'application/mac-binhex40', 'htm' => 'text/html',
35
-        'html' => 'text/html', 'ice' => 'x-conference/x-cooltalk',
36
-        'ico' => 'image/x-icon', 'ics' => 'text/calendar',
37
-        'ief' => 'image/ief', 'ifb' => 'text/calendar',
38
-        'iges' => 'model/iges', 'igs' => 'model/iges',
39
-        'jnlp' => 'application/x-java-jnlp-file', 'jp2' => 'image/jp2',
40
-        'jpe' => 'image/jpeg', 'jpeg' => 'image/jpeg',
41
-        'jpg' => 'image/jpeg', 'js' => 'application/x-javascript',
42
-        'kar' => 'audio/midi', 'latex' => 'application/x-latex',
43
-        'lha' => 'application/octet-stream',
44
-        'lzh' => 'application/octet-stream',
45
-        'm3u' => 'audio/x-mpegurl', 'm4a' => 'audio/mp4a-latm',
46
-        'm4p' => 'audio/mp4a-latm', 'm4u' => 'video/vnd.mpegurl',
47
-        'm4v' => 'video/x-m4v', 'mac' => 'image/x-macpaint',
48
-        'man' => 'application/x-troff-man',
49
-        'mathml' => 'application/mathml+xml',
50
-        'me' => 'application/x-troff-me', 'mesh' => 'model/mesh',
51
-        'mid' => 'audio/midi', 'midi' => 'audio/midi',
52
-        'mif' => 'application/vnd.mif', 'mov' => 'video/quicktime',
53
-        'movie' => 'video/x-sgi-movie', 'mp2' => 'audio/mpeg',
54
-        'mp3' => 'audio/mpeg', 'mp4' => 'video/mp4',
55
-        'mpe' => 'video/mpeg', 'mpeg' => 'video/mpeg',
56
-        'mpg' => 'video/mpeg', 'mpga' => 'audio/mpeg',
57
-        'ms' => 'application/x-troff-ms', 'msh' => 'model/mesh',
58
-        'mxu' => 'video/vnd.mpegurl', 'nc' => 'application/x-netcdf',
59
-        'oda' => 'application/oda', 'ogg' => 'application/ogg',
60
-        'ogv' => 'video/ogv', 'pbm' => 'image/x-portable-bitmap',
61
-        'pct' => 'image/pict', 'pdb' => 'chemical/x-pdb',
62
-        'pdf' => 'application/pdf',
63
-        'pgm' => 'image/x-portable-graymap',
64
-        'pgn' => 'application/x-chess-pgn', 'pic' => 'image/pict',
65
-        'pict' => 'image/pict', 'png' => 'image/png',
66
-        'pnm' => 'image/x-portable-anymap',
67
-        'pnt' => 'image/x-macpaint', 'pntg' => 'image/x-macpaint',
68
-        'ppm' => 'image/x-portable-pixmap',
69
-        'ppt' => 'application/vnd.ms-powerpoint',
70
-        'ps' => 'application/postscript', 'qt' => 'video/quicktime',
71
-        'qti' => 'image/x-quicktime', 'qtif' => 'image/x-quicktime',
72
-        'ra' => 'audio/x-pn-realaudio',
73
-        'ram' => 'audio/x-pn-realaudio', 'ras' => 'image/x-cmu-raster',
74
-        'rdf' => 'application/rdf+xml', 'rgb' => 'image/x-rgb',
75
-        'rm' => 'application/vnd.rn-realmedia',
76
-        'roff' => 'application/x-troff', 'rtf' => 'text/rtf',
77
-        'rtx' => 'text/richtext', 'sgm' => 'text/sgml',
78
-        'sgml' => 'text/sgml', 'sh' => 'application/x-sh',
79
-        'shar' => 'application/x-shar', 'silo' => 'model/mesh',
80
-        'sit' => 'application/x-stuffit',
81
-        'skd' => 'application/x-koan', 'skm' => 'application/x-koan',
82
-        'skp' => 'application/x-koan', 'skt' => 'application/x-koan',
83
-        'smi' => 'application/smil', 'smil' => 'application/smil',
84
-        'snd' => 'audio/basic', 'so' => 'application/octet-stream',
85
-        'spl' => 'application/x-futuresplash',
86
-        'src' => 'application/x-wais-source',
87
-        'sv4cpio' => 'application/x-sv4cpio',
88
-        'sv4crc' => 'application/x-sv4crc', 'svg' => 'image/svg+xml',
89
-        'swf' => 'application/x-shockwave-flash',
90
-        't' => 'application/x-troff', 'tar' => 'application/x-tar',
91
-        'tcl' => 'application/x-tcl', 'tex' => 'application/x-tex',
92
-        'texi' => 'application/x-texinfo',
93
-        'texinfo' => 'application/x-texinfo', 'tif' => 'image/tiff',
94
-        'tiff' => 'image/tiff', 'tr' => 'application/x-troff',
95
-        'tsv' => 'text/tab-separated-values', 'txt' => 'text/plain',
96
-        'ustar' => 'application/x-ustar',
97
-        'vcd' => 'application/x-cdlink', 'vrml' => 'model/vrml',
98
-        'vxml' => 'application/voicexml+xml', 'wav' => 'audio/x-wav',
99
-        'wbmp' => 'image/vnd.wap.wbmp',
100
-        'wbxml' => 'application/vnd.wap.wbxml', 'webm' => 'video/webm',
101
-        'wml' => 'text/vnd.wap.wml',
102
-        'wmlc' => 'application/vnd.wap.wmlc',
103
-        'wmls' => 'text/vnd.wap.wmlscript',
104
-        'wmlsc' => 'application/vnd.wap.wmlscriptc',
105
-        'wmv' => 'video/x-ms-wmv', 'wrl' => 'model/vrml',
106
-        'xbm' => 'image/x-xbitmap', 'xht' => 'application/xhtml+xml',
107
-        'xhtml' => 'application/xhtml+xml',
108
-        'xls' => 'application/vnd.ms-excel',
109
-        'xml' => 'application/xml', 'xpm' => 'image/x-xpixmap',
110
-        'xsl' => 'application/xml', 'xslt' => 'application/xslt+xml',
111
-        'xul' => 'application/vnd.mozilla.xul+xml',
112
-        'xwd' => 'image/x-xwindowdump', 'xyz' => 'chemical/x-xyz',
113
-        'zip' => 'application/zip',
114
-        "apk" => "application/vnd.android.package-archive",
115
-        "bin" => "application/octet-stream",
116
-        "cab" => "application/vnd.ms-cab-compressed",
117
-        "gb" => "application/chinese-gb",
118
-        "gba" => "application/octet-stream",
119
-        "gbc" => "application/octet-stream",
120
-        "jad" => "text/vnd.sun.j2me.app-descriptor",
121
-        "jar" => "application/java-archive",
122
-        "nes" => "application/octet-stream",
123
-        "rar" => "application/x-rar-compressed",
124
-        "sis" => "application/vnd.symbian.install",
125
-        "sisx" => "x-epoc/x-sisx-app",
126
-        "smc" => "application/octet-stream",
127
-        "smd" => "application/octet-stream",
128
-        "swf" => "application/x-shockwave-flash",
129
-        "zip" => "application/x-zip-compressed",
130
-        "wap" => "text/vnd.wap.wml wml", "mrp" => "application/mrp",
131
-        "wma" => "audio/x-ms-wma",
132
-        "lrc" => "application/lrc"
133
-    );
6
+	public static $mime_types = array(
7
+		'3gp' => 'video/3gpp', 'ai' => 'application/postscript',
8
+		'aif' => 'audio/x-aiff', 'aifc' => 'audio/x-aiff',
9
+		'aiff' => 'audio/x-aiff', 'asc' => 'text/plain',
10
+		'atom' => 'application/atom+xml', 'au' => 'audio/basic',
11
+		'avi' => 'video/x-msvideo', 'bcpio' => 'application/x-bcpio',
12
+		'bin' => 'application/octet-stream', 'bmp' => 'image/bmp',
13
+		'cdf' => 'application/x-netcdf', 'cgm' => 'image/cgm',
14
+		'class' => 'application/octet-stream',
15
+		'cpio' => 'application/x-cpio',
16
+		'cpt' => 'application/mac-compactpro',
17
+		'csh' => 'application/x-csh', 'css' => 'text/css',
18
+		'dcr' => 'application/x-director', 'dif' => 'video/x-dv',
19
+		'dir' => 'application/x-director', 'djv' => 'image/vnd.djvu',
20
+		'djvu' => 'image/vnd.djvu',
21
+		'dll' => 'application/octet-stream',
22
+		'dmg' => 'application/octet-stream',
23
+		'dms' => 'application/octet-stream',
24
+		'doc' => 'application/msword', 'dtd' => 'application/xml-dtd',
25
+		'dv' => 'video/x-dv', 'dvi' => 'application/x-dvi',
26
+		'dxr' => 'application/x-director',
27
+		'eps' => 'application/postscript', 'etx' => 'text/x-setext',
28
+		'exe' => 'application/octet-stream',
29
+		'ez' => 'application/andrew-inset', 'flv' => 'video/x-flv',
30
+		'gif' => 'image/gif', 'gram' => 'application/srgs',
31
+		'grxml' => 'application/srgs+xml',
32
+		'gtar' => 'application/x-gtar', 'gz' => 'application/x-gzip',
33
+		'hdf' => 'application/x-hdf',
34
+		'hqx' => 'application/mac-binhex40', 'htm' => 'text/html',
35
+		'html' => 'text/html', 'ice' => 'x-conference/x-cooltalk',
36
+		'ico' => 'image/x-icon', 'ics' => 'text/calendar',
37
+		'ief' => 'image/ief', 'ifb' => 'text/calendar',
38
+		'iges' => 'model/iges', 'igs' => 'model/iges',
39
+		'jnlp' => 'application/x-java-jnlp-file', 'jp2' => 'image/jp2',
40
+		'jpe' => 'image/jpeg', 'jpeg' => 'image/jpeg',
41
+		'jpg' => 'image/jpeg', 'js' => 'application/x-javascript',
42
+		'kar' => 'audio/midi', 'latex' => 'application/x-latex',
43
+		'lha' => 'application/octet-stream',
44
+		'lzh' => 'application/octet-stream',
45
+		'm3u' => 'audio/x-mpegurl', 'm4a' => 'audio/mp4a-latm',
46
+		'm4p' => 'audio/mp4a-latm', 'm4u' => 'video/vnd.mpegurl',
47
+		'm4v' => 'video/x-m4v', 'mac' => 'image/x-macpaint',
48
+		'man' => 'application/x-troff-man',
49
+		'mathml' => 'application/mathml+xml',
50
+		'me' => 'application/x-troff-me', 'mesh' => 'model/mesh',
51
+		'mid' => 'audio/midi', 'midi' => 'audio/midi',
52
+		'mif' => 'application/vnd.mif', 'mov' => 'video/quicktime',
53
+		'movie' => 'video/x-sgi-movie', 'mp2' => 'audio/mpeg',
54
+		'mp3' => 'audio/mpeg', 'mp4' => 'video/mp4',
55
+		'mpe' => 'video/mpeg', 'mpeg' => 'video/mpeg',
56
+		'mpg' => 'video/mpeg', 'mpga' => 'audio/mpeg',
57
+		'ms' => 'application/x-troff-ms', 'msh' => 'model/mesh',
58
+		'mxu' => 'video/vnd.mpegurl', 'nc' => 'application/x-netcdf',
59
+		'oda' => 'application/oda', 'ogg' => 'application/ogg',
60
+		'ogv' => 'video/ogv', 'pbm' => 'image/x-portable-bitmap',
61
+		'pct' => 'image/pict', 'pdb' => 'chemical/x-pdb',
62
+		'pdf' => 'application/pdf',
63
+		'pgm' => 'image/x-portable-graymap',
64
+		'pgn' => 'application/x-chess-pgn', 'pic' => 'image/pict',
65
+		'pict' => 'image/pict', 'png' => 'image/png',
66
+		'pnm' => 'image/x-portable-anymap',
67
+		'pnt' => 'image/x-macpaint', 'pntg' => 'image/x-macpaint',
68
+		'ppm' => 'image/x-portable-pixmap',
69
+		'ppt' => 'application/vnd.ms-powerpoint',
70
+		'ps' => 'application/postscript', 'qt' => 'video/quicktime',
71
+		'qti' => 'image/x-quicktime', 'qtif' => 'image/x-quicktime',
72
+		'ra' => 'audio/x-pn-realaudio',
73
+		'ram' => 'audio/x-pn-realaudio', 'ras' => 'image/x-cmu-raster',
74
+		'rdf' => 'application/rdf+xml', 'rgb' => 'image/x-rgb',
75
+		'rm' => 'application/vnd.rn-realmedia',
76
+		'roff' => 'application/x-troff', 'rtf' => 'text/rtf',
77
+		'rtx' => 'text/richtext', 'sgm' => 'text/sgml',
78
+		'sgml' => 'text/sgml', 'sh' => 'application/x-sh',
79
+		'shar' => 'application/x-shar', 'silo' => 'model/mesh',
80
+		'sit' => 'application/x-stuffit',
81
+		'skd' => 'application/x-koan', 'skm' => 'application/x-koan',
82
+		'skp' => 'application/x-koan', 'skt' => 'application/x-koan',
83
+		'smi' => 'application/smil', 'smil' => 'application/smil',
84
+		'snd' => 'audio/basic', 'so' => 'application/octet-stream',
85
+		'spl' => 'application/x-futuresplash',
86
+		'src' => 'application/x-wais-source',
87
+		'sv4cpio' => 'application/x-sv4cpio',
88
+		'sv4crc' => 'application/x-sv4crc', 'svg' => 'image/svg+xml',
89
+		'swf' => 'application/x-shockwave-flash',
90
+		't' => 'application/x-troff', 'tar' => 'application/x-tar',
91
+		'tcl' => 'application/x-tcl', 'tex' => 'application/x-tex',
92
+		'texi' => 'application/x-texinfo',
93
+		'texinfo' => 'application/x-texinfo', 'tif' => 'image/tiff',
94
+		'tiff' => 'image/tiff', 'tr' => 'application/x-troff',
95
+		'tsv' => 'text/tab-separated-values', 'txt' => 'text/plain',
96
+		'ustar' => 'application/x-ustar',
97
+		'vcd' => 'application/x-cdlink', 'vrml' => 'model/vrml',
98
+		'vxml' => 'application/voicexml+xml', 'wav' => 'audio/x-wav',
99
+		'wbmp' => 'image/vnd.wap.wbmp',
100
+		'wbxml' => 'application/vnd.wap.wbxml', 'webm' => 'video/webm',
101
+		'wml' => 'text/vnd.wap.wml',
102
+		'wmlc' => 'application/vnd.wap.wmlc',
103
+		'wmls' => 'text/vnd.wap.wmlscript',
104
+		'wmlsc' => 'application/vnd.wap.wmlscriptc',
105
+		'wmv' => 'video/x-ms-wmv', 'wrl' => 'model/vrml',
106
+		'xbm' => 'image/x-xbitmap', 'xht' => 'application/xhtml+xml',
107
+		'xhtml' => 'application/xhtml+xml',
108
+		'xls' => 'application/vnd.ms-excel',
109
+		'xml' => 'application/xml', 'xpm' => 'image/x-xpixmap',
110
+		'xsl' => 'application/xml', 'xslt' => 'application/xslt+xml',
111
+		'xul' => 'application/vnd.mozilla.xul+xml',
112
+		'xwd' => 'image/x-xwindowdump', 'xyz' => 'chemical/x-xyz',
113
+		'zip' => 'application/zip',
114
+		"apk" => "application/vnd.android.package-archive",
115
+		"bin" => "application/octet-stream",
116
+		"cab" => "application/vnd.ms-cab-compressed",
117
+		"gb" => "application/chinese-gb",
118
+		"gba" => "application/octet-stream",
119
+		"gbc" => "application/octet-stream",
120
+		"jad" => "text/vnd.sun.j2me.app-descriptor",
121
+		"jar" => "application/java-archive",
122
+		"nes" => "application/octet-stream",
123
+		"rar" => "application/x-rar-compressed",
124
+		"sis" => "application/vnd.symbian.install",
125
+		"sisx" => "x-epoc/x-sisx-app",
126
+		"smc" => "application/octet-stream",
127
+		"smd" => "application/octet-stream",
128
+		"swf" => "application/x-shockwave-flash",
129
+		"zip" => "application/x-zip-compressed",
130
+		"wap" => "text/vnd.wap.wml wml", "mrp" => "application/mrp",
131
+		"wma" => "audio/x-ms-wma",
132
+		"lrc" => "application/lrc"
133
+	);
134 134
 
135
-    public static function get_mimetype($ext)
136
-    {
137
-        $ext = strtolower($ext);
138
-        return (isset(self::$mime_types[$ext]) ? self::$mime_types[$ext] : 'application/octet-stream');
139
-    }
135
+	public static function get_mimetype($ext)
136
+	{
137
+		$ext = strtolower($ext);
138
+		return (isset(self::$mime_types[$ext]) ? self::$mime_types[$ext] : 'application/octet-stream');
139
+	}
140 140
 }
Please login to merge, or discard this patch.
sdk/Utils/EncodeUtils.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -4,27 +4,27 @@
 block discarded – undo
4 4
 class EncodeUtils
5 5
 {
6 6
 
7
-    /*
7
+	/*
8 8
      * URL安全的Base64编码适用于以URL方式传递Base64编码结果的场景。
9 9
      * 该编码方式的基本过程是先将内容以Base64格式编码为字符串,
10 10
      * 然后检查该结果字符串,将字符串中的加号+换成中划线-,并且将斜杠/换成下划线_,同时尾部去除等号padding。
11 11
      */
12
-    public static function encodeWithURLSafeBase64($arg)
13
-    {
14
-        if ($arg === null || empty($arg)) {
15
-            return null;
16
-        }
17
-        $result = base64_encode($arg);
18
-        $result = str_replace(array('+', '/', '='), array('-', '_', ''), $result);
19
-        return $result;
20
-    }
12
+	public static function encodeWithURLSafeBase64($arg)
13
+	{
14
+		if ($arg === null || empty($arg)) {
15
+			return null;
16
+		}
17
+		$result = base64_encode($arg);
18
+		$result = str_replace(array('+', '/', '='), array('-', '_', ''), $result);
19
+		return $result;
20
+	}
21 21
 
22
-    public static function new_encodeWithURLSafeBase64($arg)
23
-    {
24
-        if ($arg === null || empty($arg)) {
25
-            return null;
26
-        }
27
-        $result = preg_replace(array("/\r/", "/\n/"), "", rtrim(base64_encode($arg), '='));
28
-        return $result;
29
-    }
22
+	public static function new_encodeWithURLSafeBase64($arg)
23
+	{
24
+		if ($arg === null || empty($arg)) {
25
+			return null;
26
+		}
27
+		$result = preg_replace(array("/\r/", "/\n/"), "", rtrim(base64_encode($arg), '='));
28
+		return $result;
29
+	}
30 30
 }
Please login to merge, or discard this patch.