@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | { |
| 29 | 29 | if (Pregs::isLink($url)) { |
| 30 | 30 | $this->url = $url; |
| 31 | - } else { |
|
| 31 | + }else { |
|
| 32 | 32 | preg_match_all('#\bhttps?://[^,\s()<>]+(?:\([\w\d]+\)|([^,[:punct:]\s]|/))#', $url, $match); |
| 33 | 33 | $this->url = $match[0][0]; |
| 34 | 34 | } |
@@ -90,17 +90,17 @@ discard block |
||
| 90 | 90 | 'Connection' => 'keep-alive', |
| 91 | 91 | 'User-Agent' => 'Mozilla/5.0 (iPhone; CPU iPhone OS 12_1_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/16D57 Version/12.0 Safari/604.1' |
| 92 | 92 | ]; |
| 93 | - $client = new Client(['timeout' => 2, 'headers' => $headers, 'http_errors' => false,]); |
|
| 93 | + $client = new Client(['timeout' => 2, 'headers' => $headers, 'http_errors' => false, ]); |
|
| 94 | 94 | $data = []; |
| 95 | 95 | if ($headers) { |
| 96 | 96 | $data['headers'] = $headers; |
| 97 | 97 | } |
| 98 | - $data['verify'] = __DIR__ . DIRECTORY_SEPARATOR . 'cacert.pem'; |
|
| 98 | + $data['verify'] = __DIR__.DIRECTORY_SEPARATOR.'cacert.pem'; |
|
| 99 | 99 | $jar = new CookieJar; |
| 100 | 100 | $data['cookies'] = $jar; |
| 101 | 101 | if (!$params) { |
| 102 | 102 | $response = $client->request('GET', $url, $data); |
| 103 | - } else { |
|
| 103 | + }else { |
|
| 104 | 104 | $data ['form_params'] = $params; |
| 105 | 105 | $response = $client->request('POST', $url, $data); |
| 106 | 106 | } |
@@ -34,16 +34,16 @@ discard block |
||
| 34 | 34 | define("KS3_API_Author", "[email protected]"); |
| 35 | 35 | define("KS3_API_Version", "1.2"); |
| 36 | 36 | |
| 37 | -require_once KS3_API_PATH . DIRECTORY_SEPARATOR . "config" . DIRECTORY_SEPARATOR . "Consts.php"; |
|
| 38 | -require_once KS3_API_PATH . DIRECTORY_SEPARATOR . "core" . DIRECTORY_SEPARATOR . "API.php"; |
|
| 39 | -require_once KS3_API_PATH . DIRECTORY_SEPARATOR . "core" . DIRECTORY_SEPARATOR . "Signers.php"; |
|
| 40 | -require_once KS3_API_PATH . DIRECTORY_SEPARATOR . "core" . DIRECTORY_SEPARATOR . "Ks3Request.class.php"; |
|
| 41 | -require_once KS3_API_PATH . DIRECTORY_SEPARATOR . "core" . DIRECTORY_SEPARATOR . "Handlers.php"; |
|
| 42 | -require_once KS3_API_PATH . DIRECTORY_SEPARATOR . "core" . DIRECTORY_SEPARATOR . "Builders.php"; |
|
| 43 | -require_once KS3_API_PATH . DIRECTORY_SEPARATOR . "core" . DIRECTORY_SEPARATOR . "Logger.php"; |
|
| 44 | -require_once KS3_API_PATH . DIRECTORY_SEPARATOR . "core" . DIRECTORY_SEPARATOR . "MessageHolder.php"; |
|
| 45 | -require_once KS3_API_PATH . DIRECTORY_SEPARATOR . "lib" . DIRECTORY_SEPARATOR . "RequestCore.class.php"; |
|
| 46 | -require_once KS3_API_PATH . DIRECTORY_SEPARATOR . "exceptions" . DIRECTORY_SEPARATOR . "Exceptions.php"; |
|
| 37 | +require_once KS3_API_PATH.DIRECTORY_SEPARATOR."config".DIRECTORY_SEPARATOR."Consts.php"; |
|
| 38 | +require_once KS3_API_PATH.DIRECTORY_SEPARATOR."core".DIRECTORY_SEPARATOR."API.php"; |
|
| 39 | +require_once KS3_API_PATH.DIRECTORY_SEPARATOR."core".DIRECTORY_SEPARATOR."Signers.php"; |
|
| 40 | +require_once KS3_API_PATH.DIRECTORY_SEPARATOR."core".DIRECTORY_SEPARATOR."Ks3Request.class.php"; |
|
| 41 | +require_once KS3_API_PATH.DIRECTORY_SEPARATOR."core".DIRECTORY_SEPARATOR."Handlers.php"; |
|
| 42 | +require_once KS3_API_PATH.DIRECTORY_SEPARATOR."core".DIRECTORY_SEPARATOR."Builders.php"; |
|
| 43 | +require_once KS3_API_PATH.DIRECTORY_SEPARATOR."core".DIRECTORY_SEPARATOR."Logger.php"; |
|
| 44 | +require_once KS3_API_PATH.DIRECTORY_SEPARATOR."core".DIRECTORY_SEPARATOR."MessageHolder.php"; |
|
| 45 | +require_once KS3_API_PATH.DIRECTORY_SEPARATOR."lib".DIRECTORY_SEPARATOR."RequestCore.class.php"; |
|
| 46 | +require_once KS3_API_PATH.DIRECTORY_SEPARATOR."exceptions".DIRECTORY_SEPARATOR."Exceptions.php"; |
|
| 47 | 47 | |
| 48 | 48 | if (function_exists('get_loaded_extensions')) { |
| 49 | 49 | //检测curl扩展 |
@@ -56,10 +56,10 @@ discard block |
||
| 56 | 56 | throw new Ks3ClientException("please install mbstring extension"); |
| 57 | 57 | |
| 58 | 58 | } |
| 59 | - } else { |
|
| 59 | + }else { |
|
| 60 | 60 | throw new Ks3ClientException("please install extensions"); |
| 61 | 61 | } |
| 62 | -} else { |
|
| 62 | +}else { |
|
| 63 | 63 | throw new Ks3ClientException(); |
| 64 | 64 | } |
| 65 | 65 | |
@@ -128,12 +128,12 @@ discard block |
||
| 128 | 128 | $holder = new MessageHolder(); |
| 129 | 129 | |
| 130 | 130 | $holder->msg = "------------------Logging Start-------------------------\r\n"; |
| 131 | - $holder->msg .= "method->" . $method . " args->" . serialize($args) . "\r\n"; |
|
| 131 | + $holder->msg .= "method->".$method." args->".serialize($args)."\r\n"; |
|
| 132 | 132 | $ex = NULL; |
| 133 | 133 | try { |
| 134 | 134 | $result = $this->invoke($method, $args, $holder); |
| 135 | 135 | } catch (Exception $e) { |
| 136 | - $holder->msg .= $e . "\r\n"; |
|
| 136 | + $holder->msg .= $e."\r\n"; |
|
| 137 | 137 | $ex = $e; |
| 138 | 138 | } |
| 139 | 139 | $holder->msg .= "------------------Logging End-------------------------\r\n"; |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | { |
| 149 | 149 | $api = API::$API[$method]; |
| 150 | 150 | if (!$api) { |
| 151 | - throw new Ks3ClientException($method . " Not Found API"); |
|
| 151 | + throw new Ks3ClientException($method." Not Found API"); |
|
| 152 | 152 | } |
| 153 | 153 | if (count($args) !== 0) { |
| 154 | 154 | if (count($args) > 1 || !is_array($args[0])) { |
@@ -162,20 +162,20 @@ discard block |
||
| 162 | 162 | $request = new Ks3Request(); |
| 163 | 163 | if (empty($args["Bucket"])) { |
| 164 | 164 | if ($api["needBucket"]) { |
| 165 | - throw new Ks3ClientException($method . " this api need bucket"); |
|
| 165 | + throw new Ks3ClientException($method." this api need bucket"); |
|
| 166 | 166 | } |
| 167 | - } else { |
|
| 167 | + }else { |
|
| 168 | 168 | $request->bucket = $args["Bucket"]; |
| 169 | 169 | } |
| 170 | 170 | $position = $api["objectPostion"] ?? "Key"; |
| 171 | 171 | if (empty($args[$position])) { |
| 172 | 172 | if ($api["needObject"]) { |
| 173 | - throw new Ks3ClientException($method . " this api need " . $position); |
|
| 173 | + throw new Ks3ClientException($method." this api need ".$position); |
|
| 174 | 174 | } |
| 175 | - } else { |
|
| 175 | + }else { |
|
| 176 | 176 | $key = $args[$position]; |
| 177 | 177 | $preEncoding = mb_detect_encoding($key, array("ASCII", "UTF-8", "GB2312", "GBK", "BIG5")); |
| 178 | - $holder->msg .= "key encoding " . $preEncoding . "\r\n"; |
|
| 178 | + $holder->msg .= "key encoding ".$preEncoding."\r\n"; |
|
| 179 | 179 | if (strtolower($preEncoding) !== "utf-8") { |
| 180 | 180 | $key = iconv($preEncoding, "UTF-8", $key); |
| 181 | 181 | } |
@@ -185,10 +185,10 @@ discard block |
||
| 185 | 185 | if ($method === "Method") { |
| 186 | 186 | if (empty($args["Method"])) { |
| 187 | 187 | $request->method = "GET"; |
| 188 | - } else { |
|
| 188 | + }else { |
|
| 189 | 189 | $request->method = $args["Method"]; |
| 190 | 190 | } |
| 191 | - } else { |
|
| 191 | + }else { |
|
| 192 | 192 | $request->method = $api["method"]; |
| 193 | 193 | } |
| 194 | 194 | if (KS3_API_USE_HTTPS) { |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | foreach ($index as $key1 => $value1) { |
| 218 | 218 | if (!isset($curIndexArg[$value1]) && $value1 !== "*") { |
| 219 | 219 | $add = FALSE; |
| 220 | - } else { |
|
| 220 | + }else { |
|
| 221 | 221 | $curkey = $value1; |
| 222 | 222 | //星号表示所有,按照暂时的业务,默认星号后面就没了 |
| 223 | 223 | if ($curkey === "*") { |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | continue; |
| 240 | 240 | } |
| 241 | 241 | if ($required) { |
| 242 | - throw new Ks3ClientException($method . " param " . $value . " is required"); |
|
| 242 | + throw new Ks3ClientException($method." param ".$value." is required"); |
|
| 243 | 243 | } |
| 244 | 244 | } |
| 245 | 245 | } |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | $builderName = $api["body"]["builder"]; |
| 249 | 249 | $builder = new $builderName(); |
| 250 | 250 | $request->body = $builder->build($args); |
| 251 | - } else if (isset($api["body"]["position"])) { |
|
| 251 | + }else if (isset($api["body"]["position"])) { |
|
| 252 | 252 | $position = $api["body"]["position"]; |
| 253 | 253 | $index = explode("->", $position); |
| 254 | 254 | $curIndexArg = $args; |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | foreach ($index as $key1 => $value1) { |
| 258 | 258 | if (!isset($curIndexArg[$value1])) { |
| 259 | 259 | $add = FALSE; |
| 260 | - } else { |
|
| 260 | + }else { |
|
| 261 | 261 | $curIndexArg = $curIndexArg[$value1]; |
| 262 | 262 | $curkey = $value1; |
| 263 | 263 | } |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | $signer = new $value(); |
| 279 | 279 | $log = $signer->sign($request, array("accessKey" => $this->accessKey, "secretKey" => $this->secretKey, "args" => $args)); |
| 280 | 280 | if (!empty($log)) { |
| 281 | - $holder->msg .= $log . "\r\n"; |
|
| 281 | + $holder->msg .= $log."\r\n"; |
|
| 282 | 282 | } |
| 283 | 283 | } |
| 284 | 284 | } |
@@ -318,31 +318,31 @@ discard block |
||
| 318 | 318 | $httpRequest->set_write_stream($write_stream); |
| 319 | 319 | } |
| 320 | 320 | |
| 321 | - $holder->msg .= "request url->" . serialize($httpRequest->request_url) . "\r\n"; |
|
| 322 | - $holder->msg .= "request headers->" . serialize($httpRequest->request_headers) . "\r\n"; |
|
| 323 | - $holder->msg .= "request body->" . $httpRequest->request_body . "\r\n"; |
|
| 324 | - $holder->msg .= "request read stream length->" . $read_length . "\r\n"; |
|
| 325 | - $holder->msg .= "request read stream seek position->" . $seek_position . "\r\n"; |
|
| 321 | + $holder->msg .= "request url->".serialize($httpRequest->request_url)."\r\n"; |
|
| 322 | + $holder->msg .= "request headers->".serialize($httpRequest->request_headers)."\r\n"; |
|
| 323 | + $holder->msg .= "request body->".$httpRequest->request_body."\r\n"; |
|
| 324 | + $holder->msg .= "request read stream length->".$read_length."\r\n"; |
|
| 325 | + $holder->msg .= "request read stream seek position->".$seek_position."\r\n"; |
|
| 326 | 326 | $httpRequest->send_request(); |
| 327 | 327 | //print_r($httpRequest); |
| 328 | 328 | $body = $httpRequest->get_response_body(); |
| 329 | - $data = new ResponseCore ($httpRequest->get_response_header(), Utils::replaceNS2($body), $httpRequest->get_response_code()); |
|
| 329 | + $data = new ResponseCore($httpRequest->get_response_header(), Utils::replaceNS2($body), $httpRequest->get_response_code()); |
|
| 330 | 330 | |
| 331 | 331 | if ($data->status == 307) { |
| 332 | 332 | $respHeaders = $httpRequest->get_response_header(); |
| 333 | 333 | $location = $respHeaders["location"]; |
| 334 | 334 | if (strpos($location, "http") === 0) { |
| 335 | - $holder->msg .= "response code->" . $httpRequest->get_response_code() . "\r\n"; |
|
| 336 | - $holder->msg .= "response headers->" . serialize($httpRequest->get_response_header()) . "\r\n"; |
|
| 337 | - $holder->msg .= "response body->" . $body . "\r\n"; |
|
| 338 | - $holder->msg .= "retry request to " . $location . "\r\n"; |
|
| 335 | + $holder->msg .= "response code->".$httpRequest->get_response_code()."\r\n"; |
|
| 336 | + $holder->msg .= "response headers->".serialize($httpRequest->get_response_header())."\r\n"; |
|
| 337 | + $holder->msg .= "response body->".$body."\r\n"; |
|
| 338 | + $holder->msg .= "retry request to ".$location."\r\n"; |
|
| 339 | 339 | //array($args)详见invoke开头 |
| 340 | 340 | return $this->invoke($method, array($args), $holder, $location); |
| 341 | 341 | } |
| 342 | 342 | } |
| 343 | - $holder->msg .= "response code->" . $httpRequest->get_response_code() . "\r\n"; |
|
| 344 | - $holder->msg .= "response headers->" . serialize($httpRequest->get_response_header()) . "\r\n"; |
|
| 345 | - $holder->msg .= "response body->" . $body . "\r\n"; |
|
| 343 | + $holder->msg .= "response code->".$httpRequest->get_response_code()."\r\n"; |
|
| 344 | + $holder->msg .= "response headers->".serialize($httpRequest->get_response_header())."\r\n"; |
|
| 345 | + $holder->msg .= "response body->".$body."\r\n"; |
|
| 346 | 346 | $handlers = explode("->", $api["handler"]); |
| 347 | 347 | foreach ($handlers as $key => $value) { |
| 348 | 348 | $handler = new $value(); |
@@ -352,7 +352,7 @@ discard block |
||
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | $url = $request->toUrl($this->endpoint); |
| 355 | - $holder->msg .= $url . "\r\n"; |
|
| 355 | + $holder->msg .= $url."\r\n"; |
|
| 356 | 356 | return $url; |
| 357 | 357 | } |
| 358 | 358 | |
@@ -361,7 +361,7 @@ discard block |
||
| 361 | 361 | { |
| 362 | 362 | $policy = array(); |
| 363 | 363 | |
| 364 | - $expireTime = Utils::iso8601(time() + $expire); |
|
| 364 | + $expireTime = Utils::iso8601(time()+$expire); |
|
| 365 | 365 | $policy["expiration"] = $expireTime; |
| 366 | 366 | $postFormData["bucket"] = $bucket; |
| 367 | 367 | $conditions = array(); |
@@ -373,7 +373,7 @@ discard block |
||
| 373 | 373 | foreach ($unknowValueFormFiled as $key => $value) { |
| 374 | 374 | $condition = array(); |
| 375 | 375 | $condition[] = "starts-with"; |
| 376 | - $condition[] = "\$" . $value; |
|
| 376 | + $condition[] = "\$".$value; |
|
| 377 | 377 | $condition[] = ""; |
| 378 | 378 | $conditions[] = $condition; |
| 379 | 379 | } |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | */ |
| 84 | 84 | public function upload(string $object, string $filePath): ?bool |
| 85 | 85 | { |
| 86 | - require_once(__DIR__ . "/bin/Ks3Client.class.php"); |
|
| 86 | + require_once(__DIR__."/bin/Ks3Client.class.php"); |
|
| 87 | 87 | $client = new Ks3Client($this->accessKeyID, $this->accessKeySecret, $this->endpoint); |
| 88 | 88 | $content = fopen($filePath, 'rb'); |
| 89 | 89 | $args = [ |
@@ -91,10 +91,10 @@ discard block |
||
| 91 | 91 | "Key" => $object, |
| 92 | 92 | "Content" => [ |
| 93 | 93 | //要上传的内容 |
| 94 | - "content" => $content,//可以是文件路径或者resource,如果文件大于2G,请提供文件路径 |
|
| 94 | + "content" => $content, //可以是文件路径或者resource,如果文件大于2G,请提供文件路径 |
|
| 95 | 95 | "seek_position" => 0//跳过文件开头?个字节 |
| 96 | 96 | ], |
| 97 | - "ACL" => "public-read",//可以设置访问权限,合法值,private、public-read |
|
| 97 | + "ACL" => "public-read", //可以设置访问权限,合法值,private、public-read |
|
| 98 | 98 | "ObjectMeta" => [ |
| 99 | 99 | //设置object的元数据,可以设置"Cache-Control","Content-Disposition","Content-Encoding","Content-Length","Content-MD5","Content-Type","Expires"。当设置了Content-Length时,最后上传的为从seek_position开始向后Content-Length个字节的内容。当设置了Content-MD5时,系统会在服务端进行md5校验。 |
| 100 | 100 | "Content-Type" => "binay/ocet-stream" |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | { |
| 47 | 47 | if (Pregs::isLink($url)) { |
| 48 | 48 | $this->url = $url; |
| 49 | - } else { |
|
| 49 | + }else { |
|
| 50 | 50 | preg_match_all('#\bhttps?://[^,\s()<>]+(?:\([\w\d]+\)|([^,[:punct:]\s]|/))#', $url, $match); |
| 51 | 51 | $this->url = $match[0][0]; |
| 52 | 52 | } |
@@ -107,9 +107,9 @@ discard block |
||
| 107 | 107 | 'Connection' => 'keep-alive', |
| 108 | 108 | 'User-Agent' => 'Mozilla/5.0 (iPhone; CPU iPhone OS 12_1_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/16D57 Version/12.0 Safari/604.1' |
| 109 | 109 | ]; |
| 110 | - $client = new Client(['timeout' => 2, 'headers' => $headers, 'http_errors' => false,]); |
|
| 110 | + $client = new Client(['timeout' => 2, 'headers' => $headers, 'http_errors' => false, ]); |
|
| 111 | 111 | $data['headers'] = $headers; |
| 112 | - $data['verify'] = __DIR__ . DIRECTORY_SEPARATOR . 'cacert.pem'; |
|
| 112 | + $data['verify'] = __DIR__.DIRECTORY_SEPARATOR.'cacert.pem'; |
|
| 113 | 113 | $jar = new CookieJar(); |
| 114 | 114 | $data['cookies'] = $jar; |
| 115 | 115 | $response = $client->request('GET', $url, $data); |