@@ -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 |
@@ -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); |
@@ -31,9 +31,9 @@ |
||
31 | 31 | if(! $useBlock) { |
32 | 32 | $req = new Rest($this->config); |
33 | 33 | return $req->request('PUT', $path) |
34 | - ->withHeaders($params) |
|
35 | - ->withFile($stream) |
|
36 | - ->send(); |
|
34 | + ->withHeaders($params) |
|
35 | + ->withFile($stream) |
|
36 | + ->send(); |
|
37 | 37 | } else { |
38 | 38 | return $this->pointUpload($path, $stream, $params); |
39 | 39 | } |
@@ -28,7 +28,7 @@ discard block |
||
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) |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | $headers = array(); |
54 | 54 | if (is_array($params)) { |
55 | 55 | foreach ($params as $key => $val) { |
56 | - $headers['X-Upyun-Meta-' . $key] = $val; |
|
56 | + $headers['X-Upyun-Meta-'.$key] = $val; |
|
57 | 57 | } |
58 | 58 | } |
59 | 59 | $res = $req->request('PUT', $path) |
@@ -103,10 +103,10 @@ discard block |
||
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; |
@@ -111,7 +111,7 @@ |
||
111 | 111 | throw new \Exception('form api key is empty.'); |
112 | 112 | } |
113 | 113 | |
114 | - return $this->formApiKey; |
|
114 | + return $this->formApiKey; |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | public function setFormApiKey($key) { |
@@ -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 |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | $method = 'POST'; |
36 | 36 | $signedHeaders = Signature::getHeaderSign($this->config, $method, $path); |
37 | 37 | |
38 | - $response = $client->request($method, $this->url . $path, [ |
|
38 | + $response = $client->request($method, $this->url.$path, [ |
|
39 | 39 | 'headers' => $signedHeaders, |
40 | 40 | 'form_params' => $params |
41 | 41 | ]); |
@@ -54,10 +54,10 @@ discard block |
||
54 | 54 | 'service' => $this->config->bucketName, |
55 | 55 | 'task_ids' => implode(',', $taskIds) |
56 | 56 | ); |
57 | - $path = $path . '?' . http_build_query($params); |
|
57 | + $path = $path.'?'.http_build_query($params); |
|
58 | 58 | |
59 | 59 | $method = 'GET'; |
60 | - $url = $this->url . $path; |
|
60 | + $url = $this->url.$path; |
|
61 | 61 | $signedHeaders = Signature::getHeaderSign($this->config, $method, $path); |
62 | 62 | $response = $client->request($method, $url, [ |
63 | 63 | 'headers' => $signedHeaders |
@@ -10,15 +10,15 @@ discard block |
||
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 | * 获取 Header 签名需要的请求头 |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | $headers = array( |
40 | 40 | 'Authorization' => $sign, |
41 | 41 | 'Date' => $gmtDate, |
42 | - 'User-agent' => 'Php-Sdk/' . $bucketConfig->getVersion() |
|
42 | + 'User-agent' => 'Php-Sdk/'.$bucketConfig->getVersion() |
|
43 | 43 | ); |
44 | 44 | return $headers; |
45 | 45 | } |
@@ -58,7 +58,7 @@ discard block |
||
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 | |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | $data[] = $contentMd5; |
91 | 91 | } |
92 | 92 | $signature = base64_encode(hash_hmac('sha1', implode('&', $data), $bucketConfig->operatorPassword, true)); |
93 | - return 'UPYUN ' . $bucketConfig->operatorName . ':' . $signature; |
|
93 | + return 'UPYUN '.$bucketConfig->operatorName.':'.$signature; |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | public static function getSignature(Config $bucketConfig, $data, $type, $tokenSecret = '') { |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | $string .= $tokenSecret ? $tokenSecret : $bucketConfig->getFormApiKey(); |
109 | 109 | break; |
110 | 110 | case self::SIGN_VIDEO: |
111 | - $string = $bucketConfig->operatorName . $string . $bucketConfig->operatorPassword; |
|
111 | + $string = $bucketConfig->operatorName.$string.$bucketConfig->operatorPassword; |
|
112 | 112 | break; |
113 | 113 | case self::SIGN_VIDEO_NO_OPERATOR: |
114 | 114 | break; |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | use Upyun\Util; |
7 | 7 | use GuzzleHttp\Client; |
8 | 8 | |
9 | -class Form extends Rest{ |
|
9 | +class Form extends Rest { |
|
10 | 10 | |
11 | 11 | public function upload($path, $stream, $params) { |
12 | 12 | $params['save-key'] = $path; |
@@ -17,12 +17,12 @@ discard block |
||
17 | 17 | |
18 | 18 | $policy = Util::base64Json($params); |
19 | 19 | $method = 'POST'; |
20 | - $signature = Signature::getBodySignature($this->config, $method, '/' . $params['bucket'], null, $policy); |
|
20 | + $signature = Signature::getBodySignature($this->config, $method, '/'.$params['bucket'], null, $policy); |
|
21 | 21 | $client = new Client([ |
22 | 22 | 'timeout' => $this->config->timeout, |
23 | 23 | ]); |
24 | 24 | |
25 | - $url = ($this->config->useSsl ? 'https://' : 'http://') . $this->endpoint; |
|
25 | + $url = ($this->config->useSsl ? 'https://' : 'http://').$this->endpoint; |
|
26 | 26 | |
27 | 27 | $response = $client->request($method, $url, array( |
28 | 28 | 'multipart' => array( |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | class Util { |
4 | 4 | |
5 | 5 | public static function trim($str) { |
6 | - if(is_array($str)) { |
|
6 | + if (is_array($str)) { |
|
7 | 7 | return array_map(array('Util', 'trim'), $str); |
8 | 8 | } else { |
9 | 9 | return trim($str); |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | $params = []; |
15 | 15 | foreach ($headers as $header => $value) { |
16 | 16 | $header = strtolower($header); |
17 | - if(strpos($header, 'x-upyun-') !== false) { |
|
17 | + if (strpos($header, 'x-upyun-') !== false) { |
|
18 | 18 | $params[$header] = $value[0]; |
19 | 19 | } |
20 | 20 | } |
@@ -23,12 +23,12 @@ discard block |
||
23 | 23 | |
24 | 24 | public static function parseDir($body) { |
25 | 25 | $files = array(); |
26 | - if(!$body) { |
|
26 | + if (!$body) { |
|
27 | 27 | return array(); |
28 | 28 | } |
29 | 29 | |
30 | 30 | $lines = explode("\n", $body); |
31 | - foreach($lines as $line) { |
|
31 | + foreach ($lines as $line) { |
|
32 | 32 | $file = []; |
33 | 33 | list($file['name'], $file['type'], $file['size'], $file['time']) = explode("\t", $line, 4); |
34 | 34 | $files[] = $file; |
@@ -64,16 +64,16 @@ discard block |
||
64 | 64 | */ |
65 | 65 | public static function encodeURI($url) { |
66 | 66 | $unescaped = array( |
67 | - '%2D'=>'-','%5F'=>'_','%2E'=>'.','%21'=>'!', '%7E'=>'~', |
|
67 | + '%2D'=>'-', '%5F'=>'_', '%2E'=>'.', '%21'=>'!', '%7E'=>'~', |
|
68 | 68 | '%2A'=>'*', '%27'=>"'", '%28'=>'(', '%29'=>')' |
69 | 69 | ); |
70 | 70 | $reserved = array( |
71 | - '%3B'=>';','%2C'=>',','%2F'=>'/','%3F'=>'?','%3A'=>':', |
|
72 | - '%40'=>'@','%26'=>'&','%3D'=>'=','%2B'=>'+','%24'=>'$' |
|
71 | + '%3B'=>';', '%2C'=>',', '%2F'=>'/', '%3F'=>'?', '%3A'=>':', |
|
72 | + '%40'=>'@', '%26'=>'&', '%3D'=>'=', '%2B'=>'+', '%24'=>'$' |
|
73 | 73 | ); |
74 | 74 | $score = array( |
75 | 75 | '%23'=>'#' |
76 | 76 | ); |
77 | - return strtr(rawurlencode($url), array_merge($reserved,$unescaped,$score)); |
|
77 | + return strtr(rawurlencode($url), array_merge($reserved, $unescaped, $score)); |
|
78 | 78 | } |
79 | 79 | } |
@@ -3,7 +3,7 @@ |
||
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; |