Skip to content

Commit a38d9dd

Browse files
committed
fix format error
1 parent 2beeb94 commit a38d9dd

11 files changed

+43
-46
lines changed

src/Upyun/Api/Multi.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ public function upload($path, $stream, $fileHash, $params = []) {
3737

3838
$newBlockStatus = $blockStatus;
3939

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) {
4242
$return = $this->blockUpload($initInfo, $blockId, $stream);
4343
$newBlockStatus = $return->status;
4444
}
4545
}
4646

47-
if(array_sum($newBlockStatus) === $initInfo->blocks) {
47+
if (array_sum($newBlockStatus) === $initInfo->blocks) {
4848
return $this->endRequest($initInfo, $params);
4949
} else {
5050
throw new \Exception(sprintf("chunk upload failed! current every block status is : [%s]", implode(',', $newBlockStatus)));
@@ -93,6 +93,7 @@ private function blockUpload($blocksInfo, $blockId, Psr7\Stream $stream, $params
9393
'block_hash' => md5($fileBlock),
9494
);
9595
$metaData = array_merge($metaData, $params);
96+
$postData = array();
9697
$postData['policy'] = Util::base64Json($metaData);
9798
$postData['signature'] = Signature::getSignature(
9899
$this->config,
@@ -102,7 +103,7 @@ private function blockUpload($blocksInfo, $blockId, Psr7\Stream $stream, $params
102103
);
103104

104105
$multipart = [];
105-
foreach($postData as $key => $value) {
106+
foreach ($postData as $key => $value) {
106107
$multipart[] = ['name' => $key, 'contents' => $value];
107108
}
108109
$multipart[] = [
@@ -122,6 +123,7 @@ private function blockUpload($blocksInfo, $blockId, Psr7\Stream $stream, $params
122123
}
123124

124125
private function endRequest($initInfo, $data = array()) {
126+
$metaData = array();
125127
$metaData['save_token'] = $initInfo->save_token;
126128
$metaData['expiration'] = $initInfo->expired_at;
127129

src/Upyun/Api/Pretreat.php

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010

1111
class Pretreat {
1212

13+
/**
14+
* @var Config
15+
*/
16+
protected $config;
17+
1318
protected $url = 'http://p0.api.upyun.com';
1419

1520
public function __construct(Config $config) {

src/Upyun/Api/Rest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function send() {
5959

6060
$url = ($this->config->useSsl ? 'https://' : 'http://') . $this->endpoint . $this->storagePath;
6161
$body = null;
62-
if($this->file && $this->method === 'PUT') {
62+
if ($this->file && $this->method === 'PUT') {
6363
$body = $this->file;
6464
}
6565

@@ -73,7 +73,7 @@ public function send() {
7373
$this->method,
7474
$request->getUri()->getPath()
7575
);
76-
foreach($authHeader as $head => $value) {
76+
foreach ($authHeader as $head => $value) {
7777
$request = $request->withHeader($head, $value);
7878
}
7979
$response = $client->send($request, [
@@ -91,7 +91,7 @@ public function withHeader($header, $value) {
9191
}
9292

9393
public function withHeaders($headers) {
94-
if(is_array($headers)) {
94+
if (is_array($headers)) {
9595
foreach ($headers as $header => $value) {
9696
$this->withHeader($header, $value);
9797
}

src/Upyun/Config.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class Config {
7373
/**
7474
* @var string rest api 和 form api 的接口地址
7575
*/
76-
static $restApiEndPoint;
76+
public static $restApiEndPoint;
7777

7878

7979
/**
@@ -112,7 +112,7 @@ public function setOperatorPassword($operatorPassword) {
112112
}
113113

114114
public function getFormApiKey() {
115-
if(! $this->formApiKey) {
115+
if (! $this->formApiKey) {
116116
throw new \Exception('form api key is empty.');
117117
}
118118

src/Upyun/Uploader.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function upload($path, $file, $params, $withAsyncProcess) {
2828
return $req->upload($path, $stream, $params);
2929
}
3030

31-
if(! $useBlock) {
31+
if (! $useBlock) {
3232
$req = new Rest($this->config);
3333
return $req->request('PUT', $path)
3434
->withHeaders($params)
@@ -103,9 +103,9 @@ private function pointUpload($path, $stream, $params) {
103103
}
104104

105105
private function needUseBlock($fileSize) {
106-
if($this->config->uploadType === 'BLOCK') {
106+
if ($this->config->uploadType === 'BLOCK') {
107107
return true;
108-
} else if($this->config->uploadType === 'AUTO' &&
108+
} else if ($this->config->uploadType === 'AUTO' &&
109109
$fileSize >= $this->config->sizeBoundary ) {
110110
return true;
111111
} else {

src/Upyun/Upyun.php

+8-10
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function setConfig(Config $config) {
8585
* @throws \Exception 上传失败时,抛出异常
8686
*/
8787
public function write($path, $content, $params = array(), $withAsyncProcess = false) {
88-
if(!$content) {
88+
if (!$content) {
8989
throw new \Exception('write content can not be empty.');
9090
}
9191

@@ -111,7 +111,7 @@ public function write($path, $content, $params = array(), $withAsyncProcess = fa
111111
*
112112
* @throws \Exception
113113
*/
114-
public function read($path, $saveHandler = NULL, $params = array()) {
114+
public function read($path, $saveHandler = null, $params = array()) {
115115
$req = new Rest($this->config);
116116
$response = $req->request('GET', $path)
117117
->withHeaders($params)
@@ -121,8 +121,8 @@ public function read($path, $saveHandler = NULL, $params = array()) {
121121
$params = Util::getHeaderParams($response->getHeaders());
122122

123123

124-
if(! isset($params['x-upyun-list-iter'])) {
125-
if(is_resource($saveHandler)) {
124+
if (! isset($params['x-upyun-list-iter'])) {
125+
if (is_resource($saveHandler)) {
126126
Psr7\copy_to_stream($response->getBody(), Psr7\stream_for($saveHandler));
127127
return true;
128128
} else {
@@ -149,9 +149,9 @@ public function has($path) {
149149
try {
150150
$req->request('HEAD', $path)
151151
->send();
152-
} catch(GuzzleHttp\Exception\BadResponseException $e) {
152+
} catch (GuzzleHttp\Exception\BadResponseException $e) {
153153
$statusCode = $e->getResponse()->getStatusCode();
154-
if($statusCode === 404) {
154+
if ($statusCode === 404) {
155155
return false;
156156
} else {
157157
throw $e;
@@ -190,7 +190,7 @@ public function info($path) {
190190
public function delete($path, $async = false) {
191191
$req = new Rest($this->config);
192192
$req->request('DELETE', $path);
193-
if($async) {
193+
if ($async) {
194194
$req->withHeader('x-upyun-async', 'true');
195195
}
196196
$res = $req->send();
@@ -234,11 +234,9 @@ public function deleteDir($path) {
234234
* @throws \Exception
235235
*/
236236
public function usage($path = '/') {
237-
238237
$path = rtrim($path, '/') . '/';
239238
$req = new Rest($this->config);
240239
$response = $req->request('GET', $path . '?usage')
241-
->withHeader('folder', 'true')
242240
->send();
243241

244242
return $response->getBody()->getContents();
@@ -253,7 +251,7 @@ public function usage($path = '/') {
253251
*/
254252
public function purge($urls) {
255253
$urlString = $urls;
256-
if(is_array($urls)) {
254+
if (is_array($urls)) {
257255
$urlString = implode("\n", $urls);
258256
}
259257

src/Upyun/Util.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
class Util {
44

55
public static function trim($str) {
6-
if(is_array($str)) {
6+
if (is_array($str)) {
77
return array_map(array('Util', 'trim'), $str);
88
} else {
99
return trim($str);
@@ -14,7 +14,7 @@ public static function getHeaderParams($headers) {
1414
$params = [];
1515
foreach ($headers as $header => $value) {
1616
$header = strtolower($header);
17-
if(strpos($header, 'x-upyun-') !== false) {
17+
if (strpos($header, 'x-upyun-') !== false) {
1818
$params[$header] = $value[0];
1919
}
2020
}
@@ -23,12 +23,12 @@ public static function getHeaderParams($headers) {
2323

2424
public static function parseDir($body) {
2525
$files = array();
26-
if(!$body) {
26+
if (!$body) {
2727
return array();
2828
}
2929

3030
$lines = explode("\n", $body);
31-
foreach($lines as $line) {
31+
foreach ($lines as $line) {
3232
$file = [];
3333
list($file['name'], $file['type'], $file['size'], $file['time']) = explode("\t", $line, 4);
3434
$files[] = $file;

tests/SignatureTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public function setUp() {
1616

1717
public function testGetSignature() {
1818
$sign = Signature::getSignature($this->config, array('a' => 'a', 'b' => 'b'), Signature::SIGN_MULTIPART, '123');
19-
$this->assertEquals($sign , '2aa0afd612df8fab4b3fded36c396234');
19+
$this->assertEquals($sign, '2aa0afd612df8fab4b3fded36c396234');
2020
}
2121

2222
public function testGetBodySignature() {

tests/UpyunTest.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function testWriteString() {
3939
public function testWriteStream() {
4040
$filename = 'test.jpeg';
4141
$f = fopen(__DIR__ . '/assets/sample.jpeg', 'rb');
42-
if(!$f) {
42+
if (!$f) {
4343
throw new \Exception('open test file failed!');
4444
}
4545
self::$upyun->write($filename, $f);
@@ -51,7 +51,7 @@ public function testWriteWithAsyncProcess() {
5151
$filename = 'test_async.jpeg';
5252
$newFilename = 'test_async.png';
5353
$f = fopen(__DIR__ . '/assets/sample.jpeg', 'rb');
54-
if(!$f) {
54+
if (!$f) {
5555
throw new \Exception('open test file failed!');
5656
}
5757
$result = self::$upyun->write($filename, $f, array(
@@ -72,7 +72,7 @@ public function testWriteWithException() {
7272
$fs = new Upyun(new Config(BUCKET, USER_NAME, 'error-password'));
7373
try {
7474
$fs->write('test.txt', 'test file content');
75-
} catch(\Exception $e) {
75+
} catch (\Exception $e) {
7676
return ;
7777
}
7878
throw new \Exception('should get sign error.');
@@ -101,10 +101,10 @@ public function testReadFile() {
101101
*/
102102
public function testDeleteFile() {
103103
self::$upyun->write('test-delete.txt', 'test file content 3');
104-
$r = self::$upyun->delete('test-delete.txt');
104+
self::$upyun->delete('test-delete.txt');
105105
try {
106106
self::$upyun->read('test-delete.txt');
107-
} catch(\Exception $e) {
107+
} catch (\Exception $e) {
108108
return ;
109109
}
110110
throw new \Exception('delete file failed');

tests/bootstrap.php

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
<?php
22
require dirname(__DIR__) . '/vendor/autoload.php';
3-
$config = require_once __DIR__ . '/config.php';
43

5-
define('USER_NAME', $config['user_name']);
6-
define('PWD', $config['pwd']);
7-
define('BUCKET', $config['bucket']);
8-
define('PIC_PATH' , $config['picture_path']);
9-
define('PIC_SIZE' , filesize(PIC_PATH));
4+
define('USER_NAME', 'tester');
5+
define('PWD', 'grjxv2mxELR3');
6+
define('BUCKET', 'sdkimg');
7+
define('PIC_PATH', dirname(__FILE__) . '/assets/sample.jpeg');
8+
define('PIC_SIZE', filesize(PIC_PATH));
109

1110
function getFileUrl($path) {
1211
return "http://" . BUCKET . ".b0.upaiyun.com/" . ltrim($path, '/');
@@ -22,7 +21,7 @@ function getUpyunFileSize($path) {
2221
preg_match('~^HTTP/1.1 (\d{3})~', $return, $match1);
2322
preg_match('~Content-Length: (\d+)~', $return, $match2);
2423

25-
if(isset($match1[1]) && $match1[1] == 200) {
24+
if (isset($match1[1]) && $match1[1] == 200) {
2625
return isset($match2[1]) ? intval($match2[1]) : false;
2726
} else {
2827
return false;

tests/config.php

-7
This file was deleted.

0 commit comments

Comments
 (0)