@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | use Upyun\Config; |
4 | 4 | use Upyun\Upyun; |
5 | 5 | |
6 | -class UpyunTest extends \PHPUnit_Framework_TestCase{ |
|
6 | +class UpyunTest extends \PHPUnit_Framework_TestCase { |
|
7 | 7 | |
8 | 8 | /** |
9 | 9 | * @var Upyun |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | $config->setFormApiKey('Mv83tlocuzkmfKKUFbz2s04FzTw='); |
21 | 21 | $config->processNotifyUrl = 'http://localhost:9999'; |
22 | 22 | self::$upyun = new Upyun($config); |
23 | - self::$tempFilePath = __DIR__ . '/assets/test.txt'; |
|
23 | + self::$tempFilePath = __DIR__.'/assets/test.txt'; |
|
24 | 24 | touch(self::$tempFilePath); |
25 | 25 | } |
26 | 26 | |
@@ -38,8 +38,8 @@ discard block |
||
38 | 38 | |
39 | 39 | public function testWriteStream() { |
40 | 40 | $filename = 'test.jpeg'; |
41 | - $f = fopen(__DIR__ . '/assets/sample.jpeg', 'rb'); |
|
42 | - if(!$f) { |
|
41 | + $f = fopen(__DIR__.'/assets/sample.jpeg', 'rb'); |
|
42 | + if (!$f) { |
|
43 | 43 | throw new \Exception('open test file failed!'); |
44 | 44 | } |
45 | 45 | self::$upyun->write($filename, $f); |
@@ -50,8 +50,8 @@ discard block |
||
50 | 50 | public function testWriteWithAsyncProcess() { |
51 | 51 | $filename = 'test_async.jpeg'; |
52 | 52 | $newFilename = 'test_async.png'; |
53 | - $f = fopen(__DIR__ . '/assets/sample.jpeg', 'rb'); |
|
54 | - if(!$f) { |
|
53 | + $f = fopen(__DIR__.'/assets/sample.jpeg', 'rb'); |
|
54 | + if (!$f) { |
|
55 | 55 | throw new \Exception('open test file failed!'); |
56 | 56 | } |
57 | 57 | $result = self::$upyun->write($filename, $f, array( |
@@ -72,8 +72,8 @@ discard block |
||
72 | 72 | $fs = new Upyun(new Config(BUCKET, USER_NAME, 'error-password')); |
73 | 73 | try { |
74 | 74 | $fs->write('test.txt', 'test file content'); |
75 | - } catch(\Exception $e) { |
|
76 | - return ; |
|
75 | + } catch (\Exception $e) { |
|
76 | + return; |
|
77 | 77 | } |
78 | 78 | throw new \Exception('should get sign error.'); |
79 | 79 | } |
@@ -104,8 +104,8 @@ discard block |
||
104 | 104 | $r = self::$upyun->delete('test-delete.txt'); |
105 | 105 | try { |
106 | 106 | self::$upyun->read('test-delete.txt'); |
107 | - } catch(\Exception $e) { |
|
108 | - return ; |
|
107 | + } catch (\Exception $e) { |
|
108 | + return; |
|
109 | 109 | } |
110 | 110 | throw new \Exception('delete file failed'); |
111 | 111 | } |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | |
190 | 190 | public function testProcess() { |
191 | 191 | $source = 'php-sdk-sample.mp4'; |
192 | - self::$upyun->write($source, fopen(__DIR__ . '/assets/SampleVideo_640x360_1mb.mp4', 'r')); |
|
192 | + self::$upyun->write($source, fopen(__DIR__.'/assets/SampleVideo_640x360_1mb.mp4', 'r')); |
|
193 | 193 | $result = self::$upyun->process($source, array( |
194 | 194 | array('type' => 'video', 'avopts' => '/s/240p(4:3)/as/1/r/30', 'return_info' => true, 'save_as' => '/video/result.mp4') |
195 | 195 | )); |
@@ -3,5 +3,5 @@ |
||
3 | 3 | 'user_name' => 'tester', |
4 | 4 | 'pwd' => 'grjxv2mxELR3', |
5 | 5 | 'bucket' => 'sdkimg', |
6 | - 'picture_path' => dirname(__FILE__) . '/assets/sample.jpeg' |
|
6 | + 'picture_path' => dirname(__FILE__).'/assets/sample.jpeg' |
|
7 | 7 | ); |
8 | 8 | \ No newline at end of file |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | use Upyun\Signature; |
4 | 4 | use Upyun\Config; |
5 | 5 | |
6 | -class SignatureTest extends \PHPUnit_Framework_TestCase{ |
|
6 | +class SignatureTest extends \PHPUnit_Framework_TestCase { |
|
7 | 7 | |
8 | 8 | /** |
9 | 9 | * @var Config; |
@@ -16,6 +16,6 @@ discard block |
||
16 | 16 | |
17 | 17 | public function testGetSignature() { |
18 | 18 | $sign = Signature::getSignature($this->config, array('a' => 'a', 'b' => 'b'), Signature::SIGN_MULTIPART, '123'); |
19 | - $this->assertEquals($sign , '2aa0afd612df8fab4b3fded36c396234'); |
|
19 | + $this->assertEquals($sign, '2aa0afd612df8fab4b3fded36c396234'); |
|
20 | 20 | } |
21 | 21 | } |
22 | 22 | \ No newline at end of file |
@@ -1,15 +1,15 @@ discard block |
||
1 | 1 | <?php |
2 | -require dirname(__DIR__) . '/vendor/autoload.php'; |
|
3 | -$config = require_once __DIR__ . '/config.php'; |
|
2 | +require dirname(__DIR__).'/vendor/autoload.php'; |
|
3 | +$config = require_once __DIR__.'/config.php'; |
|
4 | 4 | |
5 | 5 | define('USER_NAME', $config['user_name']); |
6 | 6 | define('PWD', $config['pwd']); |
7 | 7 | define('BUCKET', $config['bucket']); |
8 | -define('PIC_PATH' , $config['picture_path']); |
|
9 | -define('PIC_SIZE' , filesize(PIC_PATH)); |
|
8 | +define('PIC_PATH', $config['picture_path']); |
|
9 | +define('PIC_SIZE', filesize(PIC_PATH)); |
|
10 | 10 | |
11 | 11 | function getFileUrl($path) { |
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) { |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | preg_match('~^HTTP/1.1 (\d{3})~', $return, $match1); |
23 | 23 | preg_match('~Content-Length: (\d+)~', $return, $match2); |
24 | 24 | |
25 | - if(isset($match1[1]) && $match1[1] == 200) { |
|
25 | + if (isset($match1[1]) && $match1[1] == 200) { |
|
26 | 26 | return isset($match2[1]) ? intval($match2[1]) : false; |
27 | 27 | } else { |
28 | 28 | return false; |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | use GuzzleHttp\Psr7; |
7 | 7 | use Upyun\Upyun; |
8 | 8 | |
9 | -class MultiTest extends \PHPUnit_Framework_TestCase{ |
|
9 | +class MultiTest extends \PHPUnit_Framework_TestCase { |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * @var Multi; |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | } |
21 | 21 | |
22 | 22 | public function testUpload() { |
23 | - $filePath = __DIR__ . '/../assets/sample.jpeg'; |
|
23 | + $filePath = __DIR__.'/../assets/sample.jpeg'; |
|
24 | 24 | $stream = Psr7\stream_for(fopen($filePath, 'rb')); |
25 | 25 | $r = $this->multiPart->upload('test-sample.jpeg', $stream, md5_file($filePath)); |
26 | 26 | $this->assertEquals($r->getStatusCode(), 200); |
@@ -82,17 +82,17 @@ discard block |
||
82 | 82 | /** |
83 | 83 | * 分块上传接口请求地址 |
84 | 84 | */ |
85 | - const ED_FORM = 'm0.api.upyun.com'; |
|
85 | + const ED_FORM = 'm0.api.upyun.com'; |
|
86 | 86 | |
87 | 87 | /** |
88 | 88 | * 异步云处理接口地址 |
89 | 89 | */ |
90 | - const ED_VIDEO = 'p0.api.upyun.com'; |
|
90 | + const ED_VIDEO = 'p0.api.upyun.com'; |
|
91 | 91 | |
92 | 92 | /** |
93 | 93 | * 刷新接口地址 |
94 | 94 | */ |
95 | - const ED_PURGE = 'http://purge.upyun.com/purge/'; |
|
95 | + const ED_PURGE = 'http://purge.upyun.com/purge/'; |
|
96 | 96 | |
97 | 97 | public function __construct($bucketName, $operatorName, $operatorPassword) { |
98 | 98 | $this->bucketName = $bucketName; |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | } |
108 | 108 | |
109 | 109 | public function getFormApiKey() { |
110 | - if(! $this->formApiKey) { |
|
110 | + if (!$this->formApiKey) { |
|
111 | 111 | throw new \Exception('form api key is empty.'); |
112 | 112 | } |
113 | 113 |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | * @throws \Exception 上传失败时,抛出异常 |
87 | 87 | */ |
88 | 88 | public function write($path, $content, $params = array(), $withAsyncProcess = false) { |
89 | - if(!$content) { |
|
89 | + if (!$content) { |
|
90 | 90 | throw new \Exception('write content can not be empty.'); |
91 | 91 | } |
92 | 92 | |
@@ -122,8 +122,8 @@ discard block |
||
122 | 122 | $params = Util::getHeaderParams($response->getHeaders()); |
123 | 123 | |
124 | 124 | |
125 | - if(! isset($params['x-upyun-list-iter'])) { |
|
126 | - if(is_resource($saveHandler)) { |
|
125 | + if (!isset($params['x-upyun-list-iter'])) { |
|
126 | + if (is_resource($saveHandler)) { |
|
127 | 127 | Psr7\copy_to_stream($response->getBody(), Psr7\stream_for($saveHandler)); |
128 | 128 | return true; |
129 | 129 | } else { |
@@ -150,9 +150,9 @@ discard block |
||
150 | 150 | try { |
151 | 151 | $req->request('HEAD', $path) |
152 | 152 | ->send(); |
153 | - } catch(GuzzleHttp\Exception\BadResponseException $e) { |
|
153 | + } catch (GuzzleHttp\Exception\BadResponseException $e) { |
|
154 | 154 | $statusCode = $e->getResponse()->getStatusCode(); |
155 | - if($statusCode === 404) { |
|
155 | + if ($statusCode === 404) { |
|
156 | 156 | return false; |
157 | 157 | } else { |
158 | 158 | throw $e; |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | public function delete($path, $async = false) { |
192 | 192 | $req = new Rest($this->config); |
193 | 193 | $req->request('DELETE', $path); |
194 | - if($async) { |
|
194 | + if ($async) { |
|
195 | 195 | $req->withHeader('x-upyun-async', 'true'); |
196 | 196 | } |
197 | 197 | $res = $req->send(); |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | * @throws \Exception |
208 | 208 | */ |
209 | 209 | public function createDir($path) { |
210 | - $path = rtrim($path, '/') . '/'; |
|
210 | + $path = rtrim($path, '/').'/'; |
|
211 | 211 | $req = new Rest($this->config); |
212 | 212 | $res = $req->request('POST', $path) |
213 | 213 | ->withHeader('folder', 'true') |
@@ -236,9 +236,9 @@ discard block |
||
236 | 236 | */ |
237 | 237 | public function usage($path = '/') { |
238 | 238 | |
239 | - $path = rtrim($path, '/') . '/'; |
|
239 | + $path = rtrim($path, '/').'/'; |
|
240 | 240 | $req = new Rest($this->config); |
241 | - $response = $req->request('GET', $path . '?usage') |
|
241 | + $response = $req->request('GET', $path.'?usage') |
|
242 | 242 | ->withHeader('folder', 'true') |
243 | 243 | ->send(); |
244 | 244 | |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | */ |
255 | 255 | public function purge($urls) { |
256 | 256 | $urlString = $urls; |
257 | - if(is_array($urls)) { |
|
257 | + if (is_array($urls)) { |
|
258 | 258 | $urlString = implode("\n", $urls); |
259 | 259 | } |
260 | 260 |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | 'accept' => 'json' |
32 | 32 | ); |
33 | 33 | |
34 | - $url = $this->url . '/pretreatment'; |
|
34 | + $url = $this->url.'/pretreatment'; |
|
35 | 35 | $signature = Signature::getSignature($this->config, $params, Signature::SIGN_VIDEO); |
36 | 36 | $response = $client->request('POST', $url, [ |
37 | 37 | 'headers' => array('Authorization' => "UPYUN {$this->config->operatorName}:$signature"), |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | 'task_ids' => implode(',', $taskIds) |
54 | 54 | ); |
55 | 55 | |
56 | - $url = $this->url . $path; |
|
56 | + $url = $this->url.$path; |
|
57 | 57 | $signature = Signature::getSignature($this->config, $params, Signature::SIGN_VIDEO); |
58 | 58 | $response = $client->request('GET', $url, [ |
59 | 59 | 'headers' => array('Authorization' => "UPYUN {$this->config->operatorName}:$signature"), |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | |
18 | 18 | public function __construct(Config $config) { |
19 | 19 | $this->config = $config; |
20 | - $this->url = ($this->config->useSsl ? 'https://' : 'http://') . Config::ED_FORM . '/'. |
|
20 | + $this->url = ($this->config->useSsl ? 'https://' : 'http://').Config::ED_FORM.'/'. |
|
21 | 21 | $this->config->bucketName; |
22 | 22 | } |
23 | 23 | |
@@ -31,20 +31,20 @@ discard block |
||
31 | 31 | * @throws \Exception |
32 | 32 | */ |
33 | 33 | public function upload($path, $stream, $fileHash, $params = []) { |
34 | - $path = '/' . ltrim($path, '/'); |
|
34 | + $path = '/'.ltrim($path, '/'); |
|
35 | 35 | $initInfo = $this->initRequest($path, $stream, $fileHash, $params); |
36 | 36 | $blockStatus = $initInfo->status; |
37 | 37 | |
38 | 38 | $newBlockStatus = $blockStatus; |
39 | 39 | |
40 | - for($blockId = 0; $blockId < $initInfo->blocks; $blockId++) { |
|
41 | - if($blockStatus[$blockId] === 0) { |
|
40 | + for ($blockId = 0; $blockId < $initInfo->blocks; $blockId++) { |
|
41 | + if ($blockStatus[$blockId] === 0) { |
|
42 | 42 | $return = $this->blockUpload($initInfo, $blockId, $stream); |
43 | 43 | $newBlockStatus = $return->status; |
44 | 44 | } |
45 | 45 | } |
46 | 46 | |
47 | - if(array_sum($newBlockStatus) === $initInfo->blocks) { |
|
47 | + if (array_sum($newBlockStatus) === $initInfo->blocks) { |
|
48 | 48 | return $this->endRequest($initInfo, $params); |
49 | 49 | } else { |
50 | 50 | throw new \Exception(sprintf("chunk upload failed! current every block status is : [%s]", implode(',', $newBlockStatus))); |
@@ -102,13 +102,13 @@ discard block |
||
102 | 102 | ); |
103 | 103 | |
104 | 104 | $multipart = []; |
105 | - foreach($postData as $key => $value) { |
|
105 | + foreach ($postData as $key => $value) { |
|
106 | 106 | $multipart[] = ['name' => $key, 'contents' => $value]; |
107 | 107 | } |
108 | 108 | $multipart[] = [ |
109 | 109 | 'name' => 'file', |
110 | 110 | 'contents' => $fileBlock, |
111 | - 'filename' => 'file', //this value must be file |
|
111 | + 'filename' => 'file', //this value must be file |
|
112 | 112 | 'headers' => ['Content-Type' => 'application/octet-stream'] |
113 | 113 | ]; |
114 | 114 | $postData['file'] = $fileBlock; |