@@ -1,15 +1,15 @@ |
||
1 | 1 | <?php |
2 | -require dirname(__DIR__) . '/vendor/autoload.php'; |
|
2 | +require dirname(__DIR__).'/vendor/autoload.php'; |
|
3 | 3 | |
4 | 4 | define('USER_NAME', 'tester'); |
5 | 5 | define('PWD', 'grjxv2mxELR3'); |
6 | 6 | define('BUCKET', 'sdkimg'); |
7 | -define('PIC_PATH', dirname(__FILE__) . '/assets/sample.jpeg'); |
|
7 | +define('PIC_PATH', dirname(__FILE__).'/assets/sample.jpeg'); |
|
8 | 8 | define('PIC_SIZE', filesize(PIC_PATH)); |
9 | 9 | |
10 | 10 | function getFileUrl($path) |
11 | 11 | { |
12 | - return "http://" . BUCKET . ".b0.upaiyun.com/" . ltrim($path, '/'); |
|
12 | + return "http://".BUCKET.".b0.upaiyun.com/".ltrim($path, '/'); |
|
13 | 13 | } |
14 | 14 | |
15 | 15 | function getUpyunFileSize($path) |
@@ -72,12 +72,12 @@ |
||
72 | 72 | public static function encodeURI($url) |
73 | 73 | { |
74 | 74 | $unescaped = array( |
75 | - '%2D'=>'-','%5F'=>'_','%2E'=>'.','%21'=>'!', '%7E'=>'~', |
|
75 | + '%2D'=>'-', '%5F'=>'_', '%2E'=>'.', '%21'=>'!', '%7E'=>'~', |
|
76 | 76 | '%2A'=>'*', '%27'=>"'", '%28'=>'(', '%29'=>')' |
77 | 77 | ); |
78 | 78 | $reserved = array( |
79 | - '%3B'=>';','%2C'=>',','%2F'=>'/','%3F'=>'?','%3A'=>':', |
|
80 | - '%40'=>'@','%26'=>'&','%3D'=>'=','%2B'=>'+','%24'=>'$' |
|
79 | + '%3B'=>';', '%2C'=>',', '%2F'=>'/', '%3F'=>'?', '%3A'=>':', |
|
80 | + '%40'=>'@', '%26'=>'&', '%3D'=>'=', '%2B'=>'+', '%24'=>'$' |
|
81 | 81 | ); |
82 | 82 | $score = array( |
83 | 83 | '%23'=>'#' |
@@ -18,7 +18,7 @@ |
||
18 | 18 | |
19 | 19 | $policy = Util::base64Json($params); |
20 | 20 | $method = 'POST'; |
21 | - $signature = Signature::getBodySignature($this->config, $method, '/' . $params['service'], null, $policy); |
|
21 | + $signature = Signature::getBodySignature($this->config, $method, '/'.$params['service'], null, $policy); |
|
22 | 22 | $client = new Client([ |
23 | 23 | 'timeout' => $this->config->timeout, |
24 | 24 | ]); |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | $method = 'POST'; |
44 | 44 | $signedHeaders = Signature::getHeaderSign($this->config, $method, $path); |
45 | 45 | |
46 | - $url = $this->config->getPretreatEndPoint() . $path; |
|
46 | + $url = $this->config->getPretreatEndPoint().$path; |
|
47 | 47 | $response = $client->request($method, $url, [ |
48 | 48 | 'headers' => $signedHeaders, |
49 | 49 | 'form_params' => $params |
@@ -64,10 +64,10 @@ discard block |
||
64 | 64 | 'service' => $this->config->serviceName, |
65 | 65 | 'task_ids' => implode(',', $taskIds) |
66 | 66 | ); |
67 | - $path = $path . '?' . http_build_query($params); |
|
67 | + $path = $path.'?'.http_build_query($params); |
|
68 | 68 | |
69 | 69 | $method = 'GET'; |
70 | - $url = $this->config->getPretreatEndPoint() . $path; |
|
70 | + $url = $this->config->getPretreatEndPoint().$path; |
|
71 | 71 | $signedHeaders = Signature::getHeaderSign($this->config, $method, $path); |
72 | 72 | $response = $client->request($method, $url, [ |
73 | 73 | 'headers' => $signedHeaders |
@@ -26,11 +26,11 @@ |
||
26 | 26 | 'timeout' => $this->config->timeout, |
27 | 27 | ]); |
28 | 28 | |
29 | - $path = '/' . $this->config->serviceName . $path; |
|
29 | + $path = '/'.$this->config->serviceName.$path; |
|
30 | 30 | $method = 'POST'; |
31 | 31 | $signedHeaders = Signature::getHeaderSign($this->config, $method, $path); |
32 | 32 | |
33 | - $url = $this->config->getSyncVideoEndPoint() . $path; |
|
33 | + $url = $this->config->getSyncVideoEndPoint().$path; |
|
34 | 34 | $response = $client->request($method, $url, [ |
35 | 35 | 'headers' => $signedHeaders, |
36 | 36 | 'json' => $params |
@@ -84,17 +84,17 @@ discard block |
||
84 | 84 | /** |
85 | 85 | * 异步云处理接口地址 |
86 | 86 | */ |
87 | - const ED_VIDEO = 'p0.api.upyun.com'; |
|
87 | + const ED_VIDEO = 'p0.api.upyun.com'; |
|
88 | 88 | |
89 | 89 | /** |
90 | 90 | * 刷新接口地址 |
91 | 91 | */ |
92 | - const ED_PURGE = 'http://purge.upyun.com/purge/'; |
|
92 | + const ED_PURGE = 'http://purge.upyun.com/purge/'; |
|
93 | 93 | |
94 | 94 | /** |
95 | 95 | * 同步视频处理接口地址 |
96 | 96 | */ |
97 | - const ED_SYNC_VIDEO = 'p1.api.upyun.com'; |
|
97 | + const ED_SYNC_VIDEO = 'p1.api.upyun.com'; |
|
98 | 98 | |
99 | 99 | public function __construct($serviceName, $operatorName, $operatorPassword) |
100 | 100 | { |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | |
114 | 114 | public function getFormApiKey() |
115 | 115 | { |
116 | - if (! $this->formApiKey) { |
|
116 | + if (!$this->formApiKey) { |
|
117 | 117 | throw new \Exception('form api key is empty.'); |
118 | 118 | } |
119 | 119 | |
@@ -132,12 +132,12 @@ discard block |
||
132 | 132 | |
133 | 133 | public function getPretreatEndPoint() |
134 | 134 | { |
135 | - return $this->getProtocol() . self::ED_VIDEO; |
|
135 | + return $this->getProtocol().self::ED_VIDEO; |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | public function getSyncVideoEndPoint() |
139 | 139 | { |
140 | - return $this->getProtocol() . self::ED_SYNC_VIDEO; |
|
140 | + return $this->getProtocol().self::ED_SYNC_VIDEO; |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | public function getProtocol() |
@@ -29,13 +29,13 @@ discard block |
||
29 | 29 | public function __construct(Config $config) |
30 | 30 | { |
31 | 31 | $this->config = $config; |
32 | - $this->endpoint = $config->getProtocol() . Config::$restApiEndPoint . '/' . $config->serviceName; |
|
32 | + $this->endpoint = $config->getProtocol().Config::$restApiEndPoint.'/'.$config->serviceName; |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | public function request($method, $storagePath) |
36 | 36 | { |
37 | 37 | $this->method = strtoupper($method); |
38 | - $this->storagePath = '/' . ltrim($storagePath, '/'); |
|
38 | + $this->storagePath = '/'.ltrim($storagePath, '/'); |
|
39 | 39 | return $this; |
40 | 40 | } |
41 | 41 | |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | 'timeout' => $this->config->timeout, |
63 | 63 | ]); |
64 | 64 | |
65 | - $url = $this->endpoint . $this->storagePath; |
|
65 | + $url = $this->endpoint.$this->storagePath; |
|
66 | 66 | $body = null; |
67 | 67 | if ($this->file && $this->method === 'PUT') { |
68 | 68 | $body = $this->file; |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | |
109 | 109 | public function toRequest() |
110 | 110 | { |
111 | - $url = $this->endpoint . $this->storagePath; |
|
111 | + $url = $this->endpoint.$this->storagePath; |
|
112 | 112 | $body = null; |
113 | 113 | if ($this->file && $this->method === 'PUT') { |
114 | 114 | $body = $this->file; |
@@ -36,9 +36,9 @@ |
||
36 | 36 | if (! $useBlock) { |
37 | 37 | $req = new Rest($this->config); |
38 | 38 | return $req->request('PUT', $path) |
39 | - ->withHeaders($params) |
|
40 | - ->withFile($stream) |
|
41 | - ->send(); |
|
39 | + ->withHeaders($params) |
|
40 | + ->withFile($stream) |
|
41 | + ->send(); |
|
42 | 42 | } elseif ($this->config->uploadType === 'BLOCK_PARALLEL') { |
43 | 43 | return $this->concurrentPointUpload($path, $stream, $params); |
44 | 44 | } else { |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | return $req->upload($path, $stream, $params); |
34 | 34 | } |
35 | 35 | |
36 | - if (! $useBlock) { |
|
36 | + if (!$useBlock) { |
|
37 | 37 | $req = new Rest($this->config); |
38 | 38 | return $req->request('PUT', $path) |
39 | 39 | ->withHeaders($params) |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | $headers = array(); |
62 | 62 | if (is_array($params)) { |
63 | 63 | foreach ($params as $key => $val) { |
64 | - $headers['X-Upyun-Meta-' . $key] = $val; |
|
64 | + $headers['X-Upyun-Meta-'.$key] = $val; |
|
65 | 65 | } |
66 | 66 | } |
67 | 67 | $res = $req->request('PUT', $path) |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | $headers = array(); |
140 | 140 | if (is_array($params)) { |
141 | 141 | foreach ($params as $key => $val) { |
142 | - $headers['X-Upyun-Meta-' . $key] = $val; |
|
142 | + $headers['X-Upyun-Meta-'.$key] = $val; |
|
143 | 143 | } |
144 | 144 | } |
145 | 145 | $res = $req->request('PUT', $path) |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | |
157 | 157 | $init = Util::getHeaderParams($res->getHeaders()); |
158 | 158 | $uuid = $init['x-upyun-multi-uuid']; |
159 | - $requests = function ($req, $path, $stream, $uuid) { |
|
159 | + $requests = function($req, $path, $stream, $uuid) { |
|
160 | 160 | $blockSize = 1024 * 1024; |
161 | 161 | $total = ceil($stream->getSize() / $blockSize); |
162 | 162 | for ($i = 0; $i < $total; $i++) { |
@@ -176,12 +176,12 @@ discard block |
||
176 | 176 | ]); |
177 | 177 | $pool = new Pool($client, $requests($req, $path, $stream, $uuid), [ |
178 | 178 | 'concurrency' => $this->config->concurrency, |
179 | - 'fulfilled' => function ($res) { |
|
179 | + 'fulfilled' => function($res) { |
|
180 | 180 | if ($res->getStatusCode() !== 204) { |
181 | 181 | throw new \Exception('upload request failed when poinit upload!'); |
182 | 182 | } |
183 | 183 | }, |
184 | - 'rejected' => function () { |
|
184 | + 'rejected' => function() { |
|
185 | 185 | throw new \Exception('upload request failed when poinit upload!'); |
186 | 186 | }, |
187 | 187 | ]); |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | $config->setFormApiKey('Mv83tlocuzkmfKKUFbz2s04FzTw='); |
24 | 24 | $config->processNotifyUrl = 'http://localhost:9999'; |
25 | 25 | self::$upyun = new Upyun($config); |
26 | - self::$tempFilePath = __DIR__ . '/assets/test.txt'; |
|
26 | + self::$tempFilePath = __DIR__.'/assets/test.txt'; |
|
27 | 27 | touch(self::$tempFilePath); |
28 | 28 | } |
29 | 29 | |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | public function testWriteStream() |
45 | 45 | { |
46 | 46 | $filename = 'test.jpeg'; |
47 | - $f = fopen(__DIR__ . '/assets/sample.jpeg', 'rb'); |
|
47 | + $f = fopen(__DIR__.'/assets/sample.jpeg', 'rb'); |
|
48 | 48 | if (!$f) { |
49 | 49 | throw new \Exception('open test file failed!'); |
50 | 50 | } |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | { |
58 | 58 | $filename = 'test_async.jpeg'; |
59 | 59 | $newFilename = 'test_async.png'; |
60 | - $f = fopen(__DIR__ . '/assets/sample.jpeg', 'rb'); |
|
60 | + $f = fopen(__DIR__.'/assets/sample.jpeg', 'rb'); |
|
61 | 61 | if (!$f) { |
62 | 62 | throw new \Exception('open test file failed!'); |
63 | 63 | } |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | try { |
82 | 82 | $fs->write('test.txt', 'test file content'); |
83 | 83 | } catch (\Exception $e) { |
84 | - return ; |
|
84 | + return; |
|
85 | 85 | } |
86 | 86 | throw new \Exception('should get sign error.'); |
87 | 87 | } |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | try { |
117 | 117 | self::$upyun->read('test-delete.txt'); |
118 | 118 | } catch (\Exception $e) { |
119 | - return ; |
|
119 | + return; |
|
120 | 120 | } |
121 | 121 | throw new \Exception('delete file failed'); |
122 | 122 | } |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | public function testProcess() |
247 | 247 | { |
248 | 248 | $source = 'php-sdk-sample.mp4'; |
249 | - self::$upyun->write($source, fopen(__DIR__ . '/assets/SampleVideo_640x360_1mb.mp4', 'r')); |
|
249 | + self::$upyun->write($source, fopen(__DIR__.'/assets/SampleVideo_640x360_1mb.mp4', 'r')); |
|
250 | 250 | $result = self::$upyun->process(array( |
251 | 251 | array('type' => 'video', 'avopts' => '/s/240p(4:3)/as/1/r/30', 'return_info' => true, 'save_as' => '/video/result.mp4') |
252 | 252 | ), Upyun::$PROCESS_TYPE_MEDIA, $source); |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | public function testAvMeta() |
286 | 286 | { |
287 | 287 | $source = 'php-sdk-sample.mp4'; |
288 | - self::$upyun->write($source, fopen(__DIR__ . '/assets/SampleVideo_640x360_1mb.mp4', 'r')); |
|
288 | + self::$upyun->write($source, fopen(__DIR__.'/assets/SampleVideo_640x360_1mb.mp4', 'r')); |
|
289 | 289 | $result = self::$upyun->avMeta('/php-sdk-sample.mp4'); |
290 | 290 | $this->assertTrue(count($result) === 2); |
291 | 291 | $this->assertTrue($result['streams'][0]['type'] === 'video'); |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | { |
296 | 296 | sleep(5); |
297 | 297 | $source = 'php-sdk-sample.mp4'; |
298 | - self::$upyun->write($source, fopen(__DIR__ . '/assets/SampleVideo_640x360_1mb.mp4', 'r')); |
|
298 | + self::$upyun->write($source, fopen(__DIR__.'/assets/SampleVideo_640x360_1mb.mp4', 'r')); |
|
299 | 299 | $result = self::$upyun->snapshot('/php-sdk-sample.mp4', '/snapshot.jpg', '00:00:01', '720x480', 'jpg'); |
300 | 300 | $this->assertTrue($result['status_code'] === 200); |
301 | 301 | } |
@@ -306,7 +306,7 @@ discard block |
||
306 | 306 | $config->setUploadType('BLOCK_PARALLEL'); |
307 | 307 | $upyun = new Upyun($config); |
308 | 308 | $filename = 'test_parallel.jpeg'; |
309 | - $upyun->write($filename, fopen(__DIR__ . '/assets/sample.jpeg', 'rb')); |
|
309 | + $upyun->write($filename, fopen(__DIR__.'/assets/sample.jpeg', 'rb')); |
|
310 | 310 | |
311 | 311 | $size = getUpyunFileSize($filename); |
312 | 312 | $this->assertEquals($size, PIC_SIZE); |