@@ -1,43 +1,43 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | require_once KS3_API_PATH.DIRECTORY_SEPARATOR."exceptions".DIRECTORY_SEPARATOR."Exceptions.php"; |
| 3 | -class Logger{ |
|
| 4 | - function info($msg){ |
|
| 5 | - $this->log("INFO",$msg); |
|
| 3 | +class Logger { |
|
| 4 | + function info($msg) { |
|
| 5 | + $this->log("INFO", $msg); |
|
| 6 | 6 | } |
| 7 | - function error($msg){ |
|
| 8 | - $this->log("ERROR",$msg); |
|
| 7 | + function error($msg) { |
|
| 8 | + $this->log("ERROR", $msg); |
|
| 9 | 9 | } |
| 10 | - function warn($msg){ |
|
| 11 | - $this->log("WARN",$msg); |
|
| 10 | + function warn($msg) { |
|
| 11 | + $this->log("WARN", $msg); |
|
| 12 | 12 | } |
| 13 | - function debug($msg){ |
|
| 14 | - $this->log("DEBUG",$msg); |
|
| 13 | + function debug($msg) { |
|
| 14 | + $this->log("DEBUG", $msg); |
|
| 15 | 15 | } |
| 16 | - private function log($level,$msg){ |
|
| 16 | + private function log($level, $msg) { |
|
| 17 | 17 | $date = gmdate('D, d M Y H:i:s \G\M\T'); |
| 18 | 18 | $log = $date." ".$level."\r\n".$msg."\r\n"; |
| 19 | - if(defined('KS3_API_LOG_PATH') ){ |
|
| 19 | + if (defined('KS3_API_LOG_PATH')) { |
|
| 20 | 20 | $log_path = KS3_API_LOG_PATH; |
| 21 | - if(empty($log_path)){ |
|
| 21 | + if (empty($log_path)) { |
|
| 22 | 22 | $log_path = KS3_API_PATH.DIRECTORY_SEPARATOR.'log'.DIRECTORY_SEPARATOR; |
| 23 | 23 | } |
| 24 | - }else{ |
|
| 24 | + }else { |
|
| 25 | 25 | $log_path = KS3_API_PATH.DIRECTORY_SEPARATOR.'log'.DIRECTORY_SEPARATOR; |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | //检测日志目录是否存在 |
| 29 | - if(!file_exists($log_path)){ |
|
| 29 | + if (!file_exists($log_path)) { |
|
| 30 | 30 | mkdir($log_path); |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | $log_name = $log_path.'ks3_php_sdk_'.date('Y-m-d').'.log'; |
| 34 | 34 | |
| 35 | - if(KS3_API_DISPLAY_LOG){ |
|
| 35 | + if (KS3_API_DISPLAY_LOG) { |
|
| 36 | 36 | echo $log; |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | - if(KS3_API_LOG){ |
|
| 40 | - if(!error_log($log,3,$log_name)){ |
|
| 39 | + if (KS3_API_LOG) { |
|
| 40 | + if (!error_log($log, 3, $log_name)) { |
|
| 41 | 41 | throw new Ks3ClientException("write to log file error"); |
| 42 | 42 | } |
| 43 | 43 | } |
@@ -2,33 +2,33 @@ discard block |
||
| 2 | 2 | require_once KS3_API_PATH.DIRECTORY_SEPARATOR."exceptions".DIRECTORY_SEPARATOR."Exceptions.php"; |
| 3 | 3 | require_once KS3_API_PATH.DIRECTORY_SEPARATOR."config".DIRECTORY_SEPARATOR."Consts.php"; |
| 4 | 4 | |
| 5 | -class LocationBuilder{ |
|
| 6 | - function build($args){ |
|
| 7 | - if(isset($args["Location"])){ |
|
| 5 | +class LocationBuilder { |
|
| 6 | + function build($args) { |
|
| 7 | + if (isset($args["Location"])) { |
|
| 8 | 8 | $location = $args["Location"]; |
| 9 | 9 | $xml = new SimpleXmlElement('<CreateBucketConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"></CreateBucketConfiguration>'); |
| 10 | - $xml->addChild("LocationConstraint",$args["Location"]); |
|
| 10 | + $xml->addChild("LocationConstraint", $args["Location"]); |
|
| 11 | 11 | return $xml->asXml(); |
| 12 | 12 | } |
| 13 | 13 | } |
| 14 | 14 | } |
| 15 | -class CORSBuilder{ |
|
| 16 | - function build($args){ |
|
| 17 | - if(isset($args["CORS"])){ |
|
| 15 | +class CORSBuilder { |
|
| 16 | + function build($args) { |
|
| 17 | + if (isset($args["CORS"])) { |
|
| 18 | 18 | $cors = $args["CORS"]; |
| 19 | 19 | $xml = new SimpleXmlElement('<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"></CORSConfiguration>'); |
| 20 | - if(is_array($cors)){ |
|
| 20 | + if (is_array($cors)) { |
|
| 21 | 21 | foreach ($cors as $key => $rule) { |
| 22 | 22 | $ruleXml = $xml->addChild("CORSRule"); |
| 23 | - if(is_array($rule)){ |
|
| 23 | + if (is_array($rule)) { |
|
| 24 | 24 | foreach ($rule as $key => $value) { |
| 25 | - if(in_array($key,Consts::$CORSElements)){ |
|
| 26 | - if(is_array($value)){ |
|
| 25 | + if (in_array($key, Consts::$CORSElements)) { |
|
| 26 | + if (is_array($value)) { |
|
| 27 | 27 | foreach ($value as $ele) { |
| 28 | - $ruleXml->addChild($key,$ele); |
|
| 28 | + $ruleXml->addChild($key, $ele); |
|
| 29 | 29 | } |
| 30 | - }else{ |
|
| 31 | - $ruleXml->addChild($key,$value); |
|
| 30 | + }else { |
|
| 31 | + $ruleXml->addChild($key, $value); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | } |
@@ -40,23 +40,23 @@ discard block |
||
| 40 | 40 | } |
| 41 | 41 | } |
| 42 | 42 | } |
| 43 | -class BucketLoggingBuilder{ |
|
| 44 | - function build($args){ |
|
| 45 | - if(isset($args["BucketLogging"])){ |
|
| 43 | +class BucketLoggingBuilder { |
|
| 44 | + function build($args) { |
|
| 45 | + if (isset($args["BucketLogging"])) { |
|
| 46 | 46 | $logging = $args["BucketLogging"]; |
| 47 | 47 | $xml = new SimpleXmlElement('<BucketLoggingStatus xmlns="http://s3.amazonaws.com/doc/2006-03-01/" />'); |
| 48 | - if(is_array($logging)){ |
|
| 48 | + if (is_array($logging)) { |
|
| 49 | 49 | |
| 50 | - if(!isset($logging["Enable"])) |
|
| 50 | + if (!isset($logging["Enable"])) |
|
| 51 | 51 | throw new Ks3ClientException("bucket logging must provide Enable argument"); |
| 52 | 52 | |
| 53 | - if($logging["Enable"]){ |
|
| 54 | - if(!isset($logging["TargetBucket"])) |
|
| 53 | + if ($logging["Enable"]) { |
|
| 54 | + if (!isset($logging["TargetBucket"])) |
|
| 55 | 55 | throw new Ks3ClientException("bucket logging must provide TargetBucket argument"); |
| 56 | 56 | $loggingConfig = $xml->addChild("LoggingEnabled"); |
| 57 | 57 | foreach ($logging as $key => $value) { |
| 58 | - if(in_array($key,Consts::$BucketLoggingElements)){ |
|
| 59 | - $loggingConfig->addChild($key,$value); |
|
| 58 | + if (in_array($key, Consts::$BucketLoggingElements)) { |
|
| 59 | + $loggingConfig->addChild($key, $value); |
|
| 60 | 60 | } |
| 61 | 61 | } |
| 62 | 62 | } |
@@ -65,32 +65,32 @@ discard block |
||
| 65 | 65 | } |
| 66 | 66 | } |
| 67 | 67 | } |
| 68 | -class DeleteObjectsBuilder{ |
|
| 69 | - function build($args){ |
|
| 70 | - if(isset($args["DeleteKeys"])){ |
|
| 68 | +class DeleteObjectsBuilder { |
|
| 69 | + function build($args) { |
|
| 70 | + if (isset($args["DeleteKeys"])) { |
|
| 71 | 71 | $keys = $args["DeleteKeys"]; |
| 72 | 72 | $xml = new SimpleXmlElement('<Delete></Delete>'); |
| 73 | - if(is_array($keys)){ |
|
| 73 | + if (is_array($keys)) { |
|
| 74 | 74 | foreach ($keys as $key => $value) { |
| 75 | 75 | $object = $xml->addChild("Object"); |
| 76 | - $object->addChild("Key",$value); |
|
| 76 | + $object->addChild("Key", $value); |
|
| 77 | 77 | } |
| 78 | 78 | } |
| 79 | 79 | return $xml->asXml(); |
| 80 | 80 | } |
| 81 | 81 | } |
| 82 | 82 | } |
| 83 | -class CompleteMultipartUploadBuilder{ |
|
| 84 | - function build($args){ |
|
| 85 | - if(isset($args["Parts"])){ |
|
| 83 | +class CompleteMultipartUploadBuilder { |
|
| 84 | + function build($args) { |
|
| 85 | + if (isset($args["Parts"])) { |
|
| 86 | 86 | $parts = $args["Parts"]; |
| 87 | 87 | $xml = new SimpleXmlElement('<CompleteMultipartUpload></CompleteMultipartUpload>'); |
| 88 | - if(is_array($parts)){ |
|
| 88 | + if (is_array($parts)) { |
|
| 89 | 89 | foreach ($parts as $part) { |
| 90 | 90 | $partXml = $xml->addChild("Part"); |
| 91 | 91 | foreach ($part as $key => $value) { |
| 92 | - if(in_array($key,Consts::$PartsElement)){ |
|
| 93 | - $partXml->addChild($key,$value); |
|
| 92 | + if (in_array($key, Consts::$PartsElement)) { |
|
| 93 | + $partXml->addChild($key, $value); |
|
| 94 | 94 | } |
| 95 | 95 | } |
| 96 | 96 | } |
@@ -5,53 +5,53 @@ discard block |
||
| 5 | 5 | require_once KS3_API_PATH.DIRECTORY_SEPARATOR."config".DIRECTORY_SEPARATOR."Consts.php"; |
| 6 | 6 | require_once KS3_API_PATH.DIRECTORY_SEPARATOR."exceptions".DIRECTORY_SEPARATOR."Exceptions.php"; |
| 7 | 7 | |
| 8 | -interface Signer{ |
|
| 9 | - public function sign( Ks3Request $request,$args=array()); |
|
| 8 | +interface Signer { |
|
| 9 | + public function sign(Ks3Request $request, $args = array()); |
|
| 10 | 10 | } |
| 11 | -class DefaultUserAgentSigner implements Signer{ |
|
| 12 | - public function sign(Ks3Request $request,$args=array()){ |
|
| 13 | - $request->addHeader(Headers::$UserAgent,Consts::$UserAgent); |
|
| 11 | +class DefaultUserAgentSigner implements Signer { |
|
| 12 | + public function sign(Ks3Request $request, $args = array()) { |
|
| 13 | + $request->addHeader(Headers::$UserAgent, Consts::$UserAgent); |
|
| 14 | 14 | } |
| 15 | 15 | } |
| 16 | -class DefaultContentTypeSigner implements Signer{ |
|
| 17 | - public function sign(Ks3Request $request,$args=array()){ |
|
| 16 | +class DefaultContentTypeSigner implements Signer { |
|
| 17 | + public function sign(Ks3Request $request, $args = array()) { |
|
| 18 | 18 | $contentType = $request->getHeader(Headers::$ContentType); |
| 19 | - if(empty($contentType)){ |
|
| 20 | - $request->addHeader(Headers::$ContentType,"application/xml"); |
|
| 19 | + if (empty($contentType)) { |
|
| 20 | + $request->addHeader(Headers::$ContentType, "application/xml"); |
|
| 21 | 21 | } |
| 22 | 22 | } |
| 23 | 23 | } |
| 24 | -class StreamContentTypeSigner implements Signer{ |
|
| 25 | - public function sign(Ks3Request $request,$args=array()){ |
|
| 24 | +class StreamContentTypeSigner implements Signer { |
|
| 25 | + public function sign(Ks3Request $request, $args = array()) { |
|
| 26 | 26 | $contentType = $request->getHeader(Headers::$ContentType); |
| 27 | - if(empty($contentType)){ |
|
| 28 | - $request->addHeader(Headers::$ContentType,"application/ocet-stream"); |
|
| 27 | + if (empty($contentType)) { |
|
| 28 | + $request->addHeader(Headers::$ContentType, "application/ocet-stream"); |
|
| 29 | 29 | } |
| 30 | 30 | } |
| 31 | 31 | } |
| 32 | -class SuffixContentTypeSigner implements Signer{ |
|
| 33 | - public function sign(Ks3Request $request,$args=array()){ |
|
| 32 | +class SuffixContentTypeSigner implements Signer { |
|
| 33 | + public function sign(Ks3Request $request, $args = array()) { |
|
| 34 | 34 | $key = $request->key; |
| 35 | 35 | $objArr = explode('/', $key); |
| 36 | 36 | $basename = array_pop($objArr); |
| 37 | - $extension = explode ( '.', $basename ); |
|
| 38 | - $extension = array_pop ( $extension ); |
|
| 37 | + $extension = explode('.', $basename); |
|
| 38 | + $extension = array_pop($extension); |
|
| 39 | 39 | $content_type = Utils::get_mimetype(strtolower($extension)); |
| 40 | - $request->addHeader(Headers::$ContentType,$content_type); |
|
| 40 | + $request->addHeader(Headers::$ContentType, $content_type); |
|
| 41 | 41 | } |
| 42 | 42 | } |
| 43 | -class HeaderAuthSigner implements Signer{ |
|
| 44 | - public function sign(Ks3Request $request,$args=array()){ |
|
| 43 | +class HeaderAuthSigner implements Signer { |
|
| 44 | + public function sign(Ks3Request $request, $args = array()) { |
|
| 45 | 45 | $log = "stringToSing->\r\n"; |
| 46 | 46 | $date = gmdate('D, d M Y H:i:s \G\M\T'); |
| 47 | 47 | $request->addHeader(Headers::$Date, $date); |
| 48 | 48 | |
| 49 | 49 | $ak = $args["accessKey"]; |
| 50 | 50 | $sk = $args["secretKey"]; |
| 51 | - if(empty($ak)){ |
|
| 51 | + if (empty($ak)) { |
|
| 52 | 52 | throw new Ks3ClientException("you should provide accessKey"); |
| 53 | 53 | } |
| 54 | - if(empty($sk)){ |
|
| 54 | + if (empty($sk)) { |
|
| 55 | 55 | throw new Ks3ClientException("you should provide secretKey"); |
| 56 | 56 | } |
| 57 | 57 | $authration = "KSS "; |
@@ -63,21 +63,21 @@ discard block |
||
| 63 | 63 | ); |
| 64 | 64 | $headers = AuthUtils::canonicalizedKssHeaders($request); |
| 65 | 65 | $resource = AuthUtils::canonicalizedResource($request); |
| 66 | - if(!empty($headers)){ |
|
| 67 | - array_push($signList,$headers); |
|
| 66 | + if (!empty($headers)) { |
|
| 67 | + array_push($signList, $headers); |
|
| 68 | 68 | } |
| 69 | - array_push($signList,$resource); |
|
| 70 | - $stringToSign = join("\n",$signList); |
|
| 71 | - $log.= $stringToSign; |
|
| 69 | + array_push($signList, $resource); |
|
| 70 | + $stringToSign = join("\n", $signList); |
|
| 71 | + $log .= $stringToSign; |
|
| 72 | 72 | $signature = base64_encode(hash_hmac('sha1', $stringToSign, $sk, true)); |
| 73 | 73 | |
| 74 | - $authration.=$ak.":".$signature; |
|
| 74 | + $authration .= $ak.":".$signature; |
|
| 75 | 75 | $request->addHeader(Headers::$Authorization, $authration); |
| 76 | 76 | return $log; |
| 77 | 77 | } |
| 78 | 78 | } |
| 79 | -class QueryAuthSigner implements Signer{ |
|
| 80 | - public function sign(Ks3Request $request,$args=array()){ |
|
| 79 | +class QueryAuthSigner implements Signer { |
|
| 80 | + public function sign(Ks3Request $request, $args = array()) { |
|
| 81 | 81 | $log = "stringToSing->\r\n"; |
| 82 | 82 | $ak = $args["accessKey"]; |
| 83 | 83 | $sk = $args["secretKey"]; |
@@ -93,447 +93,447 @@ discard block |
||
| 93 | 93 | ); |
| 94 | 94 | $headers = AuthUtils::canonicalizedKssHeaders($request); |
| 95 | 95 | $resource = AuthUtils::canonicalizedResource($request); |
| 96 | - if(!empty($headers)){ |
|
| 97 | - array_push($signList,$headers); |
|
| 96 | + if (!empty($headers)) { |
|
| 97 | + array_push($signList, $headers); |
|
| 98 | 98 | } |
| 99 | - array_push($signList,$resource); |
|
| 99 | + array_push($signList, $resource); |
|
| 100 | 100 | |
| 101 | - $stringToSign = join("\n",$signList); |
|
| 102 | - $log.= $stringToSign; |
|
| 101 | + $stringToSign = join("\n", $signList); |
|
| 102 | + $log .= $stringToSign; |
|
| 103 | 103 | $signature = base64_encode(hash_hmac('sha1', $stringToSign, $sk, true)); |
| 104 | - $request->addQueryParams("KSSAccessKeyId",$ak); |
|
| 105 | - $request->addQueryParams("Signature",$signature); |
|
| 106 | - $request->addQueryParams("Expires",$expiresSencond); |
|
| 104 | + $request->addQueryParams("KSSAccessKeyId", $ak); |
|
| 105 | + $request->addQueryParams("Signature", $signature); |
|
| 106 | + $request->addQueryParams("Expires", $expiresSencond); |
|
| 107 | 107 | return $log; |
| 108 | 108 | } |
| 109 | 109 | } |
| 110 | -class ACLSigner implements Signer{ |
|
| 111 | - public function sign(Ks3Request $request,$args=array()){ |
|
| 110 | +class ACLSigner implements Signer { |
|
| 111 | + public function sign(Ks3Request $request, $args = array()) { |
|
| 112 | 112 | $args = $args["args"]; |
| 113 | - if(isset($args["ACL"])){ |
|
| 113 | + if (isset($args["ACL"])) { |
|
| 114 | 114 | $acl = $args["ACL"]; |
| 115 | - if(!in_array($acl, Consts::$Acl)){ |
|
| 115 | + if (!in_array($acl, Consts::$Acl)) { |
|
| 116 | 116 | throw new Ks3ClientException("unsupport acl :".$acl); |
| 117 | - }else{ |
|
| 118 | - $request->addHeader(Headers::$Acl,$acl); |
|
| 117 | + }else { |
|
| 118 | + $request->addHeader(Headers::$Acl, $acl); |
|
| 119 | 119 | } |
| 120 | 120 | } |
| 121 | - if(isset($args["ACP"])){ |
|
| 121 | + if (isset($args["ACP"])) { |
|
| 122 | 122 | |
| 123 | 123 | } |
| 124 | 124 | } |
| 125 | 125 | } |
| 126 | -class ContentMD5Signer implements Signer{ |
|
| 127 | - public function sign(Ks3Request $request,$args=array()){ |
|
| 126 | +class ContentMD5Signer implements Signer { |
|
| 127 | + public function sign(Ks3Request $request, $args = array()) { |
|
| 128 | 128 | $args = $args["args"]; |
| 129 | 129 | $contentmd5 = ""; |
| 130 | - if(isset($args["ObjectMeta"][Headers::$ContentMd5])){ |
|
| 130 | + if (isset($args["ObjectMeta"][Headers::$ContentMd5])) { |
|
| 131 | 131 | $contentmd5 = $args["ObjectMeta"][Headers::$ContentMd5]; |
| 132 | 132 | } |
| 133 | - if(empty($contentmd5)){ |
|
| 133 | + if (empty($contentmd5)) { |
|
| 134 | 134 | $body = $request->body; |
| 135 | - if(!empty($body)){ |
|
| 135 | + if (!empty($body)) { |
|
| 136 | 136 | $length = $request->getHeader(Headers::$ContentLength); |
| 137 | - if(empty($length)){ |
|
| 138 | - if(isset($args["ObjectMeta"][Headers::$ContentLength])) |
|
| 137 | + if (empty($length)) { |
|
| 138 | + if (isset($args["ObjectMeta"][Headers::$ContentLength])) |
|
| 139 | 139 | $length = $args["ObjectMeta"][Headers::$ContentLength]; |
| 140 | 140 | } |
| 141 | - if(!empty($length)){ |
|
| 142 | - $body = substr($body,0,$length); |
|
| 141 | + if (!empty($length)) { |
|
| 142 | + $body = substr($body, 0, $length); |
|
| 143 | 143 | } |
| 144 | 144 | $contentmd5 = Utils::hex_to_base64(md5($body)); |
| 145 | 145 | } |
| 146 | 146 | } |
| 147 | - if(!empty($contentmd5)) |
|
| 148 | - $request->addHeader(Headers::$ContentMd5,$contentmd5); |
|
| 147 | + if (!empty($contentmd5)) |
|
| 148 | + $request->addHeader(Headers::$ContentMd5, $contentmd5); |
|
| 149 | 149 | } |
| 150 | 150 | } |
| 151 | -class ContentLengthSigner implements Signer{ |
|
| 152 | - public function sign(Ks3Request $request,$args=array()){ |
|
| 151 | +class ContentLengthSigner implements Signer { |
|
| 152 | + public function sign(Ks3Request $request, $args = array()) { |
|
| 153 | 153 | $args = $args["args"]; |
| 154 | 154 | $contentlength = ""; |
| 155 | - if(isset($args["ObjectMeta"][Headers::$ContentLength])){ |
|
| 155 | + if (isset($args["ObjectMeta"][Headers::$ContentLength])) { |
|
| 156 | 156 | $contentlength = $args["ObjectMeta"][Headers::$ContentLength]; |
| 157 | 157 | } |
| 158 | - if(empty($contentlength)){ |
|
| 158 | + if (empty($contentlength)) { |
|
| 159 | 159 | $body = $request->body; |
| 160 | - if(!empty($body)){ |
|
| 160 | + if (!empty($body)) { |
|
| 161 | 161 | $contentlength = strlen($body); |
| 162 | 162 | } |
| 163 | 163 | } |
| 164 | - if(!empty($contentlength)) |
|
| 165 | - $request->addHeader(Headers::$ContentLength,$contentlength); |
|
| 164 | + if (!empty($contentlength)) |
|
| 165 | + $request->addHeader(Headers::$ContentLength, $contentlength); |
|
| 166 | 166 | } |
| 167 | 167 | } |
| 168 | -class ObjectMetaSigner implements Signer{ |
|
| 169 | - public function sign(Ks3Request $request,$args=array()){ |
|
| 168 | +class ObjectMetaSigner implements Signer { |
|
| 169 | + public function sign(Ks3Request $request, $args = array()) { |
|
| 170 | 170 | $args = $args["args"]; |
| 171 | - if(isset($args["ObjectMeta"])){ |
|
| 171 | + if (isset($args["ObjectMeta"])) { |
|
| 172 | 172 | $ObjectMeta = $args["ObjectMeta"]; |
| 173 | - if(is_array($ObjectMeta)){ |
|
| 173 | + if (is_array($ObjectMeta)) { |
|
| 174 | 174 | foreach ($ObjectMeta as $key => $value) { |
| 175 | - if(in_array($key,Consts::$ObjectMeta)&&!empty($value)){ |
|
| 176 | - $request->addHeader($key,$value); |
|
| 175 | + if (in_array($key, Consts::$ObjectMeta) && !empty($value)) { |
|
| 176 | + $request->addHeader($key, $value); |
|
| 177 | 177 | } |
| 178 | 178 | } |
| 179 | 179 | } |
| 180 | 180 | } |
| 181 | 181 | } |
| 182 | 182 | } |
| 183 | -class MultipartObjectMetaSigner implements Signer{ |
|
| 184 | - public function sign(Ks3Request $request,$args=array()){ |
|
| 183 | +class MultipartObjectMetaSigner implements Signer { |
|
| 184 | + public function sign(Ks3Request $request, $args = array()) { |
|
| 185 | 185 | $args = $args["args"]; |
| 186 | - if(isset($args["ObjectMeta"])){ |
|
| 186 | + if (isset($args["ObjectMeta"])) { |
|
| 187 | 187 | $ObjectMeta = $args["ObjectMeta"]; |
| 188 | - if(is_array($ObjectMeta)){ |
|
| 188 | + if (is_array($ObjectMeta)) { |
|
| 189 | 189 | foreach ($ObjectMeta as $key => $value) { |
| 190 | - if(in_array($key,Consts::$MultipartObjectMeta)&&!empty($value)){ |
|
| 191 | - $request->addHeader($key,$value); |
|
| 190 | + if (in_array($key, Consts::$MultipartObjectMeta) && !empty($value)) { |
|
| 191 | + $request->addHeader($key, $value); |
|
| 192 | 192 | } |
| 193 | 193 | } |
| 194 | 194 | } |
| 195 | 195 | } |
| 196 | 196 | } |
| 197 | 197 | } |
| 198 | -class UserMetaSigner implements Signer{ |
|
| 199 | - public function sign(Ks3Request $request,$args=array()){ |
|
| 198 | +class UserMetaSigner implements Signer { |
|
| 199 | + public function sign(Ks3Request $request, $args = array()) { |
|
| 200 | 200 | $args = $args["args"]; |
| 201 | - if(isset($args["UserMeta"])){ |
|
| 201 | + if (isset($args["UserMeta"])) { |
|
| 202 | 202 | $UserMeta = $args["UserMeta"]; |
| 203 | - if(is_array($UserMeta)){ |
|
| 203 | + if (is_array($UserMeta)) { |
|
| 204 | 204 | foreach ($UserMeta as $key => $value) { |
| 205 | - if (substr(strtolower($key), 0, 10) === Consts::$UserMetaPrefix){ |
|
| 206 | - $request->addHeader($key,$value); |
|
| 205 | + if (substr(strtolower($key), 0, 10) === Consts::$UserMetaPrefix) { |
|
| 206 | + $request->addHeader($key, $value); |
|
| 207 | 207 | } |
| 208 | 208 | } |
| 209 | 209 | } |
| 210 | 210 | } |
| 211 | 211 | } |
| 212 | 212 | } |
| 213 | -class CopySourceSigner implements Signer{ |
|
| 214 | - public function sign(Ks3Request $request,$args=array()){ |
|
| 213 | +class CopySourceSigner implements Signer { |
|
| 214 | + public function sign(Ks3Request $request, $args = array()) { |
|
| 215 | 215 | $args = $args["args"]; |
| 216 | - if(isset($args["CopySource"])){ |
|
| 216 | + if (isset($args["CopySource"])) { |
|
| 217 | 217 | $CopySource = $args["CopySource"]; |
| 218 | - if(is_array($CopySource)){ |
|
| 219 | - if(!isset($CopySource["Bucket"])) |
|
| 218 | + if (is_array($CopySource)) { |
|
| 219 | + if (!isset($CopySource["Bucket"])) |
|
| 220 | 220 | throw new Ks3ClientException("you should provide copy source bucket"); |
| 221 | - if(!isset($CopySource["Key"])) |
|
| 221 | + if (!isset($CopySource["Key"])) |
|
| 222 | 222 | throw new Ks3ClientException("you should provide copy source key"); |
| 223 | 223 | $bucket = $CopySource["Bucket"]; |
| 224 | 224 | $key = Utils::encodeUrl($CopySource["Key"]); |
| 225 | - $request->addHeader(Headers::$CopySource,"/".$bucket."/".$key); |
|
| 225 | + $request->addHeader(Headers::$CopySource, "/".$bucket."/".$key); |
|
| 226 | 226 | } |
| 227 | 227 | } |
| 228 | 228 | } |
| 229 | 229 | } |
| 230 | -class StreamUploadSigner implements Signer{ |
|
| 231 | - public function sign(Ks3Request $request,$args=array()){ |
|
| 230 | +class StreamUploadSigner implements Signer { |
|
| 231 | + public function sign(Ks3Request $request, $args = array()) { |
|
| 232 | 232 | $args = $args["args"]; |
| 233 | - if(isset($args["Content"])&&is_array($args["Content"])&&isset($args["Content"]["content"])){ |
|
| 233 | + if (isset($args["Content"]) && is_array($args["Content"]) && isset($args["Content"]["content"])) { |
|
| 234 | 234 | $content = $args["Content"]["content"]; |
| 235 | 235 | $seek_position = 0; |
| 236 | 236 | $resourceLength = 0; |
| 237 | 237 | $length = -1; |
| 238 | 238 | $isFile = FALSE; |
| 239 | 239 | |
| 240 | - if (!is_resource($content)){ |
|
| 240 | + if (!is_resource($content)) { |
|
| 241 | 241 | $isFile = TRUE; |
| 242 | 242 | //如果之前用户已经转化为GBK则不转换 |
| 243 | - if(Utils::chk_chinese($content)&&!Utils::check_char($content)){ |
|
| 244 | - $content = iconv('utf-8','gbk',$content); |
|
| 243 | + if (Utils::chk_chinese($content) && !Utils::check_char($content)) { |
|
| 244 | + $content = iconv('utf-8', 'gbk', $content); |
|
| 245 | 245 | } |
| 246 | - if(!file_exists($content)) |
|
| 246 | + if (!file_exists($content)) |
|
| 247 | 247 | throw new Ks3ClientException("the specified file does not exist "); |
| 248 | 248 | $length = Utils::getFileSize($content); |
| 249 | - $content = fopen($content,"r"); |
|
| 250 | - }else{ |
|
| 249 | + $content = fopen($content, "r"); |
|
| 250 | + }else { |
|
| 251 | 251 | $stats = fstat($content); |
| 252 | - if ($stats && $stats["size"] >= 0){ |
|
| 252 | + if ($stats && $stats["size"] >= 0) { |
|
| 253 | 253 | $length = $stats["size"]; |
| 254 | 254 | } |
| 255 | 255 | } |
| 256 | 256 | //之所以取resourceLength是为了防止Content-Length大于实际数据的大小,导致一直等待。 |
| 257 | 257 | $resourceLength = $length; |
| 258 | 258 | //优先取用户设置seek_position,没有的话取ftell |
| 259 | - if(isset($args["Content"]["seek_position"])&&$args["Content"]["seek_position"]>0){ |
|
| 259 | + if (isset($args["Content"]["seek_position"]) && $args["Content"]["seek_position"] > 0) { |
|
| 260 | 260 | $seek_position = $args["Content"]["seek_position"]; |
| 261 | - }else if(!$isFile){ |
|
| 261 | + }else if (!$isFile) { |
|
| 262 | 262 | $seek_position = ftell($content); |
| 263 | - if($seek_position<0) |
|
| 263 | + if ($seek_position < 0) |
|
| 264 | 264 | $seek_position = 0; |
| 265 | - fseek($content,0); |
|
| 265 | + fseek($content, 0); |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | $lengthInMeta = -1; |
| 269 | - if(isset($args["ObjectMeta"]["Content-Length"])){ |
|
| 269 | + if (isset($args["ObjectMeta"]["Content-Length"])) { |
|
| 270 | 270 | $lengthInMeta = $args["ObjectMeta"]["Content-Length"]; |
| 271 | 271 | } |
| 272 | - if($lengthInMeta > 0){ |
|
| 272 | + if ($lengthInMeta > 0) { |
|
| 273 | 273 | $length = $lengthInMeta; |
| 274 | - }else if($resourceLength > 0){ |
|
| 274 | + }else if ($resourceLength > 0) { |
|
| 275 | 275 | //根据seek_position计算实际长度 |
| 276 | - $length = $resourceLength - $seek_position; |
|
| 276 | + $length = $resourceLength-$seek_position; |
|
| 277 | 277 | } |
| 278 | - if($length <= 0) |
|
| 278 | + if ($length <= 0) |
|
| 279 | 279 | throw new Ks3ClientException("calculate content length failed,unexpected contetn length ".$length); |
| 280 | 280 | $request->read_stream = $content; |
| 281 | - $request->addHeader(Headers::$ContentLength,$length); |
|
| 281 | + $request->addHeader(Headers::$ContentLength, $length); |
|
| 282 | 282 | $request->seek_position = $seek_position; |
| 283 | - }else{ |
|
| 283 | + }else { |
|
| 284 | 284 | throw new Ks3ClientException("please specifie upload content in args"); |
| 285 | 285 | } |
| 286 | 286 | } |
| 287 | 287 | } |
| 288 | -class RangeSigner{ |
|
| 289 | - public function sign(Ks3Request $request,$args=array()){ |
|
| 288 | +class RangeSigner { |
|
| 289 | + public function sign(Ks3Request $request, $args = array()) { |
|
| 290 | 290 | $args = $args["args"]; |
| 291 | - if(isset($args["Range"])){ |
|
| 291 | + if (isset($args["Range"])) { |
|
| 292 | 292 | $Range = $args["Range"]; |
| 293 | - if(is_array($Range)){ |
|
| 293 | + if (is_array($Range)) { |
|
| 294 | 294 | $start = $Range["start"]; |
| 295 | 295 | $end = $Range["end"]; |
| 296 | 296 | $range = "bytes=".$start."-".$end; |
| 297 | - $request->addHeader(Headers::$Range,$range); |
|
| 297 | + $request->addHeader(Headers::$Range, $range); |
|
| 298 | 298 | }else |
| 299 | - $request->addHeader(Headers::$Range,$Range); |
|
| 299 | + $request->addHeader(Headers::$Range, $Range); |
|
| 300 | 300 | } |
| 301 | 301 | } |
| 302 | 302 | } |
| 303 | -class GetObjectSigner{ |
|
| 304 | - public function sign(Ks3Request $request,$args=array()){ |
|
| 303 | +class GetObjectSigner { |
|
| 304 | + public function sign(Ks3Request $request, $args = array()) { |
|
| 305 | 305 | $args = $args["args"]; |
| 306 | - if(isset($args["WriteTo"])){ |
|
| 306 | + if (isset($args["WriteTo"])) { |
|
| 307 | 307 | $WriteTo = $args["WriteTo"]; |
| 308 | - if(is_resource($WriteTo)){ |
|
| 308 | + if (is_resource($WriteTo)) { |
|
| 309 | 309 | $request->write_stream = $WriteTo; |
| 310 | - }else{ |
|
| 310 | + }else { |
|
| 311 | 311 | //如果之前用户已经转化为GBK则不转换 |
| 312 | - if(Utils::chk_chinese($WriteTo)&&!Utils::check_char($WriteTo)){ |
|
| 313 | - $WriteTo = iconv('utf-8','gbk',$WriteTo); |
|
| 312 | + if (Utils::chk_chinese($WriteTo) && !Utils::check_char($WriteTo)) { |
|
| 313 | + $WriteTo = iconv('utf-8', 'gbk', $WriteTo); |
|
| 314 | 314 | } |
| 315 | - $request->write_stream = fopen($WriteTo,"w"); |
|
| 315 | + $request->write_stream = fopen($WriteTo, "w"); |
|
| 316 | 316 | } |
| 317 | 317 | } |
| 318 | 318 | } |
| 319 | 319 | } |
| 320 | -class AdpSigner{ |
|
| 321 | - public function sign(Ks3Request $request,$args=array()){ |
|
| 320 | +class AdpSigner { |
|
| 321 | + public function sign(Ks3Request $request, $args = array()) { |
|
| 322 | 322 | $args = $args["args"]; |
| 323 | - if(isset($args["Adp"])){ |
|
| 323 | + if (isset($args["Adp"])) { |
|
| 324 | 324 | $AdpConf = $args["Adp"]; |
| 325 | - if(is_array($AdpConf)){ |
|
| 326 | - if(isset($AdpConf["NotifyURL"])){ |
|
| 325 | + if (is_array($AdpConf)) { |
|
| 326 | + if (isset($AdpConf["NotifyURL"])) { |
|
| 327 | 327 | $NotifyURL = $AdpConf["NotifyURL"]; |
| 328 | - }else{ |
|
| 328 | + }else { |
|
| 329 | 329 | throw new Ks3ClientException("adp should provide NotifyURL"); |
| 330 | 330 | } |
| 331 | - if(isset($AdpConf["Adps"])){ |
|
| 331 | + if (isset($AdpConf["Adps"])) { |
|
| 332 | 332 | $Adps = $AdpConf["Adps"]; |
| 333 | - }else{ |
|
| 333 | + }else { |
|
| 334 | 334 | throw new Ks3ClientException("adp should provide Adps"); |
| 335 | 335 | } |
| 336 | 336 | $AdpString = ""; |
| 337 | 337 | foreach ($Adps as $Adp) { |
| 338 | - if(is_array($Adp)){ |
|
| 339 | - if(!isset($Adp["Command"])){ |
|
| 338 | + if (is_array($Adp)) { |
|
| 339 | + if (!isset($Adp["Command"])) { |
|
| 340 | 340 | throw new Ks3ClientException("command is needed in adp"); |
| 341 | 341 | } |
| 342 | 342 | $command = $Adp["Command"]; |
| 343 | 343 | $bucket = NULL; |
| 344 | 344 | $key = NULL; |
| 345 | - if(isset($Adp["Bucket"])){ |
|
| 345 | + if (isset($Adp["Bucket"])) { |
|
| 346 | 346 | $bucket = $Adp["Bucket"]; |
| 347 | 347 | } |
| 348 | - if(isset($Adp["Key"])){ |
|
| 348 | + if (isset($Adp["Key"])) { |
|
| 349 | 349 | $key = $Adp["Key"]; |
| 350 | 350 | } |
| 351 | - $AdpString.=$command; |
|
| 352 | - if(!(empty($bucket)&&empty($key))){ |
|
| 353 | - if(empty($bucket)){ |
|
| 354 | - $AdpString.="|tag=saveas&object=".base64_encode($key); |
|
| 351 | + $AdpString .= $command; |
|
| 352 | + if (!(empty($bucket) && empty($key))) { |
|
| 353 | + if (empty($bucket)) { |
|
| 354 | + $AdpString .= "|tag=saveas&object=".base64_encode($key); |
|
| 355 | 355 | }elseif (empty($key)) { |
| 356 | - $AdpString.="|tag=saveas&bucket=".$bucket; |
|
| 357 | - }else{ |
|
| 358 | - $AdpString.="|tag=saveas&bucket=".$bucket."&"."object=".base64_encode($key); |
|
| 356 | + $AdpString .= "|tag=saveas&bucket=".$bucket; |
|
| 357 | + }else { |
|
| 358 | + $AdpString .= "|tag=saveas&bucket=".$bucket."&"."object=".base64_encode($key); |
|
| 359 | 359 | } |
| 360 | 360 | } |
| 361 | - $AdpString.=";"; |
|
| 361 | + $AdpString .= ";"; |
|
| 362 | 362 | } |
| 363 | 363 | } |
| 364 | - if(!empty($AdpString)&&!empty($NotifyURL)){ |
|
| 365 | - $request->addHeader(Headers::$AsynchronousProcessingList,$AdpString); |
|
| 366 | - $request->addHeader(Headers::$NotifyURL,$NotifyURL); |
|
| 364 | + if (!empty($AdpString) && !empty($NotifyURL)) { |
|
| 365 | + $request->addHeader(Headers::$AsynchronousProcessingList, $AdpString); |
|
| 366 | + $request->addHeader(Headers::$NotifyURL, $NotifyURL); |
|
| 367 | 367 | } |
| 368 | 368 | } |
| 369 | 369 | } |
| 370 | 370 | } |
| 371 | 371 | } |
| 372 | -class CallBackSigner{ |
|
| 373 | - public function sign(Ks3Request $request,$args=array()){ |
|
| 372 | +class CallBackSigner { |
|
| 373 | + public function sign(Ks3Request $request, $args = array()) { |
|
| 374 | 374 | $args = $args["args"]; |
| 375 | - if(isset($args["CallBack"])&&is_array($args["CallBack"])){ |
|
| 375 | + if (isset($args["CallBack"]) && is_array($args["CallBack"])) { |
|
| 376 | 376 | $CallBackConf = $args["CallBack"]; |
| 377 | 377 | $url = NULL; |
| 378 | 378 | $body = NULL; |
| 379 | - if(isset($CallBackConf["Url"])){ |
|
| 379 | + if (isset($CallBackConf["Url"])) { |
|
| 380 | 380 | $url = $CallBackConf["Url"]; |
| 381 | 381 | } |
| 382 | - if(empty($url)) |
|
| 382 | + if (empty($url)) |
|
| 383 | 383 | throw new Ks3ClientException("Url is needed in CallBack"); |
| 384 | - if(isset($CallBackConf["BodyMagicVariables"])){ |
|
| 385 | - if(is_array($CallBackConf["BodyMagicVariables"])){ |
|
| 384 | + if (isset($CallBackConf["BodyMagicVariables"])) { |
|
| 385 | + if (is_array($CallBackConf["BodyMagicVariables"])) { |
|
| 386 | 386 | $magics = $CallBackConf["BodyMagicVariables"]; |
| 387 | 387 | foreach ($magics as $key => $value) { |
| 388 | - if(in_array($value,Consts::$CallBackMagics)) |
|
| 389 | - $body.=$key."=\${".$value."}&"; |
|
| 388 | + if (in_array($value, Consts::$CallBackMagics)) |
|
| 389 | + $body .= $key."=\${".$value."}&"; |
|
| 390 | 390 | } |
| 391 | 391 | } |
| 392 | 392 | } |
| 393 | - if(isset($CallBackConf["BodyVariables"])){ |
|
| 394 | - if(is_array($CallBackConf["BodyVariables"])){ |
|
| 393 | + if (isset($CallBackConf["BodyVariables"])) { |
|
| 394 | + if (is_array($CallBackConf["BodyVariables"])) { |
|
| 395 | 395 | $variables = $CallBackConf["BodyVariables"]; |
| 396 | 396 | foreach ($variables as $key => $value) { |
| 397 | - $body.=$key."=\${kss-".$key."}&"; |
|
| 398 | - $request->addHeader("kss-".$key,$value); |
|
| 397 | + $body .= $key."=\${kss-".$key."}&"; |
|
| 398 | + $request->addHeader("kss-".$key, $value); |
|
| 399 | 399 | } |
| 400 | 400 | } |
| 401 | 401 | } |
| 402 | - if(!empty($body)){ |
|
| 403 | - $body=substr($body,0,strlen($body)-1); |
|
| 404 | - $request->addHeader(Headers::$XKssCallbackBody,$body); |
|
| 402 | + if (!empty($body)) { |
|
| 403 | + $body = substr($body, 0, strlen($body)-1); |
|
| 404 | + $request->addHeader(Headers::$XKssCallbackBody, $body); |
|
| 405 | 405 | } |
| 406 | - $request->addHeader(Headers::$XKssCallbackUrl,$url); |
|
| 406 | + $request->addHeader(Headers::$XKssCallbackUrl, $url); |
|
| 407 | 407 | } |
| 408 | 408 | } |
| 409 | 409 | } |
| 410 | -class SSESigner{ |
|
| 411 | - public function sign(Ks3Request $request,$args=array()){ |
|
| 410 | +class SSESigner { |
|
| 411 | + public function sign(Ks3Request $request, $args = array()) { |
|
| 412 | 412 | $args = $args["args"]; |
| 413 | - if(isset($args["SSE"])){ |
|
| 414 | - if(isset($args["SSE"]["Algm"])) |
|
| 413 | + if (isset($args["SSE"])) { |
|
| 414 | + if (isset($args["SSE"]["Algm"])) |
|
| 415 | 415 | $algm = $args["SSE"]["Algm"]; |
| 416 | - if(isset($args["SSE"]["KMSId"])) |
|
| 416 | + if (isset($args["SSE"]["KMSId"])) |
|
| 417 | 417 | $id = $args["SSE"]["KMSId"]; |
| 418 | - if(!empty($algm)){ |
|
| 419 | - $request->addHeader(Headers::$SSEAlgm,$algm); |
|
| 420 | - if(!empty($id)) |
|
| 421 | - $request->addHeader(Headers::$SSEKMSId,$id); |
|
| 418 | + if (!empty($algm)) { |
|
| 419 | + $request->addHeader(Headers::$SSEAlgm, $algm); |
|
| 420 | + if (!empty($id)) |
|
| 421 | + $request->addHeader(Headers::$SSEKMSId, $id); |
|
| 422 | 422 | } |
| 423 | 423 | } |
| 424 | 424 | } |
| 425 | 425 | } |
| 426 | -class SSECSigner{ |
|
| 427 | - public function sign(Ks3Request $request,$args=array()){ |
|
| 426 | +class SSECSigner { |
|
| 427 | + public function sign(Ks3Request $request, $args = array()) { |
|
| 428 | 428 | $args = $args["args"]; |
| 429 | - if(isset($args["SSEC"])){ |
|
| 430 | - if(isset($args["SSEC"]["Algm"])) |
|
| 429 | + if (isset($args["SSEC"])) { |
|
| 430 | + if (isset($args["SSEC"]["Algm"])) |
|
| 431 | 431 | $algm = $args["SSEC"]["Algm"]; |
| 432 | - if(isset($args["SSEC"]["Key"])) |
|
| 432 | + if (isset($args["SSEC"]["Key"])) |
|
| 433 | 433 | $key = $args["SSEC"]["Key"]; |
| 434 | - if(isset($args["SSEC"]["KeyBase64"])) |
|
| 434 | + if (isset($args["SSEC"]["KeyBase64"])) |
|
| 435 | 435 | $keybase64 = $args["SSEC"]["KeyBase64"]; |
| 436 | - if(isset($args["SSEC"]["KeyMD5"])) |
|
| 436 | + if (isset($args["SSEC"]["KeyMD5"])) |
|
| 437 | 437 | $md5 = $args["SSEC"]["KeyMD5"]; |
| 438 | - if(!empty($key)||!empty($keybase64)){ |
|
| 439 | - if(empty($key)) |
|
| 438 | + if (!empty($key) || !empty($keybase64)) { |
|
| 439 | + if (empty($key)) |
|
| 440 | 440 | $key = base64_decode($keybase64); |
| 441 | - if(empty($algm)) |
|
| 441 | + if (empty($algm)) |
|
| 442 | 442 | $algm = Consts::$SSEDefaultAlgm; |
| 443 | - if(empty($md5)) |
|
| 443 | + if (empty($md5)) |
|
| 444 | 444 | $md5 = Utils::hex_to_base64(md5($key)); |
| 445 | 445 | |
| 446 | - $request->addHeader(Headers::$SSECAlgm,$algm); |
|
| 447 | - $request->addHeader(Headers::$SSECKey,base64_encode($key)); |
|
| 448 | - $request->addHeader(Headers::$SSECMD5,$md5); |
|
| 446 | + $request->addHeader(Headers::$SSECAlgm, $algm); |
|
| 447 | + $request->addHeader(Headers::$SSECKey, base64_encode($key)); |
|
| 448 | + $request->addHeader(Headers::$SSECMD5, $md5); |
|
| 449 | 449 | } |
| 450 | 450 | } |
| 451 | 451 | } |
| 452 | 452 | } |
| 453 | -class SSECSourceSigner{ |
|
| 454 | - public function sign(Ks3Request $request,$args=array()){ |
|
| 453 | +class SSECSourceSigner { |
|
| 454 | + public function sign(Ks3Request $request, $args = array()) { |
|
| 455 | 455 | $args = $args["args"]; |
| 456 | - if(isset($args["SSECSource"])){ |
|
| 457 | - if(isset($args["SSECSource"]["Algm"])) |
|
| 456 | + if (isset($args["SSECSource"])) { |
|
| 457 | + if (isset($args["SSECSource"]["Algm"])) |
|
| 458 | 458 | $algm = $args["SSECSource"]["Algm"]; |
| 459 | - if(isset($args["SSECSource"]["Key"])) |
|
| 459 | + if (isset($args["SSECSource"]["Key"])) |
|
| 460 | 460 | $key = $args["SSECSource"]["Key"]; |
| 461 | - if(isset($args["SSECSource"]["KeyBase64"])) |
|
| 461 | + if (isset($args["SSECSource"]["KeyBase64"])) |
|
| 462 | 462 | $keybase64 = $args["SSECSource"]["KeyBase64"]; |
| 463 | - if(isset($args["SSECSource"]["KeyMD5"])) |
|
| 463 | + if (isset($args["SSECSource"]["KeyMD5"])) |
|
| 464 | 464 | $md5 = $args["SSECSource"]["KeyMD5"]; |
| 465 | - if(!empty($key)||!empty($keybase64)){ |
|
| 466 | - if(empty($key)) |
|
| 465 | + if (!empty($key) || !empty($keybase64)) { |
|
| 466 | + if (empty($key)) |
|
| 467 | 467 | $key = base64_decode($keybase64); |
| 468 | - if(empty($algm)) |
|
| 468 | + if (empty($algm)) |
|
| 469 | 469 | $algm = Consts::$SSEDefaultAlgm; |
| 470 | - if(empty($md5)) |
|
| 470 | + if (empty($md5)) |
|
| 471 | 471 | $md5 = Utils::hex_to_base64(md5($key)); |
| 472 | 472 | |
| 473 | - $request->addHeader(Headers::$SSECSourceAlgm,$algm); |
|
| 474 | - $request->addHeader(Headers::$SSECSourceKey,base64_encode($key)); |
|
| 475 | - $request->addHeader(Headers::$SSECSourceMD5,$md5); |
|
| 473 | + $request->addHeader(Headers::$SSECSourceAlgm, $algm); |
|
| 474 | + $request->addHeader(Headers::$SSECSourceKey, base64_encode($key)); |
|
| 475 | + $request->addHeader(Headers::$SSECSourceMD5, $md5); |
|
| 476 | 476 | } |
| 477 | 477 | } |
| 478 | 478 | } |
| 479 | 479 | } |
| 480 | -class AllHeaderSigner{ |
|
| 481 | - public function sign(Ks3Request $request,$args=array()){ |
|
| 480 | +class AllHeaderSigner { |
|
| 481 | + public function sign(Ks3Request $request, $args = array()) { |
|
| 482 | 482 | $args = $args["args"]; |
| 483 | - $headers = isset($args["Headers"])?$args["Headers"]:""; |
|
| 484 | - if(!empty($headers)&&is_array($headers)){ |
|
| 483 | + $headers = isset($args["Headers"]) ? $args["Headers"] : ""; |
|
| 484 | + if (!empty($headers) && is_array($headers)) { |
|
| 485 | 485 | foreach ($headers as $key => $value) { |
| 486 | - $request->addHeader($key,$value); |
|
| 486 | + $request->addHeader($key, $value); |
|
| 487 | 487 | } |
| 488 | 488 | } |
| 489 | 489 | } |
| 490 | 490 | } |
| 491 | -class AuthUtils{ |
|
| 492 | - public static function canonicalizedKssHeaders(Ks3Request $request){ |
|
| 491 | +class AuthUtils { |
|
| 492 | + public static function canonicalizedKssHeaders(Ks3Request $request) { |
|
| 493 | 493 | $header = ""; |
| 494 | 494 | $headers = $request->headers; |
| 495 | - ksort($headers,SORT_STRING); |
|
| 496 | - foreach ( $headers as $header_key => $header_value ) { |
|
| 497 | - if (substr(strtolower($header_key), 0, 6) === Consts::$KS3HeaderPrefix){ |
|
| 498 | - $header .= "\n".strtolower($header_key) . ':' .$header_value; |
|
| 495 | + ksort($headers, SORT_STRING); |
|
| 496 | + foreach ($headers as $header_key => $header_value) { |
|
| 497 | + if (substr(strtolower($header_key), 0, 6) === Consts::$KS3HeaderPrefix) { |
|
| 498 | + $header .= "\n".strtolower($header_key).':'.$header_value; |
|
| 499 | 499 | } |
| 500 | 500 | } |
| 501 | 501 | $header = substr($header, 1); |
| 502 | 502 | return $header; |
| 503 | 503 | } |
| 504 | - public static function canonicalizedResource(Ks3Request $request){ |
|
| 504 | + public static function canonicalizedResource(Ks3Request $request) { |
|
| 505 | 505 | $resource = "/"; |
| 506 | 506 | $bucket = $request->bucket; |
| 507 | 507 | $key = $request->key; |
| 508 | 508 | $subResource = $request->subResource; |
| 509 | - if(!empty($bucket)){ |
|
| 510 | - $resource.=$request->bucket."/"; |
|
| 509 | + if (!empty($bucket)) { |
|
| 510 | + $resource .= $request->bucket."/"; |
|
| 511 | 511 | } |
| 512 | - if(!empty($key)){ |
|
| 513 | - $resource.=Utils::encodeUrl($request->key); |
|
| 512 | + if (!empty($key)) { |
|
| 513 | + $resource .= Utils::encodeUrl($request->key); |
|
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | $encodeParams = ""; |
| 517 | 517 | $querys = $request->queryParams; |
| 518 | - if(!empty($subResource)){ |
|
| 518 | + if (!empty($subResource)) { |
|
| 519 | 519 | $querys[$subResource] = NULL; |
| 520 | 520 | } |
| 521 | - ksort($querys,SORT_STRING); |
|
| 521 | + ksort($querys, SORT_STRING); |
|
| 522 | 522 | foreach ($querys as $key => $value) { |
| 523 | - if(in_array($key,Consts::$SubResource)||in_array($key,Consts::$QueryParam)){ |
|
| 524 | - if(empty($value)){ |
|
| 525 | - $encodeParams.="&".$key; |
|
| 526 | - }else{ |
|
| 527 | - $encodeParams.="&".$key."=".$value; |
|
| 523 | + if (in_array($key, Consts::$SubResource) || in_array($key, Consts::$QueryParam)) { |
|
| 524 | + if (empty($value)) { |
|
| 525 | + $encodeParams .= "&".$key; |
|
| 526 | + }else { |
|
| 527 | + $encodeParams .= "&".$key."=".$value; |
|
| 528 | 528 | } |
| 529 | 529 | } |
| 530 | 530 | } |
| 531 | - $encodeParams = substr($encodeParams,1); |
|
| 531 | + $encodeParams = substr($encodeParams, 1); |
|
| 532 | 532 | |
| 533 | - $resource = str_replace("//","/%2F", $resource); |
|
| 533 | + $resource = str_replace("//", "/%2F", $resource); |
|
| 534 | 534 | |
| 535 | - if(!empty($encodeParams)){ |
|
| 536 | - $resource.="?".$encodeParams; |
|
| 535 | + if (!empty($encodeParams)) { |
|
| 536 | + $resource .= "?".$encodeParams; |
|
| 537 | 537 | } |
| 538 | 538 | return $resource; |
| 539 | 539 | } |
@@ -1,5 +1,5 @@ |
||
| 1 | 1 | <?php |
| 2 | -class MessageHolder{ |
|
| 2 | +class MessageHolder { |
|
| 3 | 3 | public $msg; |
| 4 | 4 | } |
| 5 | 5 | ?> |
| 6 | 6 | \ No newline at end of file |
@@ -1,11 +1,11 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | require_once KS3_API_PATH.DIRECTORY_SEPARATOR."core".DIRECTORY_SEPARATOR."Utils.class.php"; |
| 3 | 3 | |
| 4 | -class Ks3Request{ |
|
| 4 | +class Ks3Request { |
|
| 5 | 5 | private $bucket; |
| 6 | 6 | private $key; |
| 7 | - private $queryParams=array(); |
|
| 8 | - private $headers=array(); |
|
| 7 | + private $queryParams = array(); |
|
| 8 | + private $headers = array(); |
|
| 9 | 9 | private $subResource; |
| 10 | 10 | private $method; |
| 11 | 11 | private $endpoint; |
@@ -15,11 +15,11 @@ discard block |
||
| 15 | 15 | private $seek_position; |
| 16 | 16 | private $write_stream; |
| 17 | 17 | |
| 18 | - public function __set($property_name, $value){ |
|
| 19 | - $this->$property_name=$value; |
|
| 18 | + public function __set($property_name, $value) { |
|
| 19 | + $this->$property_name = $value; |
|
| 20 | 20 | } |
| 21 | - public function __get($property_name){ |
|
| 22 | - if(isset($this->$property_name)) |
|
| 21 | + public function __get($property_name) { |
|
| 22 | + if (isset($this->$property_name)) |
|
| 23 | 23 | { |
| 24 | 24 | return($this->$property_name); |
| 25 | 25 | }else |
@@ -27,55 +27,55 @@ discard block |
||
| 27 | 27 | return(NULL); |
| 28 | 28 | } |
| 29 | 29 | } |
| 30 | - public function getHeader($key){ |
|
| 31 | - if(isset($this->headers[$key])){ |
|
| 30 | + public function getHeader($key) { |
|
| 31 | + if (isset($this->headers[$key])) { |
|
| 32 | 32 | return $this->headers[$key]; |
| 33 | - }else{ |
|
| 33 | + }else { |
|
| 34 | 34 | return(NULL); |
| 35 | 35 | } |
| 36 | 36 | } |
| 37 | - public function addHeader($key,$value){ |
|
| 37 | + public function addHeader($key, $value) { |
|
| 38 | 38 | $this->headers[$key] = $value; |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - public function getQueryParams($key){ |
|
| 42 | - if(isset($this->queryParams[$key])){ |
|
| 41 | + public function getQueryParams($key) { |
|
| 42 | + if (isset($this->queryParams[$key])) { |
|
| 43 | 43 | return $this->queryParams[$key]; |
| 44 | - }else{ |
|
| 44 | + }else { |
|
| 45 | 45 | return(NULL); |
| 46 | 46 | } |
| 47 | 47 | } |
| 48 | - public function addQueryParams($key,$value){ |
|
| 48 | + public function addQueryParams($key, $value) { |
|
| 49 | 49 | $this->queryParams[$key] = $value; |
| 50 | 50 | } |
| 51 | - public function toUrl($endpoint){ |
|
| 51 | + public function toUrl($endpoint) { |
|
| 52 | 52 | $url = ""; |
| 53 | 53 | $bucket = $this->bucket; |
| 54 | 54 | $key = $this->key; |
| 55 | 55 | $subResource = $this->subResource; |
| 56 | - if(!empty($bucket)){ |
|
| 57 | - if(KS3_API_VHOST){ |
|
| 58 | - $url.=$bucket.".".$endpoint; |
|
| 59 | - }else{ |
|
| 60 | - $url.=$endpoint."/".$bucket; |
|
| 56 | + if (!empty($bucket)) { |
|
| 57 | + if (KS3_API_VHOST) { |
|
| 58 | + $url .= $bucket.".".$endpoint; |
|
| 59 | + }else { |
|
| 60 | + $url .= $endpoint."/".$bucket; |
|
| 61 | 61 | } |
| 62 | - }else{ |
|
| 63 | - $url.=$endpoint; |
|
| 62 | + }else { |
|
| 63 | + $url .= $endpoint; |
|
| 64 | 64 | } |
| 65 | - if(!empty($key)){ |
|
| 66 | - $url.="/".Utils::encodeUrl($key); |
|
| 65 | + if (!empty($key)) { |
|
| 66 | + $url .= "/".Utils::encodeUrl($key); |
|
| 67 | 67 | } |
| 68 | - $url = str_replace("//","/%2F", $url); |
|
| 68 | + $url = str_replace("//", "/%2F", $url); |
|
| 69 | 69 | $queryString = ""; |
| 70 | - if(!empty($subResource)){ |
|
| 71 | - $queryString.="&".$subResource; |
|
| 70 | + if (!empty($subResource)) { |
|
| 71 | + $queryString .= "&".$subResource; |
|
| 72 | 72 | } |
| 73 | 73 | foreach ($this->queryParams as $key => $value) { |
| 74 | - $queryString.="&".$key."=".rawurlencode($value); |
|
| 74 | + $queryString .= "&".$key."=".rawurlencode($value); |
|
| 75 | 75 | } |
| 76 | 76 | $queryString = substr($queryString, 1); |
| 77 | - if(!empty($queryString)){ |
|
| 78 | - $url.="?".$queryString; |
|
| 77 | + if (!empty($queryString)) { |
|
| 78 | + $url .= "?".$queryString; |
|
| 79 | 79 | } |
| 80 | 80 | $url = $this->scheme.$url; |
| 81 | 81 | return $url; |
@@ -1,32 +1,32 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | require_once KS3_API_PATH.DIRECTORY_SEPARATOR."exceptions".DIRECTORY_SEPARATOR."Exceptions.php"; |
| 3 | 3 | |
| 4 | -class Utils{ |
|
| 5 | - public static function encodeUrl($url,$path=TRUE){ |
|
| 4 | +class Utils { |
|
| 5 | + public static function encodeUrl($url, $path = TRUE) { |
|
| 6 | 6 | $url = rawurlencode($url); |
| 7 | 7 | $url = str_replace("+", "%20", $url); |
| 8 | 8 | $url = str_replace("*", "%2A", $url); |
| 9 | 9 | $url = str_replace("%7A", "~", $url); |
| 10 | - if($path){ |
|
| 10 | + if ($path) { |
|
| 11 | 11 | $url = str_replace("%2F", "/", $url); |
| 12 | 12 | } |
| 13 | 13 | return $url; |
| 14 | 14 | } |
| 15 | - public static function hex_to_base64($str){ |
|
| 15 | + public static function hex_to_base64($str) { |
|
| 16 | 16 | $result = ''; |
| 17 | 17 | |
| 18 | - for ($i = 0; $i < strlen($str); $i += 2){ |
|
| 18 | + for ($i = 0; $i < strlen($str); $i += 2) { |
|
| 19 | 19 | $result .= chr(hexdec(substr($str, $i, 2))); |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | return base64_encode($result); |
| 23 | 23 | } |
| 24 | - public static function replaceNS2($str){ |
|
| 24 | + public static function replaceNS2($str) { |
|
| 25 | 25 | $str = str_replace("<ns2:", "<", $str); |
| 26 | 26 | $str = str_replace("</ns2:", "</", $str); |
| 27 | 27 | return $str; |
| 28 | 28 | } |
| 29 | - public static $mime_types = array ( |
|
| 29 | + public static $mime_types = array( |
|
| 30 | 30 | 'apk' => 'application/vnd.android.package-archive', |
| 31 | 31 | '3gp' => 'video/3gpp', 'ai' => 'application/postscript', |
| 32 | 32 | 'aif' => 'audio/x-aiff', 'aifc' => 'audio/x-aiff', |
@@ -137,14 +137,14 @@ discard block |
||
| 137 | 137 | 'zip' => 'application/zip' ); |
| 138 | 138 | |
| 139 | 139 | public static function get_mimetype($ext) { |
| 140 | - return (isset ( self::$mime_types [$ext] ) ? self::$mime_types [$ext] : 'application/octet-stream'); |
|
| 140 | + return (isset (self::$mime_types [$ext]) ? self::$mime_types [$ext] : 'application/octet-stream'); |
|
| 141 | 141 | } |
| 142 | 142 | /** |
| 143 | 143 | * 检测是否含有中文 |
| 144 | 144 | * @param string $subject |
| 145 | 145 | * @return boolean |
| 146 | 146 | */ |
| 147 | - public static function chk_chinese($str){ |
|
| 147 | + public static function chk_chinese($str) { |
|
| 148 | 148 | return preg_match('/[\x80-\xff]./', $str); |
| 149 | 149 | } |
| 150 | 150 | |
@@ -153,18 +153,18 @@ discard block |
||
| 153 | 153 | * @param string $str |
| 154 | 154 | * @return boolean false UTF-8编码 TRUE GB2312编码 |
| 155 | 155 | */ |
| 156 | - public static function is_gb2312($str) { |
|
| 157 | - for($i=0; $i<strlen($str); $i++) { |
|
| 158 | - $v = ord( $str[$i] ); |
|
| 159 | - if( $v > 127) { |
|
| 160 | - if( ($v >= 228) && ($v <= 233) ){ |
|
| 161 | - if( ($i+2) >= (strlen($str) - 1)) return true; // not enough characters |
|
| 162 | - $v1 = ord( $str[$i+1] ); |
|
| 163 | - $v2 = ord( $str[$i+2] ); |
|
| 164 | - if( ($v1 >= 128) && ($v1 <=191) && ($v2 >=128) && ($v2 <= 191) ) |
|
| 165 | - return false; //UTF-8编码 |
|
| 156 | + public static function is_gb2312($str) { |
|
| 157 | + for ($i = 0; $i < strlen($str); $i++) { |
|
| 158 | + $v = ord($str[$i]); |
|
| 159 | + if ($v > 127) { |
|
| 160 | + if (($v >= 228) && ($v <= 233)) { |
|
| 161 | + if (($i+2) >= (strlen($str)-1)) return true; // not enough characters |
|
| 162 | + $v1 = ord($str[$i+1]); |
|
| 163 | + $v2 = ord($str[$i+2]); |
|
| 164 | + if (($v1 >= 128) && ($v1 <= 191) && ($v2 >= 128) && ($v2 <= 191)) |
|
| 165 | + return false; //UTF-8编码 |
|
| 166 | 166 | else |
| 167 | - return true; //GB编码 |
|
| 167 | + return true; //GB编码 |
|
| 168 | 168 | } |
| 169 | 169 | } |
| 170 | 170 | } |
@@ -177,57 +177,57 @@ discard block |
||
| 177 | 177 | * @param boolean $gbk |
| 178 | 178 | * @return boolean |
| 179 | 179 | */ |
| 180 | - public static function check_char($str, $gbk = true){ |
|
| 181 | - for($i=0; $i<strlen($str); $i++) { |
|
| 182 | - $v = ord( $str[$i] ); |
|
| 183 | - if( $v > 127){ |
|
| 184 | - if( ($v >= 228) && ($v <= 233) ){ |
|
| 185 | - if(($i+2)>= (strlen($str)-1)) return $gbk?true:FALSE; // not enough characters |
|
| 186 | - $v1 = ord( $str[$i+1] ); $v2 = ord( $str[$i+2] ); |
|
| 187 | - if($gbk){ |
|
| 188 | - return (($v1 >= 128) && ($v1 <=191) && ($v2 >=128) && ($v2 <= 191))?FALSE:TRUE;//GBK |
|
| 189 | - }else{ |
|
| 190 | - return (($v1 >= 128) && ($v1 <=191) && ($v2 >=128) && ($v2 <= 191))?TRUE:FALSE; |
|
| 180 | + public static function check_char($str, $gbk = true) { |
|
| 181 | + for ($i = 0; $i < strlen($str); $i++) { |
|
| 182 | + $v = ord($str[$i]); |
|
| 183 | + if ($v > 127) { |
|
| 184 | + if (($v >= 228) && ($v <= 233)) { |
|
| 185 | + if (($i+2) >= (strlen($str)-1)) return $gbk ?true:FALSE; // not enough characters |
|
| 186 | + $v1 = ord($str[$i+1]); $v2 = ord($str[$i+2]); |
|
| 187 | + if ($gbk) { |
|
| 188 | + return (($v1 >= 128) && ($v1 <= 191) && ($v2 >= 128) && ($v2 <= 191)) ?FALSE:TRUE; //GBK |
|
| 189 | + }else { |
|
| 190 | + return (($v1 >= 128) && ($v1 <= 191) && ($v2 >= 128) && ($v2 <= 191)) ?TRUE:FALSE; |
|
| 191 | 191 | } |
| 192 | 192 | } |
| 193 | 193 | } |
| 194 | 194 | } |
| 195 | - return $gbk?TRUE:FALSE; |
|
| 195 | + return $gbk ?TRUE:FALSE; |
|
| 196 | 196 | } |
| 197 | - public static function iso8601($time=false) { |
|
| 197 | + public static function iso8601($time = false) { |
|
| 198 | 198 | if ($time === false) $time = time(); |
| 199 | 199 | $date = date('Y-m-d\TH:i:s\.Z', $time); |
| 200 | 200 | return (substr($date, 0, strlen($date)-2).'Z'); |
| 201 | 201 | } |
| 202 | - public static function getFileSize($path){ |
|
| 202 | + public static function getFileSize($path) { |
|
| 203 | 203 | $success = FALSE; |
| 204 | 204 | $isresource = FALSE; |
| 205 | - if(!is_resource($path)){ |
|
| 205 | + if (!is_resource($path)) { |
|
| 206 | 206 | $isresource = FALSE; |
| 207 | - $resource = fopen($path,"r"); |
|
| 208 | - }else{ |
|
| 207 | + $resource = fopen($path, "r"); |
|
| 208 | + }else { |
|
| 209 | 209 | $isresource = TRUE; |
| 210 | 210 | $resource = $path; |
| 211 | 211 | } |
| 212 | 212 | $stat = fstat($resource); |
| 213 | 213 | $size = $stat["size"]; |
| 214 | - if($size<0){ |
|
| 214 | + if ($size < 0) { |
|
| 215 | 215 | $success = FALSE; |
| 216 | - }else{ |
|
| 216 | + }else { |
|
| 217 | 217 | $success = TRUE; |
| 218 | 218 | } |
| 219 | - if($success) |
|
| 219 | + if ($success) |
|
| 220 | 220 | return $size; |
| 221 | - else if($isresource) |
|
| 221 | + else if ($isresource) |
|
| 222 | 222 | throw new Ks3ClientException("please use file path instead resource"); |
| 223 | - if(!((strtoupper(substr(PHP_OS,0,3))=="WIN"))){//如果不是windows系统,尝试使用stat命令 |
|
| 224 | - $size=trim(`stat -c%s $path`); |
|
| 225 | - }else{//如果是windows系统,尝试cmd命令 |
|
| 226 | - if(!class_exists("COM")){ |
|
| 223 | + if (!((strtoupper(substr(PHP_OS, 0, 3)) == "WIN"))) {//如果不是windows系统,尝试使用stat命令 |
|
| 224 | + $size = trim(`stat -c%s $path`); |
|
| 225 | + }else {//如果是windows系统,尝试cmd命令 |
|
| 226 | + if (!class_exists("COM")) { |
|
| 227 | 227 | throw new Ks3ClientException("please add 'extension=php_com_dotnet.dll' and set 'com.allow_dcom = true' in php.ini and restart"); |
| 228 | 228 | } |
| 229 | 229 | $fs = new COM("Scripting.FileSystemObject"); |
| 230 | - $size=$fs->GetFile($path)->Size; |
|
| 230 | + $size = $fs->GetFile($path)->Size; |
|
| 231 | 231 | } |
| 232 | 232 | return $size; |
| 233 | 233 | } |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | signer:请求构造链 |
| 8 | 8 | handler:结果处理链 |
| 9 | 9 | */ |
| 10 | -class API{ |
|
| 10 | +class API { |
|
| 11 | 11 | public static $API = array( |
| 12 | 12 | "getService"=>array( |
| 13 | 13 | "redirect"=>"listBuckets" |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | "needBucket"=>TRUE, |
| 74 | 74 | "needObject"=>FALSE, |
| 75 | 75 | "signer"=>"DefaultUserAgentSigner->DefaultContentTypeSigner->HeaderAuthSigner", |
| 76 | - "queryParams"=>array("Options->prefix","Options->delimiter","Options->marker","Options->max-keys"), |
|
| 76 | + "queryParams"=>array("Options->prefix", "Options->delimiter", "Options->marker", "Options->max-keys"), |
|
| 77 | 77 | "handler"=>"ErrorResponseHandler->ListObjectsHandler" |
| 78 | 78 | ), |
| 79 | 79 | "getBucketAcl" => array( |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | "needBucket"=>TRUE, |
| 114 | 114 | "needObject"=>FALSE, |
| 115 | 115 | "subResource"=>"uploads", |
| 116 | - "queryParams"=>array("Options->max-uploads","Options->key-marker","Options->prefix","Options->upload-id-marker","Options->delimiter"), |
|
| 116 | + "queryParams"=>array("Options->max-uploads", "Options->key-marker", "Options->prefix", "Options->upload-id-marker", "Options->delimiter"), |
|
| 117 | 117 | "signer"=>"DefaultUserAgentSigner->DefaultContentTypeSigner->HeaderAuthSigner", |
| 118 | 118 | "handler"=>"ErrorResponseHandler->ListMutipartUploadsHandler" |
| 119 | 119 | ), |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | "method"=>"PUT", |
| 213 | 213 | "needBucket"=>TRUE, |
| 214 | 214 | "needObject"=>TRUE, |
| 215 | - "queryParams"=>array("!Options->uploadId","!Options->partNumber"), |
|
| 215 | + "queryParams"=>array("!Options->uploadId", "!Options->partNumber"), |
|
| 216 | 216 | //这个请求没有body,所以使用了ContentLengthSigner->ContentMD5Signer而没用ObjectMetaSigner |
| 217 | 217 | "signer"=>"DefaultUserAgentSigner->ACLSigner->StreamContentTypeSigner->ContentLengthSigner->ContentMD5Signer->SSECSigner->StreamUploadSigner->HeaderAuthSigner", |
| 218 | 218 | "handler"=>"ErrorResponseHandler->UploadHandler" |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | "method"=>"GET", |
| 230 | 230 | "needBucket"=>TRUE, |
| 231 | 231 | "needObject"=>TRUE, |
| 232 | - "queryParams"=>array("!Options->uploadId","Options->max-parts","Options->part-number-marker"), |
|
| 232 | + "queryParams"=>array("!Options->uploadId", "Options->max-parts", "Options->part-number-marker"), |
|
| 233 | 233 | "signer"=>"DefaultUserAgentSigner->DefaultContentTypeSigner->HeaderAuthSigner", |
| 234 | 234 | "handler"=>"ErrorResponseHandler->ListPartsHandler" |
| 235 | 235 | ), |
@@ -246,7 +246,7 @@ discard block |
||
| 246 | 246 | "method"=>"Method", |
| 247 | 247 | "needBucket"=>FALSE, |
| 248 | 248 | "needObject"=>FALSE, |
| 249 | - "queryParams"=>array("!Options->Expires","Options->*"), |
|
| 249 | + "queryParams"=>array("!Options->Expires", "Options->*"), |
|
| 250 | 250 | "signer"=>"AllHeaderSigner->QueryAuthSigner", |
| 251 | 251 | ), |
| 252 | 252 | "putAdp"=>array( |
@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | "method"=>"GET", |
| 262 | 262 | "needBucket"=>FALSE, |
| 263 | 263 | "needObject"=>TRUE, |
| 264 | - "objectPostion"=>"TaskID",//专门为这个接口定义的属性 |
|
| 264 | + "objectPostion"=>"TaskID", //专门为这个接口定义的属性 |
|
| 265 | 265 | "subResource"=>"queryadp", |
| 266 | 266 | "signer"=>"DefaultUserAgentSigner", |
| 267 | 267 | "handler"=>"ErrorResponseHandler->AdpHandler" |
@@ -1,66 +1,66 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | require_once KS3_API_PATH.DIRECTORY_SEPARATOR."exceptions".DIRECTORY_SEPARATOR."Exceptions.php"; |
| 3 | 3 | |
| 4 | -interface Handler{ |
|
| 4 | +interface Handler { |
|
| 5 | 5 | public function handle(ResponseCore $response); |
| 6 | 6 | } |
| 7 | -class ErrorResponseHandler implements Handler{ |
|
| 8 | - public function handle(ResponseCore $response){ |
|
| 7 | +class ErrorResponseHandler implements Handler { |
|
| 8 | + public function handle(ResponseCore $response) { |
|
| 9 | 9 | $code = $response->status; |
| 10 | - if($code >= 400){ |
|
| 10 | + if ($code >= 400) { |
|
| 11 | 11 | $exception = new Ks3ServiceException(); |
| 12 | - $exception->statusCode=$code; |
|
| 13 | - if(!empty($response->body)){ |
|
| 12 | + $exception->statusCode = $code; |
|
| 13 | + if (!empty($response->body)) { |
|
| 14 | 14 | $xml = new SimpleXMLElement($response->body); |
| 15 | 15 | $exception ->requestId = $xml->RequestId->__toString(); |
| 16 | 16 | $exception->errorCode = $xml->Code->__toString(); |
| 17 | - $exception->errorMessage=$xml->Message->__toString(); |
|
| 18 | - $exception->resource=$xml->Resource->__toString(); |
|
| 17 | + $exception->errorMessage = $xml->Message->__toString(); |
|
| 18 | + $exception->resource = $xml->Resource->__toString(); |
|
| 19 | 19 | } |
| 20 | 20 | throw $exception; |
| 21 | - }else{ |
|
| 21 | + }else { |
|
| 22 | 22 | return $response; |
| 23 | 23 | } |
| 24 | 24 | } |
| 25 | 25 | } |
| 26 | -class ListBucketsHandler implements Handler{ |
|
| 26 | +class ListBucketsHandler implements Handler { |
|
| 27 | 27 | |
| 28 | - public function handle(ResponseCore $response){ |
|
| 28 | + public function handle(ResponseCore $response) { |
|
| 29 | 29 | $result = array(); |
| 30 | 30 | $xml = new SimpleXMLElement($response->body); |
| 31 | 31 | foreach ($xml->Buckets->Bucket as $bucketXml) { |
| 32 | 32 | $bucket = array(); |
| 33 | 33 | foreach ($bucketXml->children() as $key => $value) { |
| 34 | - $bucket[$key]=$value->__toString(); |
|
| 34 | + $bucket[$key] = $value->__toString(); |
|
| 35 | 35 | } |
| 36 | 36 | array_push($result, $bucket); |
| 37 | 37 | } |
| 38 | 38 | return $result; |
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | -class ListObjectsHandler implements Handler{ |
|
| 42 | - public function handle(ResponseCore $response){ |
|
| 41 | +class ListObjectsHandler implements Handler { |
|
| 42 | + public function handle(ResponseCore $response) { |
|
| 43 | 43 | $result = array(); |
| 44 | 44 | $xml = new SimpleXMLElement($response->body); |
| 45 | - $result["Name"]=$xml->Name->__toString(); |
|
| 46 | - $result["Prefix"]=$xml->Prefix->__toString(); |
|
| 47 | - $result["Marker"]=$xml->Marker->__toString(); |
|
| 48 | - $result["Delimiter"]=$xml->Delimiter->__toString(); |
|
| 49 | - $result["MaxKeys"]=$xml->MaxKeys->__toString(); |
|
| 50 | - $result["IsTruncated"]=$xml->IsTruncated->__toString(); |
|
| 51 | - $result["NextMarker"]=$xml->NextMarker->__toString(); |
|
| 45 | + $result["Name"] = $xml->Name->__toString(); |
|
| 46 | + $result["Prefix"] = $xml->Prefix->__toString(); |
|
| 47 | + $result["Marker"] = $xml->Marker->__toString(); |
|
| 48 | + $result["Delimiter"] = $xml->Delimiter->__toString(); |
|
| 49 | + $result["MaxKeys"] = $xml->MaxKeys->__toString(); |
|
| 50 | + $result["IsTruncated"] = $xml->IsTruncated->__toString(); |
|
| 51 | + $result["NextMarker"] = $xml->NextMarker->__toString(); |
|
| 52 | 52 | $contents = array(); |
| 53 | 53 | foreach ($xml->Contents as $contentXml) { |
| 54 | 54 | $content = array(); |
| 55 | 55 | foreach ($contentXml->children() as $key => $value) { |
| 56 | 56 | $owner = array(); |
| 57 | - if($key === "Owner"){ |
|
| 57 | + if ($key === "Owner") { |
|
| 58 | 58 | foreach ($value->children() as $ownerkey => $ownervalue) { |
| 59 | - $owner[$ownerkey]=$ownervalue->__toString(); |
|
| 59 | + $owner[$ownerkey] = $ownervalue->__toString(); |
|
| 60 | 60 | } |
| 61 | 61 | $content["Owner"] = $owner; |
| 62 | - }else{ |
|
| 63 | - $content[$key]=$value->__toString(); |
|
| 62 | + }else { |
|
| 63 | + $content[$key] = $value->__toString(); |
|
| 64 | 64 | } |
| 65 | 65 | } |
| 66 | 66 | array_push($contents, $content); |
@@ -77,62 +77,62 @@ discard block |
||
| 77 | 77 | return $result; |
| 78 | 78 | } |
| 79 | 79 | } |
| 80 | -class GetBucketCORSHandler implements Handler{ |
|
| 81 | - public function handle(ResponseCore $response){ |
|
| 80 | +class GetBucketCORSHandler implements Handler { |
|
| 81 | + public function handle(ResponseCore $response) { |
|
| 82 | 82 | $xml = new SimpleXMLElement($response->body); |
| 83 | 83 | $cors = array(); |
| 84 | 84 | foreach ($xml->CORSRule as $rule) { |
| 85 | 85 | $acors = array(); |
| 86 | 86 | foreach ($rule as $key => $value) { |
| 87 | - if($key === "MaxAgeSeconds") |
|
| 87 | + if ($key === "MaxAgeSeconds") |
|
| 88 | 88 | { |
| 89 | 89 | $acors[$key] = $value->__toString(); |
| 90 | - }else{ |
|
| 91 | - if(!isset($acors[$key])){ |
|
| 90 | + }else { |
|
| 91 | + if (!isset($acors[$key])) { |
|
| 92 | 92 | $acors[$key] = array(); |
| 93 | 93 | } |
| 94 | - array_push($acors[$key],$value->__toString()); |
|
| 94 | + array_push($acors[$key], $value->__toString()); |
|
| 95 | 95 | } |
| 96 | 96 | } |
| 97 | - array_push($cors,$acors); |
|
| 97 | + array_push($cors, $acors); |
|
| 98 | 98 | } |
| 99 | 99 | return $cors; |
| 100 | 100 | } |
| 101 | 101 | } |
| 102 | -class GetBucketLocationHandler implements Handler{ |
|
| 103 | - public function handle(ResponseCore $response){ |
|
| 102 | +class GetBucketLocationHandler implements Handler { |
|
| 103 | + public function handle(ResponseCore $response) { |
|
| 104 | 104 | $xml = new SimpleXMLElement($response->body); |
| 105 | 105 | $location = $xml->__toString(); |
| 106 | 106 | |
| 107 | 107 | return $location; |
| 108 | 108 | } |
| 109 | 109 | } |
| 110 | -class GetBucketLoggingHandler implements Handler{ |
|
| 111 | - public function handle(ResponseCore $response){ |
|
| 110 | +class GetBucketLoggingHandler implements Handler { |
|
| 111 | + public function handle(ResponseCore $response) { |
|
| 112 | 112 | $logging = array(); |
| 113 | 113 | $xml = new SimpleXMLElement($response->body); |
| 114 | 114 | $loggingXml = $xml->LoggingEnabled; |
| 115 | - if($loggingXml&&$loggingXml!==NULL) |
|
| 115 | + if ($loggingXml && $loggingXml !== NULL) |
|
| 116 | 116 | { |
| 117 | 117 | foreach ($loggingXml->children() as $key => $value) { |
| 118 | 118 | $logging["Enable"] = TRUE; |
| 119 | 119 | $logging[$key] = $value->__toString(); |
| 120 | 120 | } |
| 121 | - }else{ |
|
| 121 | + }else { |
|
| 122 | 122 | $logging["Enable"] = FALSE; |
| 123 | 123 | } |
| 124 | 124 | return $logging; |
| 125 | 125 | } |
| 126 | 126 | } |
| 127 | -class ObjectMetaHandler implements Handler{ |
|
| 128 | - public function handle(ResponseCore $response){ |
|
| 127 | +class ObjectMetaHandler implements Handler { |
|
| 128 | + public function handle(ResponseCore $response) { |
|
| 129 | 129 | $ObjectMeta = array(); |
| 130 | 130 | $UserMeta = array(); |
| 131 | 131 | foreach ($response->header as $key => $value) { |
| 132 | - if (substr(strtolower($key), 0, 10) === Consts::$UserMetaPrefix){ |
|
| 133 | - $UserMeta[$key]=$value; |
|
| 134 | - }else if(isset(Consts::$ResponseObjectMeta[strtolower($key)])){ |
|
| 135 | - $ObjectMeta[Consts::$ResponseObjectMeta[strtolower($key)]]=$value; |
|
| 132 | + if (substr(strtolower($key), 0, 10) === Consts::$UserMetaPrefix) { |
|
| 133 | + $UserMeta[$key] = $value; |
|
| 134 | + }else if (isset(Consts::$ResponseObjectMeta[strtolower($key)])) { |
|
| 135 | + $ObjectMeta[Consts::$ResponseObjectMeta[strtolower($key)]] = $value; |
|
| 136 | 136 | } |
| 137 | 137 | } |
| 138 | 138 | $Meta = array( |
@@ -142,15 +142,15 @@ discard block |
||
| 142 | 142 | return $Meta; |
| 143 | 143 | } |
| 144 | 144 | } |
| 145 | -class getObjectHandler implements Handler{ |
|
| 146 | - public function handle(ResponseCore $response){ |
|
| 145 | +class getObjectHandler implements Handler { |
|
| 146 | + public function handle(ResponseCore $response) { |
|
| 147 | 147 | $ObjectMeta = array(); |
| 148 | 148 | $UserMeta = array(); |
| 149 | 149 | foreach ($response->header as $key => $value) { |
| 150 | - if (substr(strtolower($key), 0, 10) === Consts::$UserMetaPrefix){ |
|
| 151 | - $UserMeta[$key]=$value; |
|
| 152 | - }else if(isset(Consts::$ResponseObjectMeta[strtolower($key)])){ |
|
| 153 | - $ObjectMeta[Consts::$ResponseObjectMeta[strtolower($key)]]=$value; |
|
| 150 | + if (substr(strtolower($key), 0, 10) === Consts::$UserMetaPrefix) { |
|
| 151 | + $UserMeta[$key] = $value; |
|
| 152 | + }else if (isset(Consts::$ResponseObjectMeta[strtolower($key)])) { |
|
| 153 | + $ObjectMeta[Consts::$ResponseObjectMeta[strtolower($key)]] = $value; |
|
| 154 | 154 | } |
| 155 | 155 | } |
| 156 | 156 | $Meta = array( |
@@ -164,21 +164,21 @@ discard block |
||
| 164 | 164 | return $ks3Object; |
| 165 | 165 | } |
| 166 | 166 | } |
| 167 | -class CopyHandler implements Handler{ |
|
| 168 | - public function handle(ResponseCore $response){ |
|
| 167 | +class CopyHandler implements Handler { |
|
| 168 | + public function handle(ResponseCore $response) { |
|
| 169 | 169 | $headers = array(); |
| 170 | 170 | |
| 171 | 171 | foreach ($response->header as $key => $value) { |
| 172 | - if(isset(Consts::$SSEHandler[strtolower($key)])&&!empty($value)){ |
|
| 173 | - $headers[Consts::$SSEHandler[strtolower($key)]]=$value; |
|
| 172 | + if (isset(Consts::$SSEHandler[strtolower($key)]) && !empty($value)) { |
|
| 173 | + $headers[Consts::$SSEHandler[strtolower($key)]] = $value; |
|
| 174 | 174 | } |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | return $headers; |
| 178 | 178 | } |
| 179 | 179 | } |
| 180 | -class InitMultipartUploadHandler implements Handler{ |
|
| 181 | - public function handle(ResponseCore $response){ |
|
| 180 | +class InitMultipartUploadHandler implements Handler { |
|
| 181 | + public function handle(ResponseCore $response) { |
|
| 182 | 182 | $upload = array(); |
| 183 | 183 | $xml = new SimpleXMLElement($response->body); |
| 184 | 184 | foreach ($xml->children() as $key => $value) { |
@@ -186,27 +186,27 @@ discard block |
||
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | foreach ($response->header as $key => $value) { |
| 189 | - if(isset(Consts::$SSEHandler[strtolower($key)])&&!empty($value)){ |
|
| 190 | - $upload[Consts::$SSEHandler[strtolower($key)]]=$value; |
|
| 189 | + if (isset(Consts::$SSEHandler[strtolower($key)]) && !empty($value)) { |
|
| 190 | + $upload[Consts::$SSEHandler[strtolower($key)]] = $value; |
|
| 191 | 191 | } |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | return $upload; |
| 195 | 195 | } |
| 196 | 196 | } |
| 197 | -class ListPartsHandler implements Handler{ |
|
| 198 | - public function handle(ResponseCore $response){ |
|
| 197 | +class ListPartsHandler implements Handler { |
|
| 198 | + public function handle(ResponseCore $response) { |
|
| 199 | 199 | $listParts = array(); |
| 200 | 200 | $xml = new SimpleXMLElement($response->body); |
| 201 | 201 | |
| 202 | - $listParts["Bucket"]=$xml->Bucket->__toString(); |
|
| 203 | - $listParts["Key"]=$xml->Key->__toString(); |
|
| 204 | - $listParts["UploadId"]=$xml->UploadId->__toString(); |
|
| 205 | - $listParts["StorageClass"]=$xml->StorageClass->__toString(); |
|
| 206 | - $listParts["PartNumberMarker"]=$xml->PartNumberMarker->__toString(); |
|
| 207 | - $listParts["NextPartNumberMarker"]=$xml->NextPartNumberMarker->__toString(); |
|
| 208 | - $listParts["MaxParts"]=$xml->MaxParts->__toString(); |
|
| 209 | - $listParts["IsTruncated"]=$xml->IsTruncated->__toString(); |
|
| 202 | + $listParts["Bucket"] = $xml->Bucket->__toString(); |
|
| 203 | + $listParts["Key"] = $xml->Key->__toString(); |
|
| 204 | + $listParts["UploadId"] = $xml->UploadId->__toString(); |
|
| 205 | + $listParts["StorageClass"] = $xml->StorageClass->__toString(); |
|
| 206 | + $listParts["PartNumberMarker"] = $xml->PartNumberMarker->__toString(); |
|
| 207 | + $listParts["NextPartNumberMarker"] = $xml->NextPartNumberMarker->__toString(); |
|
| 208 | + $listParts["MaxParts"] = $xml->MaxParts->__toString(); |
|
| 209 | + $listParts["IsTruncated"] = $xml->IsTruncated->__toString(); |
|
| 210 | 210 | |
| 211 | 211 | $initer = array(); |
| 212 | 212 | $owner = array(); |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | $owner[$key] = $value->__toString(); |
| 219 | 219 | } |
| 220 | 220 | $listParts["Owner"] = $owner; |
| 221 | - $listParts["Initiator"]=$initer; |
|
| 221 | + $listParts["Initiator"] = $initer; |
|
| 222 | 222 | |
| 223 | 223 | $parts = array(); |
| 224 | 224 | foreach ($xml->Part as $partxml) { |
@@ -226,25 +226,25 @@ discard block |
||
| 226 | 226 | foreach ($partxml->children() as $key => $value) { |
| 227 | 227 | $part[$key] = $value->__toString(); |
| 228 | 228 | } |
| 229 | - array_push($parts,$part); |
|
| 229 | + array_push($parts, $part); |
|
| 230 | 230 | } |
| 231 | 231 | $listParts["Parts"] = $parts; |
| 232 | 232 | return $listParts; |
| 233 | 233 | } |
| 234 | 234 | } |
| 235 | -class UploadHandler implements Handler{ |
|
| 236 | - public function handle(ResponseCore $response){ |
|
| 235 | +class UploadHandler implements Handler { |
|
| 236 | + public function handle(ResponseCore $response) { |
|
| 237 | 237 | $Headers = array(); |
| 238 | 238 | foreach ($response->header as $key => $value) { |
| 239 | - if(isset(Consts::$UploadHandler[strtolower($key)])&&!empty($value)){ |
|
| 240 | - $Headers[Consts::$UploadHandler[strtolower($key)]]=$value; |
|
| 239 | + if (isset(Consts::$UploadHandler[strtolower($key)]) && !empty($value)) { |
|
| 240 | + $Headers[Consts::$UploadHandler[strtolower($key)]] = $value; |
|
| 241 | 241 | } |
| 242 | 242 | } |
| 243 | 243 | return $Headers; |
| 244 | 244 | } |
| 245 | 245 | } |
| 246 | -class GetAclHandler implements Handler{ |
|
| 247 | - public function handle(ResponseCore $response){ |
|
| 246 | +class GetAclHandler implements Handler { |
|
| 247 | + public function handle(ResponseCore $response) { |
|
| 248 | 248 | $hasread = FALSE; |
| 249 | 249 | $haswrite = FALSE; |
| 250 | 250 | $xml = new SimpleXMLElement($response->body); |
@@ -254,88 +254,88 @@ discard block |
||
| 254 | 254 | $hasURI = FALSE; |
| 255 | 255 | $grantee = $grant->Grantee; |
| 256 | 256 | foreach ($grantee->children() as $key => $value) { |
| 257 | - if($key === "URI"&&$value->__toString() === Consts::$Grantee_Group_All){ |
|
| 257 | + if ($key === "URI" && $value->__toString() === Consts::$Grantee_Group_All) { |
|
| 258 | 258 | $hasURI = TRUE; |
| 259 | 259 | } |
| 260 | 260 | } |
| 261 | - if($hasURI){ |
|
| 262 | - if($permission===Consts::$Permission_Read){ |
|
| 261 | + if ($hasURI) { |
|
| 262 | + if ($permission === Consts::$Permission_Read) { |
|
| 263 | 263 | $hasread = TRUE; |
| 264 | - }elseif($permission===Consts::$Permission_Write){ |
|
| 264 | + }elseif ($permission === Consts::$Permission_Write) { |
|
| 265 | 265 | $haswrite = TRUE; |
| 266 | 266 | } |
| 267 | 267 | } |
| 268 | 268 | } |
| 269 | - if($hasread&&$haswrite){ |
|
| 269 | + if ($hasread && $haswrite) { |
|
| 270 | 270 | return "public-read-write"; |
| 271 | - }else{ |
|
| 272 | - if($hasread) |
|
| 271 | + }else { |
|
| 272 | + if ($hasread) |
|
| 273 | 273 | return "public-read"; |
| 274 | 274 | else |
| 275 | 275 | return "private"; |
| 276 | 276 | } |
| 277 | 277 | } |
| 278 | 278 | } |
| 279 | -class ListMutipartUploadsHandler implements Handler{ |
|
| 280 | - public function handle(ResponseCore $response){ |
|
| 279 | +class ListMutipartUploadsHandler implements Handler { |
|
| 280 | + public function handle(ResponseCore $response) { |
|
| 281 | 281 | $mutiUploads = array(); |
| 282 | 282 | $xml = new SimpleXMLElement($response->body); |
| 283 | 283 | |
| 284 | - $mutiUploads["Bucket"]=$xml->Bucket->__toString(); |
|
| 285 | - $mutiUploads["KeyMarker"]=$xml->KeyMarker->__toString(); |
|
| 286 | - $mutiUploads["UploadIdMarker"]=$xml->UploadIdMarker->__toString(); |
|
| 287 | - $mutiUploads["NextKeyMarker"]=$xml->NextKeyMarker->__toString(); |
|
| 288 | - $mutiUploads["NextUploadIdMarker"]=$xml->NextUploadIdMarker->__toString(); |
|
| 289 | - $mutiUploads["MaxUploads"]=$xml->MaxUploads->__toString(); |
|
| 290 | - $mutiUploads["IsTruncated"]=$xml->IsTruncated->__toString(); |
|
| 284 | + $mutiUploads["Bucket"] = $xml->Bucket->__toString(); |
|
| 285 | + $mutiUploads["KeyMarker"] = $xml->KeyMarker->__toString(); |
|
| 286 | + $mutiUploads["UploadIdMarker"] = $xml->UploadIdMarker->__toString(); |
|
| 287 | + $mutiUploads["NextKeyMarker"] = $xml->NextKeyMarker->__toString(); |
|
| 288 | + $mutiUploads["NextUploadIdMarker"] = $xml->NextUploadIdMarker->__toString(); |
|
| 289 | + $mutiUploads["MaxUploads"] = $xml->MaxUploads->__toString(); |
|
| 290 | + $mutiUploads["IsTruncated"] = $xml->IsTruncated->__toString(); |
|
| 291 | 291 | |
| 292 | 292 | |
| 293 | 293 | $uploads = array(); |
| 294 | 294 | foreach ($xml->Upload as $uploadxml) { |
| 295 | 295 | $upload = array(); |
| 296 | 296 | foreach ($uploadxml->children() as $key => $value) { |
| 297 | - if($key === "Initiator"){ |
|
| 297 | + if ($key === "Initiator") { |
|
| 298 | 298 | $initer = array(); |
| 299 | 299 | foreach ($value->children() as $key1 => $value1) { |
| 300 | 300 | $initer[$key1] = $value1->__toString(); |
| 301 | 301 | } |
| 302 | 302 | $upload["Initiator"] = $initer; |
| 303 | - }elseif($key === "Owner"){ |
|
| 303 | + }elseif ($key === "Owner") { |
|
| 304 | 304 | $owner = array(); |
| 305 | 305 | foreach ($value->children() as $key1 => $value1) { |
| 306 | 306 | $owner[$key1] = $value1->__toString(); |
| 307 | 307 | } |
| 308 | 308 | $upload["Owner"] = $owner; |
| 309 | - }else{ |
|
| 309 | + }else { |
|
| 310 | 310 | $upload[$key] = $value->__toString(); |
| 311 | 311 | } |
| 312 | 312 | } |
| 313 | - array_push($uploads,$upload); |
|
| 313 | + array_push($uploads, $upload); |
|
| 314 | 314 | } |
| 315 | 315 | $mutiUploads["Uploads"] = $uploads; |
| 316 | 316 | return $mutiUploads; |
| 317 | 317 | } |
| 318 | 318 | } |
| 319 | -class AdpHandler implements Handler{ |
|
| 320 | - public function handle(ResponseCore $response){ |
|
| 319 | +class AdpHandler implements Handler { |
|
| 320 | + public function handle(ResponseCore $response) { |
|
| 321 | 321 | return $response->body; |
| 322 | 322 | } |
| 323 | 323 | } |
| 324 | -class BooleanHandler implements Handler{ |
|
| 325 | - public function handle(ResponseCore $response){ |
|
| 326 | - if($response->isOk()){ |
|
| 324 | +class BooleanHandler implements Handler { |
|
| 325 | + public function handle(ResponseCore $response) { |
|
| 326 | + if ($response->isOk()) { |
|
| 327 | 327 | return TRUE; |
| 328 | - }else{ |
|
| 328 | + }else { |
|
| 329 | 329 | return FALSE; |
| 330 | 330 | } |
| 331 | 331 | } |
| 332 | 332 | } |
| 333 | -class ExistsHandler implements Handler{ |
|
| 334 | - public function handle(ResponseCore $response){ |
|
| 333 | +class ExistsHandler implements Handler { |
|
| 334 | + public function handle(ResponseCore $response) { |
|
| 335 | 335 | $status = $response->status; |
| 336 | - if($status === 404){ |
|
| 336 | + if ($status === 404) { |
|
| 337 | 337 | return FALSE; |
| 338 | - }else{ |
|
| 338 | + }else { |
|
| 339 | 339 | return TRUE; |
| 340 | 340 | } |
| 341 | 341 | } |
@@ -387,7 +387,7 @@ discard block |
||
| 387 | 387 | |
| 388 | 388 | if ($position !== false && $position >= 0) |
| 389 | 389 | { |
| 390 | - $size = $stats['size'] - $position; |
|
| 390 | + $size = $stats['size']-$position; |
|
| 391 | 391 | } |
| 392 | 392 | } |
| 393 | 393 | } |
@@ -462,7 +462,7 @@ discard block |
||
| 462 | 462 | */ |
| 463 | 463 | public function set_seek_position($position) |
| 464 | 464 | { |
| 465 | - $this->seek_position = isset($position) ? (integer) $position : null; |
|
| 465 | + $this->seek_position = isset($position) ? (integer)$position : null; |
|
| 466 | 466 | |
| 467 | 467 | return $this; |
| 468 | 468 | } |
@@ -533,7 +533,7 @@ discard block |
||
| 533 | 533 | // Execute callback function |
| 534 | 534 | if ($this->registered_streaming_read_callback) |
| 535 | 535 | { |
| 536 | - return $this->registered_streaming_read_callback->streaming_read_callback($curl_handle, $file_handle, $length,$this->read_stream,$this->seek_position); |
|
| 536 | + return $this->registered_streaming_read_callback->streaming_read_callback($curl_handle, $file_handle, $length, $this->read_stream, $this->seek_position); |
|
| 537 | 537 | } |
| 538 | 538 | // Once we've sent as much as we're supposed to send... |
| 539 | 539 | if ($this->read_stream_read >= $this->read_stream_size) |
@@ -551,7 +551,7 @@ discard block |
||
| 551 | 551 | } |
| 552 | 552 | } |
| 553 | 553 | |
| 554 | - $read = fread($this->read_stream, min($this->read_stream_size - $this->read_stream_read, $length)); // Remaining upload data or cURL's requested chunk size |
|
| 554 | + $read = fread($this->read_stream, min($this->read_stream_size-$this->read_stream_read, $length)); // Remaining upload data or cURL's requested chunk size |
|
| 555 | 555 | $this->read_stream_read += strlen($read); |
| 556 | 556 | |
| 557 | 557 | $out = $read === false ? '' : $read; |
@@ -568,8 +568,8 @@ discard block |
||
| 568 | 568 | */ |
| 569 | 569 | public function streaming_write_callback($curl_handle, $data) |
| 570 | 570 | { |
| 571 | - if ($this->registered_streaming_write_callback){ |
|
| 572 | - return $this->registered_streaming_write_callback->streaming_write_callback($curl_handle,$data,$this->write_stream); |
|
| 571 | + if ($this->registered_streaming_write_callback) { |
|
| 572 | + return $this->registered_streaming_write_callback->streaming_write_callback($curl_handle, $data, $this->write_stream); |
|
| 573 | 573 | } |
| 574 | 574 | $length = strlen($data); |
| 575 | 575 | $written_total = 0; |
@@ -631,7 +631,7 @@ discard block |
||
| 631 | 631 | // chmod the file as 0755 |
| 632 | 632 | if ($this->cacert_location === true) |
| 633 | 633 | { |
| 634 | - curl_setopt($curl_handle, CURLOPT_CAINFO, dirname(__FILE__) . '/cacert.pem'); |
|
| 634 | + curl_setopt($curl_handle, CURLOPT_CAINFO, dirname(__FILE__).'/cacert.pem'); |
|
| 635 | 635 | } |
| 636 | 636 | elseif (is_string($this->cacert_location)) |
| 637 | 637 | { |
@@ -656,12 +656,12 @@ discard block |
||
| 656 | 656 | curl_setopt($curl_handle, CURLOPT_HTTPPROXYTUNNEL, true); |
| 657 | 657 | |
| 658 | 658 | $host = $this->proxy['host']; |
| 659 | - $host .= ($this->proxy['port']) ? ':' . $this->proxy['port'] : ''; |
|
| 659 | + $host .= ($this->proxy['port']) ? ':'.$this->proxy['port'] : ''; |
|
| 660 | 660 | curl_setopt($curl_handle, CURLOPT_PROXY, $host); |
| 661 | 661 | |
| 662 | 662 | if (isset($this->proxy['user']) && isset($this->proxy['pass'])) |
| 663 | 663 | { |
| 664 | - curl_setopt($curl_handle, CURLOPT_PROXYUSERPWD, $this->proxy['user'] . ':' . $this->proxy['pass']); |
|
| 664 | + curl_setopt($curl_handle, CURLOPT_PROXYUSERPWD, $this->proxy['user'].':'.$this->proxy['pass']); |
|
| 665 | 665 | } |
| 666 | 666 | } |
| 667 | 667 | |
@@ -669,7 +669,7 @@ discard block |
||
| 669 | 669 | if ($this->username && $this->password) |
| 670 | 670 | { |
| 671 | 671 | curl_setopt($curl_handle, CURLOPT_HTTPAUTH, CURLAUTH_ANY); |
| 672 | - curl_setopt($curl_handle, CURLOPT_USERPWD, $this->username . ':' . $this->password); |
|
| 672 | + curl_setopt($curl_handle, CURLOPT_USERPWD, $this->username.':'.$this->password); |
|
| 673 | 673 | } |
| 674 | 674 | |
| 675 | 675 | // Handle the encoding if we can. |
@@ -685,7 +685,7 @@ discard block |
||
| 685 | 685 | |
| 686 | 686 | foreach ($this->request_headers as $k => $v) |
| 687 | 687 | { |
| 688 | - $temp_headers[] = $k . ': ' . $v; |
|
| 688 | + $temp_headers[] = $k.': '.$v; |
|
| 689 | 689 | } |
| 690 | 690 | |
| 691 | 691 | curl_setopt($curl_handle, CURLOPT_HTTPHEADER, $temp_headers); |
@@ -787,7 +787,7 @@ discard block |
||
| 787 | 787 | foreach ($this->response_headers as $header) |
| 788 | 788 | { |
| 789 | 789 | $kv = explode(': ', $header); |
| 790 | - $header_assoc[strtolower($kv[0])] = isset($kv[1])?$kv[1]:''; |
|
| 790 | + $header_assoc[strtolower($kv[0])] = isset($kv[1]) ? $kv[1] : ''; |
|
| 791 | 791 | } |
| 792 | 792 | |
| 793 | 793 | // Reset the headers to the appropriate property. |
@@ -820,7 +820,7 @@ discard block |
||
| 820 | 820 | |
| 821 | 821 | if ($this->response === false) |
| 822 | 822 | { |
| 823 | - throw new RequestCore_Exception('cURL resource: ' . (string) $curl_handle . '; cURL error: ' . curl_error($curl_handle) . ' (' . curl_errno($curl_handle) . ')'); |
|
| 823 | + throw new RequestCore_Exception('cURL resource: '.(string)$curl_handle.'; cURL error: '.curl_error($curl_handle).' ('.curl_errno($curl_handle).')'); |
|
| 824 | 824 | } |
| 825 | 825 | |
| 826 | 826 | $parsed_response = $this->process_response($curl_handle, $this->response); |
@@ -893,13 +893,13 @@ discard block |
||
| 893 | 893 | // Since curl_errno() isn't reliable for handles that were in multirequests, we check the 'result' of the info read, which contains the curl error number, (listed here http://curl.haxx.se/libcurl/c/libcurl-errors.html ) |
| 894 | 894 | if ($done['result'] > 0) |
| 895 | 895 | { |
| 896 | - throw new RequestCore_Exception('cURL resource: ' . (string) $done['handle'] . '; cURL error: ' . curl_error($done['handle']) . ' (' . $done['result'] . ')'); |
|
| 896 | + throw new RequestCore_Exception('cURL resource: '.(string)$done['handle'].'; cURL error: '.curl_error($done['handle']).' ('.$done['result'].')'); |
|
| 897 | 897 | } |
| 898 | 898 | |
| 899 | 899 | // Because curl_multi_info_read() might return more than one message about a request, we check to see if this request is already in our array of completed requests |
| 900 | - elseif (!isset($to_process[(int) $done['handle']])) |
|
| 900 | + elseif (!isset($to_process[(int)$done['handle']])) |
|
| 901 | 901 | { |
| 902 | - $to_process[(int) $done['handle']] = $done; |
|
| 902 | + $to_process[(int)$done['handle']] = $done; |
|
| 903 | 903 | } |
| 904 | 904 | } |
| 905 | 905 | |