Completed
Push — master ( bfc0cc...f0e226 )
by sabaku
04:05
created
tests/UpyunTest.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
         ));
Please login to merge, or discard this patch.
tests/config.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -3,5 +3,5 @@
 block discarded – undo
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
Please login to merge, or discard this patch.
tests/SignatureTest.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
Please login to merge, or discard this patch.
tests/bootstrap.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -1,15 +1,15 @@  discard block
 block discarded – undo
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
 block discarded – undo
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;
Please login to merge, or discard this patch.
tests/Api/MultiTest.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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);
Please login to merge, or discard this patch.
src/Upyun/Uploader.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
             return $req->upload($path, $stream, $params);
29 29
         }
30 30
 
31
-        if(! $useBlock) {
31
+        if (!$useBlock) {
32 32
             $req = new Rest($this->config);
33 33
             return $req->request('PUT', $path)
34 34
                        ->withHeaders($params)
@@ -52,8 +52,8 @@  discard block
 block discarded – undo
52 52
         $req = new Rest($this->config);
53 53
         $headers = array();
54 54
         if (is_array($params)) {
55
-            foreach($params as $key => $val) {
56
-                $headers['X-Upyun-Meta-' . $key] = $val;
55
+            foreach ($params as $key => $val) {
56
+                $headers['X-Upyun-Meta-'.$key] = $val;
57 57
             }
58 58
         }
59 59
         $res = $req->request('PUT', $path)
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
             }
88 88
             $data   = Util::getHeaderParams($res->getHeaders());
89 89
             $partId = $data['x-upyun-next-part-id'];
90
-        } while($partId != -1);
90
+        } while ($partId != -1);
91 91
 
92 92
         $res = $req->request('PUT', $path)
93 93
             ->withHeaders(array(
@@ -103,10 +103,10 @@  discard block
 block discarded – undo
103 103
     }
104 104
 
105 105
     private function needUseBlock($fileSize) {
106
-        if($this->config->uploadType === 'BLOCK') {
106
+        if ($this->config->uploadType === 'BLOCK') {
107 107
             return true;
108
-        } else if($this->config->uploadType === 'AUTO' &&
109
-                  $fileSize >= $this->config->sizeBoundary ) {
108
+        } else if ($this->config->uploadType === 'AUTO' &&
109
+                  $fileSize >= $this->config->sizeBoundary) {
110 110
             return true;
111 111
         } else {
112 112
             return false;
Please login to merge, or discard this patch.
src/Upyun/Config.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -82,17 +82,17 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
src/Upyun/Signature.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -10,15 +10,15 @@  discard block
 block discarded – undo
10 10
     /**
11 11
      * 获取分块上传接口的签名
12 12
      */
13
-    const SIGN_MULTIPART     = 1;
13
+    const SIGN_MULTIPART = 1;
14 14
     /**
15 15
      * 生成视频处理接口的签名
16 16
      */
17
-    const SIGN_VIDEO         = 2;
17
+    const SIGN_VIDEO = 2;
18 18
     /**
19 19
      * 生成视频处理接口的签名(不需要操作员时使用)
20 20
      */
21
-    const SIGN_VIDEO_NO_OPERATOR   = 3;
21
+    const SIGN_VIDEO_NO_OPERATOR = 3;
22 22
 
23 23
     /**
24 24
      * 获取 RESET API 请求需要的签名头
@@ -32,14 +32,14 @@  discard block
 block discarded – undo
32 32
      */
33 33
     public static function getRestApiSignHeader($bucketConfig, $method, $remotePath, $contentLength) {
34 34
         $gmtDate = gmdate('D, d M Y H:i:s \G\M\T');
35
-        $path = '/' . $bucketConfig->bucketName . '/' . ltrim($remotePath, '/');
35
+        $path = '/'.$bucketConfig->bucketName.'/'.ltrim($remotePath, '/');
36 36
 
37 37
         $sign = md5("$method&$path&$gmtDate&$contentLength&{$bucketConfig->operatorPassword}");
38 38
 
39 39
         $headers = array(
40 40
             'Authorization' => "UpYun {$bucketConfig->operatorName}:$sign",
41 41
             'Date' => $gmtDate,
42
-            'User-agent' => 'Php-Sdk/' . $bucketConfig->getVersion() . ' (rest api)'
42
+            'User-agent' => 'Php-Sdk/'.$bucketConfig->getVersion().' (rest api)'
43 43
         );
44 44
         return $headers;
45 45
     }
@@ -52,42 +52,42 @@  discard block
 block discarded – undo
52 52
      *
53 53
      * @return array
54 54
      */
55
-    public static function getPurgeSignHeader( Config $bucketConfig, $urlString) {
55
+    public static function getPurgeSignHeader(Config $bucketConfig, $urlString) {
56 56
         $gmtDate = gmdate('D, d M Y H:i:s \G\M\T');
57 57
         $sign = md5("$urlString&{$bucketConfig->bucketName}&$gmtDate&{$bucketConfig->operatorPassword}");
58 58
         return array(
59 59
             'Authorization' => "UpYun {$bucketConfig->bucketName}:{$bucketConfig->operatorName}:$sign",
60 60
             'Date' => $gmtDate,
61
-            'User-agent' => 'Php-Sdk/' . $bucketConfig->getVersion() . ' (purge api)'
61
+            'User-agent' => 'Php-Sdk/'.$bucketConfig->getVersion().' (purge api)'
62 62
         );
63 63
     }
64 64
 
65 65
     public static function getFormSignature(Config $bucketConfig, $data) {
66 66
         $data['bucket'] = $bucketConfig->bucketName;
67 67
         $policy = Util::base64Json($data);
68
-        $signature = md5($policy . '&' . $bucketConfig->getFormApiKey());
68
+        $signature = md5($policy.'&'.$bucketConfig->getFormApiKey());
69 69
         return array(
70 70
             'policy' => $policy,
71 71
             'signature' => $signature
72 72
         );
73 73
     }
74 74
 
75
-    public static function getSignature( Config $bucketConfig, $data, $type, $tokenSecret = '') {
76
-        if(is_array($data)) {
75
+    public static function getSignature(Config $bucketConfig, $data, $type, $tokenSecret = '') {
76
+        if (is_array($data)) {
77 77
             ksort($data);
78 78
             $string = '';
79
-            foreach($data as $k => $v) {
80
-                if(is_array($v)) {
79
+            foreach ($data as $k => $v) {
80
+                if (is_array($v)) {
81 81
                     $v = implode('', $v);
82 82
                 }
83 83
                 $string .= "$k$v";
84 84
             }
85
-            switch($type) {
85
+            switch ($type) {
86 86
                 case self::SIGN_MULTIPART:
87 87
                     $string .= $tokenSecret ? $tokenSecret : $bucketConfig->getFormApiKey();
88 88
                     break;
89 89
                 case self::SIGN_VIDEO:
90
-                    $string = $bucketConfig->operatorName . $string . $bucketConfig->operatorPassword;
90
+                    $string = $bucketConfig->operatorName.$string.$bucketConfig->operatorPassword;
91 91
                     break;
92 92
                 case self::SIGN_VIDEO_NO_OPERATOR:
93 93
                     break;
Please login to merge, or discard this patch.
src/Upyun/Upyun.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.