Passed
Push — v6 ( 20d195...68f5c0 )
by 光春
03:59
created
src/service/ksyun/bin/core/Builders.php 3 patches
Indentation   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -3,100 +3,100 @@
 block discarded – undo
3 3
 require_once KS3_API_PATH.DIRECTORY_SEPARATOR."config".DIRECTORY_SEPARATOR."Consts.php";
4 4
 
5 5
 class LocationBuilder{
6
-	function build($args){
7
-		if(isset($args["Location"])){
8
-			$location = $args["Location"];
9
-			$xml = new SimpleXmlElement('<CreateBucketConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"></CreateBucketConfiguration>');
10
-			$xml->addChild("LocationConstraint",$args["Location"]);
11
-			return $xml->asXml();
12
-		}
13
-	}
6
+    function build($args){
7
+        if(isset($args["Location"])){
8
+            $location = $args["Location"];
9
+            $xml = new SimpleXmlElement('<CreateBucketConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"></CreateBucketConfiguration>');
10
+            $xml->addChild("LocationConstraint",$args["Location"]);
11
+            return $xml->asXml();
12
+        }
13
+    }
14 14
 }
15 15
 class CORSBuilder{
16
-	function build($args){
17
-		if(isset($args["CORS"])){
18
-			$cors = $args["CORS"];
19
-			$xml = new SimpleXmlElement('<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"></CORSConfiguration>');
20
-			if(is_array($cors)){
21
-				foreach ($cors as $key => $rule) {
22
-					$ruleXml = $xml->addChild("CORSRule");
23
-					if(is_array($rule)){
24
-						foreach ($rule as $key => $value) {
25
-							if(in_array($key,Consts::$CORSElements)){
26
-								if(is_array($value)){
27
-									foreach ($value as  $ele) {
28
-										$ruleXml->addChild($key,$ele);
29
-									}
30
-								}else{
31
-									$ruleXml->addChild($key,$value);
32
-								}
16
+    function build($args){
17
+        if(isset($args["CORS"])){
18
+            $cors = $args["CORS"];
19
+            $xml = new SimpleXmlElement('<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"></CORSConfiguration>');
20
+            if(is_array($cors)){
21
+                foreach ($cors as $key => $rule) {
22
+                    $ruleXml = $xml->addChild("CORSRule");
23
+                    if(is_array($rule)){
24
+                        foreach ($rule as $key => $value) {
25
+                            if(in_array($key,Consts::$CORSElements)){
26
+                                if(is_array($value)){
27
+                                    foreach ($value as  $ele) {
28
+                                        $ruleXml->addChild($key,$ele);
29
+                                    }
30
+                                }else{
31
+                                    $ruleXml->addChild($key,$value);
32
+                                }
33 33
 								
34
-							}
35
-						}
36
-					}
37
-				}
38
-			}
39
-			return $xml->asXml();
40
-		}
41
-	}
34
+                            }
35
+                        }
36
+                    }
37
+                }
38
+            }
39
+            return $xml->asXml();
40
+        }
41
+    }
42 42
 }
43 43
 class BucketLoggingBuilder{
44
-	function build($args){
45
-		if(isset($args["BucketLogging"])){
46
-			$logging = $args["BucketLogging"];
47
-			$xml = new SimpleXmlElement('<BucketLoggingStatus xmlns="http://s3.amazonaws.com/doc/2006-03-01/" />');
48
-			if(is_array($logging)){
44
+    function build($args){
45
+        if(isset($args["BucketLogging"])){
46
+            $logging = $args["BucketLogging"];
47
+            $xml = new SimpleXmlElement('<BucketLoggingStatus xmlns="http://s3.amazonaws.com/doc/2006-03-01/" />');
48
+            if(is_array($logging)){
49 49
 
50
-				if(!isset($logging["Enable"]))
51
-					throw new Ks3ClientException("bucket logging must provide Enable argument");
50
+                if(!isset($logging["Enable"]))
51
+                    throw new Ks3ClientException("bucket logging must provide Enable argument");
52 52
 				
53
-				if($logging["Enable"]){
54
-					if(!isset($logging["TargetBucket"]))
55
-						throw new Ks3ClientException("bucket logging must provide TargetBucket argument");
56
-					$loggingConfig = $xml->addChild("LoggingEnabled");
57
-					foreach ($logging as $key => $value) {
58
-						if(in_array($key,Consts::$BucketLoggingElements)){
59
-							$loggingConfig->addChild($key,$value);
60
-						}
61
-					}
62
-				}
63
-			}
64
-			return $xml->asXml();
65
-		}
66
-	}
53
+                if($logging["Enable"]){
54
+                    if(!isset($logging["TargetBucket"]))
55
+                        throw new Ks3ClientException("bucket logging must provide TargetBucket argument");
56
+                    $loggingConfig = $xml->addChild("LoggingEnabled");
57
+                    foreach ($logging as $key => $value) {
58
+                        if(in_array($key,Consts::$BucketLoggingElements)){
59
+                            $loggingConfig->addChild($key,$value);
60
+                        }
61
+                    }
62
+                }
63
+            }
64
+            return $xml->asXml();
65
+        }
66
+    }
67 67
 }
68 68
 class DeleteObjectsBuilder{
69
-	function build($args){
70
-		if(isset($args["DeleteKeys"])){
71
-			$keys = $args["DeleteKeys"];
72
-			$xml = new SimpleXmlElement('<Delete></Delete>');
73
-			if(is_array($keys)){
74
-				foreach ($keys as $key => $value) {
75
-					$object = $xml->addChild("Object");
76
-					$object->addChild("Key",$value);
77
-				}
78
-			}
79
-			return $xml->asXml();
80
-		}
81
-	}
69
+    function build($args){
70
+        if(isset($args["DeleteKeys"])){
71
+            $keys = $args["DeleteKeys"];
72
+            $xml = new SimpleXmlElement('<Delete></Delete>');
73
+            if(is_array($keys)){
74
+                foreach ($keys as $key => $value) {
75
+                    $object = $xml->addChild("Object");
76
+                    $object->addChild("Key",$value);
77
+                }
78
+            }
79
+            return $xml->asXml();
80
+        }
81
+    }
82 82
 }
83 83
 class CompleteMultipartUploadBuilder{
84
-	function build($args){
85
-		if(isset($args["Parts"])){
86
-			$parts = $args["Parts"];
87
-			$xml = new SimpleXmlElement('<CompleteMultipartUpload></CompleteMultipartUpload>');
88
-			if(is_array($parts)){
89
-				foreach ($parts as $part) {
90
-					$partXml = $xml->addChild("Part");
91
-					foreach ($part as $key => $value) {
92
-						if(in_array($key,Consts::$PartsElement)){
93
-							$partXml->addChild($key,$value);
94
-						}
95
-					}
96
-				}
97
-			}
98
-			return $xml->asXml();
99
-		}
100
-	}
84
+    function build($args){
85
+        if(isset($args["Parts"])){
86
+            $parts = $args["Parts"];
87
+            $xml = new SimpleXmlElement('<CompleteMultipartUpload></CompleteMultipartUpload>');
88
+            if(is_array($parts)){
89
+                foreach ($parts as $part) {
90
+                    $partXml = $xml->addChild("Part");
91
+                    foreach ($part as $key => $value) {
92
+                        if(in_array($key,Consts::$PartsElement)){
93
+                            $partXml->addChild($key,$value);
94
+                        }
95
+                    }
96
+                }
97
+            }
98
+            return $xml->asXml();
99
+        }
100
+    }
101 101
 }
102 102
 ?>
103 103
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -2,33 +2,33 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 				}
Please login to merge, or discard this patch.
Braces   +7 added lines, -5 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 									foreach ($value as  $ele) {
28 28
 										$ruleXml->addChild($key,$ele);
29 29
 									}
30
-								}else{
30
+								} else{
31 31
 									$ruleXml->addChild($key,$value);
32 32
 								}
33 33
 								
@@ -47,12 +47,14 @@  discard block
 block discarded – undo
47 47
 			$xml = new SimpleXmlElement('<BucketLoggingStatus xmlns="http://s3.amazonaws.com/doc/2006-03-01/" />');
48 48
 			if(is_array($logging)){
49 49
 
50
-				if(!isset($logging["Enable"]))
51
-					throw new Ks3ClientException("bucket logging must provide Enable argument");
50
+				if(!isset($logging["Enable"])) {
51
+									throw new Ks3ClientException("bucket logging must provide Enable argument");
52
+				}
52 53
 				
53 54
 				if($logging["Enable"]){
54
-					if(!isset($logging["TargetBucket"]))
55
-						throw new Ks3ClientException("bucket logging must provide TargetBucket argument");
55
+					if(!isset($logging["TargetBucket"])) {
56
+											throw new Ks3ClientException("bucket logging must provide TargetBucket argument");
57
+					}
56 58
 					$loggingConfig = $xml->addChild("LoggingEnabled");
57 59
 					foreach ($logging as $key => $value) {
58 60
 						if(in_array($key,Consts::$BucketLoggingElements)){
Please login to merge, or discard this patch.
src/service/ksyun/bin/core/Signers.php 3 patches
Indentation   +473 added lines, -473 removed lines patch added patch discarded remove patch
@@ -6,536 +6,536 @@
 block discarded – undo
6 6
 require_once KS3_API_PATH.DIRECTORY_SEPARATOR."exceptions".DIRECTORY_SEPARATOR."Exceptions.php";
7 7
 
8 8
 interface Signer{
9
-	public function sign( Ks3Request $request,$args=array());
9
+    public function sign( Ks3Request $request,$args=array());
10 10
 }
11 11
 class DefaultUserAgentSigner implements Signer{
12
-	public function sign(Ks3Request $request,$args=array()){
13
-		$request->addHeader(Headers::$UserAgent,Consts::$UserAgent);
14
-	}
12
+    public function sign(Ks3Request $request,$args=array()){
13
+        $request->addHeader(Headers::$UserAgent,Consts::$UserAgent);
14
+    }
15 15
 }
16 16
 class DefaultContentTypeSigner implements Signer{
17
-	public function sign(Ks3Request $request,$args=array()){
18
-		$contentType = $request->getHeader(Headers::$ContentType);
19
-		if(empty($contentType)){
20
-			$request->addHeader(Headers::$ContentType,"application/xml");
21
-		}
22
-	}
17
+    public function sign(Ks3Request $request,$args=array()){
18
+        $contentType = $request->getHeader(Headers::$ContentType);
19
+        if(empty($contentType)){
20
+            $request->addHeader(Headers::$ContentType,"application/xml");
21
+        }
22
+    }
23 23
 }
24 24
 class StreamContentTypeSigner implements Signer{
25
-	public function sign(Ks3Request $request,$args=array()){
26
-		$contentType = $request->getHeader(Headers::$ContentType);
27
-		if(empty($contentType)){
28
-			$request->addHeader(Headers::$ContentType,"application/ocet-stream");
29
-		}
30
-	}
25
+    public function sign(Ks3Request $request,$args=array()){
26
+        $contentType = $request->getHeader(Headers::$ContentType);
27
+        if(empty($contentType)){
28
+            $request->addHeader(Headers::$ContentType,"application/ocet-stream");
29
+        }
30
+    }
31 31
 }
32 32
 class SuffixContentTypeSigner implements Signer{
33
-	public function sign(Ks3Request $request,$args=array()){
34
-		$key = $request->key;
35
-		$objArr = explode('/', $key);
36
-		$basename = array_pop($objArr);
37
-		$extension = explode ( '.', $basename );
38
-		$extension = array_pop ( $extension );
39
-		$content_type = Utils::get_mimetype(strtolower($extension));
40
-		$request->addHeader(Headers::$ContentType,$content_type);
41
-	}
33
+    public function sign(Ks3Request $request,$args=array()){
34
+        $key = $request->key;
35
+        $objArr = explode('/', $key);
36
+        $basename = array_pop($objArr);
37
+        $extension = explode ( '.', $basename );
38
+        $extension = array_pop ( $extension );
39
+        $content_type = Utils::get_mimetype(strtolower($extension));
40
+        $request->addHeader(Headers::$ContentType,$content_type);
41
+    }
42 42
 }
43 43
 class HeaderAuthSigner implements Signer{
44
-	public function sign(Ks3Request $request,$args=array()){
45
-		$log = "stringToSing->\r\n";
46
-		$date = gmdate('D, d M Y H:i:s \G\M\T');
47
-		$request->addHeader(Headers::$Date, $date);
44
+    public function sign(Ks3Request $request,$args=array()){
45
+        $log = "stringToSing->\r\n";
46
+        $date = gmdate('D, d M Y H:i:s \G\M\T');
47
+        $request->addHeader(Headers::$Date, $date);
48 48
 
49
-		$ak = $args["accessKey"];
50
-		$sk = $args["secretKey"];
51
-		if(empty($ak)){
52
-			throw new Ks3ClientException("you should provide accessKey");
53
-		}
54
-		if(empty($sk)){
55
-			throw new Ks3ClientException("you should provide secretKey");
56
-		}
57
-		$authration = "KSS ";
58
-		$signList = array(
59
-			$request->method,
60
-			$request->getHeader(Headers::$ContentMd5),
61
-			$request->getHeader(Headers::$ContentType),
62
-			$date
63
-			);
64
-		$headers = AuthUtils::canonicalizedKssHeaders($request);
65
-		$resource = AuthUtils::canonicalizedResource($request);
66
-		if(!empty($headers)){
67
-			array_push($signList,$headers);
68
-		}
69
-		array_push($signList,$resource);
70
-		$stringToSign = join("\n",$signList);
71
-		$log.= $stringToSign;
72
-		$signature = base64_encode(hash_hmac('sha1', $stringToSign, $sk, true));
49
+        $ak = $args["accessKey"];
50
+        $sk = $args["secretKey"];
51
+        if(empty($ak)){
52
+            throw new Ks3ClientException("you should provide accessKey");
53
+        }
54
+        if(empty($sk)){
55
+            throw new Ks3ClientException("you should provide secretKey");
56
+        }
57
+        $authration = "KSS ";
58
+        $signList = array(
59
+            $request->method,
60
+            $request->getHeader(Headers::$ContentMd5),
61
+            $request->getHeader(Headers::$ContentType),
62
+            $date
63
+            );
64
+        $headers = AuthUtils::canonicalizedKssHeaders($request);
65
+        $resource = AuthUtils::canonicalizedResource($request);
66
+        if(!empty($headers)){
67
+            array_push($signList,$headers);
68
+        }
69
+        array_push($signList,$resource);
70
+        $stringToSign = join("\n",$signList);
71
+        $log.= $stringToSign;
72
+        $signature = base64_encode(hash_hmac('sha1', $stringToSign, $sk, true));
73 73
 
74
-		$authration.=$ak.":".$signature;
75
-		$request->addHeader(Headers::$Authorization, $authration);
76
-		return $log;
77
-	}
74
+        $authration.=$ak.":".$signature;
75
+        $request->addHeader(Headers::$Authorization, $authration);
76
+        return $log;
77
+    }
78 78
 }
79 79
 class QueryAuthSigner implements Signer{
80
-	public function sign(Ks3Request $request,$args=array()){
81
-		$log = "stringToSing->\r\n";
82
-		$ak = $args["accessKey"];
83
-		$sk = $args["secretKey"];
84
-		$expires = $args["args"]["Options"]["Expires"];
85
-		$expiresSencond = time()+$expires;
80
+    public function sign(Ks3Request $request,$args=array()){
81
+        $log = "stringToSing->\r\n";
82
+        $ak = $args["accessKey"];
83
+        $sk = $args["secretKey"];
84
+        $expires = $args["args"]["Options"]["Expires"];
85
+        $expiresSencond = time()+$expires;
86 86
 
87
-		$resource = AuthUtils::canonicalizedResource($request);
88
-		$signList = array(
89
-			$request->method,
90
-			$request->getHeader(Headers::$ContentMd5),
91
-			$request->getHeader(Headers::$ContentType),
92
-			$expiresSencond
93
-			);
94
-		$headers = AuthUtils::canonicalizedKssHeaders($request);
95
-		$resource = AuthUtils::canonicalizedResource($request);
96
-		if(!empty($headers)){
97
-			array_push($signList,$headers);
98
-		}
99
-		array_push($signList,$resource);
87
+        $resource = AuthUtils::canonicalizedResource($request);
88
+        $signList = array(
89
+            $request->method,
90
+            $request->getHeader(Headers::$ContentMd5),
91
+            $request->getHeader(Headers::$ContentType),
92
+            $expiresSencond
93
+            );
94
+        $headers = AuthUtils::canonicalizedKssHeaders($request);
95
+        $resource = AuthUtils::canonicalizedResource($request);
96
+        if(!empty($headers)){
97
+            array_push($signList,$headers);
98
+        }
99
+        array_push($signList,$resource);
100 100
 
101
-		$stringToSign = join("\n",$signList);
102
-		$log.= $stringToSign;
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);
107
-		return $log;
108
-	}
101
+        $stringToSign = join("\n",$signList);
102
+        $log.= $stringToSign;
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);
107
+        return $log;
108
+    }
109 109
 }
110 110
 class ACLSigner implements Signer{
111
-	public function sign(Ks3Request $request,$args=array()){
112
-		$args = $args["args"];
113
-		if(isset($args["ACL"])){
114
-			$acl = $args["ACL"];
115
-			if(!in_array($acl, Consts::$Acl)){
116
-				throw new Ks3ClientException("unsupport acl :".$acl);
117
-			}else{
118
-				$request->addHeader(Headers::$Acl,$acl);
119
-			}
120
-		}
121
-		if(isset($args["ACP"])){
111
+    public function sign(Ks3Request $request,$args=array()){
112
+        $args = $args["args"];
113
+        if(isset($args["ACL"])){
114
+            $acl = $args["ACL"];
115
+            if(!in_array($acl, Consts::$Acl)){
116
+                throw new Ks3ClientException("unsupport acl :".$acl);
117
+            }else{
118
+                $request->addHeader(Headers::$Acl,$acl);
119
+            }
120
+        }
121
+        if(isset($args["ACP"])){
122 122
 
123
-		}
124
-	}
123
+        }
124
+    }
125 125
 }
126 126
 class ContentMD5Signer implements Signer{
127
-	public function sign(Ks3Request $request,$args=array()){
128
-		$args = $args["args"];
129
-		$contentmd5 = "";
130
-		if(isset($args["ObjectMeta"][Headers::$ContentMd5])){
131
-			$contentmd5 = $args["ObjectMeta"][Headers::$ContentMd5];
132
-		}
133
-		if(empty($contentmd5)){
134
-			$body = $request->body;
135
-			if(!empty($body)){
136
-				$length = $request->getHeader(Headers::$ContentLength);
137
-				if(empty($length)){
138
-					if(isset($args["ObjectMeta"][Headers::$ContentLength]))
139
-						$length = $args["ObjectMeta"][Headers::$ContentLength];
140
-				}
141
-				if(!empty($length)){
142
-					$body = substr($body,0,$length);
143
-				}
144
-				$contentmd5 = Utils::hex_to_base64(md5($body));
145
-			}
146
-		}
147
-		if(!empty($contentmd5))
148
-			$request->addHeader(Headers::$ContentMd5,$contentmd5);
149
-	}
127
+    public function sign(Ks3Request $request,$args=array()){
128
+        $args = $args["args"];
129
+        $contentmd5 = "";
130
+        if(isset($args["ObjectMeta"][Headers::$ContentMd5])){
131
+            $contentmd5 = $args["ObjectMeta"][Headers::$ContentMd5];
132
+        }
133
+        if(empty($contentmd5)){
134
+            $body = $request->body;
135
+            if(!empty($body)){
136
+                $length = $request->getHeader(Headers::$ContentLength);
137
+                if(empty($length)){
138
+                    if(isset($args["ObjectMeta"][Headers::$ContentLength]))
139
+                        $length = $args["ObjectMeta"][Headers::$ContentLength];
140
+                }
141
+                if(!empty($length)){
142
+                    $body = substr($body,0,$length);
143
+                }
144
+                $contentmd5 = Utils::hex_to_base64(md5($body));
145
+            }
146
+        }
147
+        if(!empty($contentmd5))
148
+            $request->addHeader(Headers::$ContentMd5,$contentmd5);
149
+    }
150 150
 }
151 151
 class ContentLengthSigner implements Signer{
152
-	public function sign(Ks3Request $request,$args=array()){
153
-		$args = $args["args"];
154
-		$contentlength = "";
155
-		if(isset($args["ObjectMeta"][Headers::$ContentLength])){
156
-			$contentlength = $args["ObjectMeta"][Headers::$ContentLength];
157
-		}
158
-		if(empty($contentlength)){
159
-			$body = $request->body;
160
-			if(!empty($body)){
161
-				$contentlength = strlen($body);
162
-			}
163
-		}
164
-		if(!empty($contentlength))
165
-			$request->addHeader(Headers::$ContentLength,$contentlength);
166
-	}
152
+    public function sign(Ks3Request $request,$args=array()){
153
+        $args = $args["args"];
154
+        $contentlength = "";
155
+        if(isset($args["ObjectMeta"][Headers::$ContentLength])){
156
+            $contentlength = $args["ObjectMeta"][Headers::$ContentLength];
157
+        }
158
+        if(empty($contentlength)){
159
+            $body = $request->body;
160
+            if(!empty($body)){
161
+                $contentlength = strlen($body);
162
+            }
163
+        }
164
+        if(!empty($contentlength))
165
+            $request->addHeader(Headers::$ContentLength,$contentlength);
166
+    }
167 167
 }
168 168
 class ObjectMetaSigner implements Signer{
169
-	public function sign(Ks3Request $request,$args=array()){
170
-		$args = $args["args"];
171
-		if(isset($args["ObjectMeta"])){
172
-			$ObjectMeta = $args["ObjectMeta"];
173
-			if(is_array($ObjectMeta)){
174
-				foreach ($ObjectMeta as $key => $value) {
175
-					if(in_array($key,Consts::$ObjectMeta)&&!empty($value)){
176
-						$request->addHeader($key,$value);
177
-					}
178
-				}
179
-			}
180
-		}
181
-	}
169
+    public function sign(Ks3Request $request,$args=array()){
170
+        $args = $args["args"];
171
+        if(isset($args["ObjectMeta"])){
172
+            $ObjectMeta = $args["ObjectMeta"];
173
+            if(is_array($ObjectMeta)){
174
+                foreach ($ObjectMeta as $key => $value) {
175
+                    if(in_array($key,Consts::$ObjectMeta)&&!empty($value)){
176
+                        $request->addHeader($key,$value);
177
+                    }
178
+                }
179
+            }
180
+        }
181
+    }
182 182
 }
183 183
 class MultipartObjectMetaSigner implements Signer{
184
-	public function sign(Ks3Request $request,$args=array()){
185
-		$args = $args["args"];
186
-		if(isset($args["ObjectMeta"])){
187
-			$ObjectMeta = $args["ObjectMeta"];
188
-			if(is_array($ObjectMeta)){
189
-				foreach ($ObjectMeta as $key => $value) {
190
-					if(in_array($key,Consts::$MultipartObjectMeta)&&!empty($value)){
191
-						$request->addHeader($key,$value);
192
-					}
193
-				}
194
-			}
195
-		}
196
-	}
184
+    public function sign(Ks3Request $request,$args=array()){
185
+        $args = $args["args"];
186
+        if(isset($args["ObjectMeta"])){
187
+            $ObjectMeta = $args["ObjectMeta"];
188
+            if(is_array($ObjectMeta)){
189
+                foreach ($ObjectMeta as $key => $value) {
190
+                    if(in_array($key,Consts::$MultipartObjectMeta)&&!empty($value)){
191
+                        $request->addHeader($key,$value);
192
+                    }
193
+                }
194
+            }
195
+        }
196
+    }
197 197
 }
198 198
 class UserMetaSigner implements Signer{
199
-	public function sign(Ks3Request $request,$args=array()){
200
-		$args = $args["args"];
201
-		if(isset($args["UserMeta"])){
202
-			$UserMeta = $args["UserMeta"];
203
-			if(is_array($UserMeta)){
204
-				foreach ($UserMeta as $key => $value) {
205
-					if (substr(strtolower($key), 0, 10) === Consts::$UserMetaPrefix){
206
-						$request->addHeader($key,$value);
207
-					}
208
-				}
209
-			}
210
-		}
211
-	}
199
+    public function sign(Ks3Request $request,$args=array()){
200
+        $args = $args["args"];
201
+        if(isset($args["UserMeta"])){
202
+            $UserMeta = $args["UserMeta"];
203
+            if(is_array($UserMeta)){
204
+                foreach ($UserMeta as $key => $value) {
205
+                    if (substr(strtolower($key), 0, 10) === Consts::$UserMetaPrefix){
206
+                        $request->addHeader($key,$value);
207
+                    }
208
+                }
209
+            }
210
+        }
211
+    }
212 212
 }
213 213
 class CopySourceSigner implements Signer{
214
-	public function sign(Ks3Request $request,$args=array()){
215
-		$args = $args["args"];
216
-		if(isset($args["CopySource"])){
217
-			$CopySource = $args["CopySource"];
218
-			if(is_array($CopySource)){
219
-				if(!isset($CopySource["Bucket"]))
220
-					throw new Ks3ClientException("you should provide copy source bucket");
221
-				if(!isset($CopySource["Key"]))
222
-					throw new Ks3ClientException("you should provide copy source key");
223
-				$bucket = $CopySource["Bucket"];
224
-				$key = Utils::encodeUrl($CopySource["Key"]);
225
-				$request->addHeader(Headers::$CopySource,"/".$bucket."/".$key);
226
-			}
227
-		}
228
-	}
214
+    public function sign(Ks3Request $request,$args=array()){
215
+        $args = $args["args"];
216
+        if(isset($args["CopySource"])){
217
+            $CopySource = $args["CopySource"];
218
+            if(is_array($CopySource)){
219
+                if(!isset($CopySource["Bucket"]))
220
+                    throw new Ks3ClientException("you should provide copy source bucket");
221
+                if(!isset($CopySource["Key"]))
222
+                    throw new Ks3ClientException("you should provide copy source key");
223
+                $bucket = $CopySource["Bucket"];
224
+                $key = Utils::encodeUrl($CopySource["Key"]);
225
+                $request->addHeader(Headers::$CopySource,"/".$bucket."/".$key);
226
+            }
227
+        }
228
+    }
229 229
 }
230 230
 class StreamUploadSigner implements Signer{
231
-	public function sign(Ks3Request $request,$args=array()){
232
-		$args = $args["args"];
233
-		if(isset($args["Content"])&&is_array($args["Content"])&&isset($args["Content"]["content"])){
234
-			$content = $args["Content"]["content"];
235
-			$seek_position = 0;
236
-			$resourceLength = 0;
237
-			$length = -1;
238
-			$isFile = FALSE;
231
+    public function sign(Ks3Request $request,$args=array()){
232
+        $args = $args["args"];
233
+        if(isset($args["Content"])&&is_array($args["Content"])&&isset($args["Content"]["content"])){
234
+            $content = $args["Content"]["content"];
235
+            $seek_position = 0;
236
+            $resourceLength = 0;
237
+            $length = -1;
238
+            $isFile = FALSE;
239 239
 
240
-			if (!is_resource($content)){
241
-				$isFile = TRUE;
242
-				//如果之前用户已经转化为GBK则不转换
243
-				if(Utils::chk_chinese($content)&&!Utils::check_char($content)){
244
-					$content = iconv('utf-8','gbk',$content);
245
-				}
246
-				if(!file_exists($content))
247
-					throw new Ks3ClientException("the specified file does not exist ");
248
-				$length = Utils::getFileSize($content);
249
-				$content = fopen($content,"r");
250
-			}else{
251
-				$stats = fstat($content);
252
-				if ($stats && $stats["size"] >= 0){
253
-					$length = $stats["size"];	
254
-				}
255
-			}
256
-			//之所以取resourceLength是为了防止Content-Length大于实际数据的大小,导致一直等待。
257
-			$resourceLength = $length;
258
-			//优先取用户设置seek_position,没有的话取ftell
259
-			if(isset($args["Content"]["seek_position"])&&$args["Content"]["seek_position"]>0){
260
-				$seek_position = $args["Content"]["seek_position"];
261
-			}else if(!$isFile){
262
-				$seek_position = ftell($content);
263
-				if($seek_position<0)
264
-					$seek_position = 0;
265
-				fseek($content,0);
266
-			}
240
+            if (!is_resource($content)){
241
+                $isFile = TRUE;
242
+                //如果之前用户已经转化为GBK则不转换
243
+                if(Utils::chk_chinese($content)&&!Utils::check_char($content)){
244
+                    $content = iconv('utf-8','gbk',$content);
245
+                }
246
+                if(!file_exists($content))
247
+                    throw new Ks3ClientException("the specified file does not exist ");
248
+                $length = Utils::getFileSize($content);
249
+                $content = fopen($content,"r");
250
+            }else{
251
+                $stats = fstat($content);
252
+                if ($stats && $stats["size"] >= 0){
253
+                    $length = $stats["size"];	
254
+                }
255
+            }
256
+            //之所以取resourceLength是为了防止Content-Length大于实际数据的大小,导致一直等待。
257
+            $resourceLength = $length;
258
+            //优先取用户设置seek_position,没有的话取ftell
259
+            if(isset($args["Content"]["seek_position"])&&$args["Content"]["seek_position"]>0){
260
+                $seek_position = $args["Content"]["seek_position"];
261
+            }else if(!$isFile){
262
+                $seek_position = ftell($content);
263
+                if($seek_position<0)
264
+                    $seek_position = 0;
265
+                fseek($content,0);
266
+            }
267 267
 
268
-			$lengthInMeta = -1;
269
-			if(isset($args["ObjectMeta"]["Content-Length"])){
270
-				$lengthInMeta = $args["ObjectMeta"]["Content-Length"];
271
-			}
272
-			if($lengthInMeta > 0){
273
-				$length = $lengthInMeta;
274
-			}else if($resourceLength > 0){
275
-				//根据seek_position计算实际长度
276
-				$length = $resourceLength - $seek_position;
277
-			}
278
-			if($length <= 0)
279
-				throw new Ks3ClientException("calculate content length failed,unexpected contetn length ".$length);
280
-			$request->read_stream = $content;
281
-			$request->addHeader(Headers::$ContentLength,$length);
282
-			$request->seek_position = $seek_position;
283
-		}else{
284
-			throw new Ks3ClientException("please specifie upload content in args");
285
-		}
286
-	}
268
+            $lengthInMeta = -1;
269
+            if(isset($args["ObjectMeta"]["Content-Length"])){
270
+                $lengthInMeta = $args["ObjectMeta"]["Content-Length"];
271
+            }
272
+            if($lengthInMeta > 0){
273
+                $length = $lengthInMeta;
274
+            }else if($resourceLength > 0){
275
+                //根据seek_position计算实际长度
276
+                $length = $resourceLength - $seek_position;
277
+            }
278
+            if($length <= 0)
279
+                throw new Ks3ClientException("calculate content length failed,unexpected contetn length ".$length);
280
+            $request->read_stream = $content;
281
+            $request->addHeader(Headers::$ContentLength,$length);
282
+            $request->seek_position = $seek_position;
283
+        }else{
284
+            throw new Ks3ClientException("please specifie upload content in args");
285
+        }
286
+    }
287 287
 }
288 288
 class RangeSigner{
289
-	public function sign(Ks3Request $request,$args=array()){
290
-		$args = $args["args"];
291
-		if(isset($args["Range"])){
292
-			$Range = $args["Range"];
293
-			if(is_array($Range)){
294
-				$start = $Range["start"];
295
-				$end = $Range["end"];
296
-				$range = "bytes=".$start."-".$end;
297
-				$request->addHeader(Headers::$Range,$range);
298
-			}else
299
-				$request->addHeader(Headers::$Range,$Range);
300
-		}
301
-	}
289
+    public function sign(Ks3Request $request,$args=array()){
290
+        $args = $args["args"];
291
+        if(isset($args["Range"])){
292
+            $Range = $args["Range"];
293
+            if(is_array($Range)){
294
+                $start = $Range["start"];
295
+                $end = $Range["end"];
296
+                $range = "bytes=".$start."-".$end;
297
+                $request->addHeader(Headers::$Range,$range);
298
+            }else
299
+                $request->addHeader(Headers::$Range,$Range);
300
+        }
301
+    }
302 302
 }
303 303
 class GetObjectSigner{
304
-	public function sign(Ks3Request $request,$args=array()){
305
-		$args = $args["args"];
306
-		if(isset($args["WriteTo"])){
307
-			$WriteTo = $args["WriteTo"];
308
-			if(is_resource($WriteTo)){
309
-				$request->write_stream = $WriteTo;
310
-			}else{
311
-				//如果之前用户已经转化为GBK则不转换
312
-				if(Utils::chk_chinese($WriteTo)&&!Utils::check_char($WriteTo)){
313
-					$WriteTo = iconv('utf-8','gbk',$WriteTo);
314
-				}
315
-				$request->write_stream = fopen($WriteTo,"w");
316
-			}
317
-		}
318
-	}
304
+    public function sign(Ks3Request $request,$args=array()){
305
+        $args = $args["args"];
306
+        if(isset($args["WriteTo"])){
307
+            $WriteTo = $args["WriteTo"];
308
+            if(is_resource($WriteTo)){
309
+                $request->write_stream = $WriteTo;
310
+            }else{
311
+                //如果之前用户已经转化为GBK则不转换
312
+                if(Utils::chk_chinese($WriteTo)&&!Utils::check_char($WriteTo)){
313
+                    $WriteTo = iconv('utf-8','gbk',$WriteTo);
314
+                }
315
+                $request->write_stream = fopen($WriteTo,"w");
316
+            }
317
+        }
318
+    }
319 319
 }
320 320
 class AdpSigner{
321
-	public function sign(Ks3Request $request,$args=array()){
322
-		$args = $args["args"];
323
-		if(isset($args["Adp"])){
324
-			$AdpConf = $args["Adp"];
325
-			if(is_array($AdpConf)){
326
-				if(isset($AdpConf["NotifyURL"])){
327
-					$NotifyURL = $AdpConf["NotifyURL"];
328
-				}else{
329
-					throw new Ks3ClientException("adp should provide NotifyURL");
330
-				}
331
-				if(isset($AdpConf["Adps"])){
332
-					$Adps = $AdpConf["Adps"];
333
-				}else{
334
-					throw new Ks3ClientException("adp should provide Adps");
335
-				}
336
-				$AdpString = "";
337
-				foreach ($Adps as $Adp) {
338
-					if(is_array($Adp)){
339
-						if(!isset($Adp["Command"])){
340
-							throw new Ks3ClientException("command is needed in adp");
341
-						}
342
-						$command = $Adp["Command"];
343
-						$bucket = NULL;
344
-						$key = NULL;
345
-						if(isset($Adp["Bucket"])){
346
-							$bucket = $Adp["Bucket"];
347
-						}
348
-						if(isset($Adp["Key"])){
349
-							$key = $Adp["Key"];
350
-						}
351
-						$AdpString.=$command;
352
-						if(!(empty($bucket)&&empty($key))){
353
-							if(empty($bucket)){
354
-								$AdpString.="|tag=saveas&object=".base64_encode($key);
355
-							}elseif (empty($key)) {
356
-								$AdpString.="|tag=saveas&bucket=".$bucket;
357
-							}else{
358
-								$AdpString.="|tag=saveas&bucket=".$bucket."&"."object=".base64_encode($key);
359
-							}
360
-						}
361
-						$AdpString.=";";
362
-					}
363
-				}
364
-				if(!empty($AdpString)&&!empty($NotifyURL)){
365
-					$request->addHeader(Headers::$AsynchronousProcessingList,$AdpString);
366
-					$request->addHeader(Headers::$NotifyURL,$NotifyURL);
367
-				}
368
-			}
369
-		}
370
-	}
321
+    public function sign(Ks3Request $request,$args=array()){
322
+        $args = $args["args"];
323
+        if(isset($args["Adp"])){
324
+            $AdpConf = $args["Adp"];
325
+            if(is_array($AdpConf)){
326
+                if(isset($AdpConf["NotifyURL"])){
327
+                    $NotifyURL = $AdpConf["NotifyURL"];
328
+                }else{
329
+                    throw new Ks3ClientException("adp should provide NotifyURL");
330
+                }
331
+                if(isset($AdpConf["Adps"])){
332
+                    $Adps = $AdpConf["Adps"];
333
+                }else{
334
+                    throw new Ks3ClientException("adp should provide Adps");
335
+                }
336
+                $AdpString = "";
337
+                foreach ($Adps as $Adp) {
338
+                    if(is_array($Adp)){
339
+                        if(!isset($Adp["Command"])){
340
+                            throw new Ks3ClientException("command is needed in adp");
341
+                        }
342
+                        $command = $Adp["Command"];
343
+                        $bucket = NULL;
344
+                        $key = NULL;
345
+                        if(isset($Adp["Bucket"])){
346
+                            $bucket = $Adp["Bucket"];
347
+                        }
348
+                        if(isset($Adp["Key"])){
349
+                            $key = $Adp["Key"];
350
+                        }
351
+                        $AdpString.=$command;
352
+                        if(!(empty($bucket)&&empty($key))){
353
+                            if(empty($bucket)){
354
+                                $AdpString.="|tag=saveas&object=".base64_encode($key);
355
+                            }elseif (empty($key)) {
356
+                                $AdpString.="|tag=saveas&bucket=".$bucket;
357
+                            }else{
358
+                                $AdpString.="|tag=saveas&bucket=".$bucket."&"."object=".base64_encode($key);
359
+                            }
360
+                        }
361
+                        $AdpString.=";";
362
+                    }
363
+                }
364
+                if(!empty($AdpString)&&!empty($NotifyURL)){
365
+                    $request->addHeader(Headers::$AsynchronousProcessingList,$AdpString);
366
+                    $request->addHeader(Headers::$NotifyURL,$NotifyURL);
367
+                }
368
+            }
369
+        }
370
+    }
371 371
 }
372 372
 class CallBackSigner{
373
-	public function sign(Ks3Request $request,$args=array()){
374
-		$args = $args["args"];
375
-		if(isset($args["CallBack"])&&is_array($args["CallBack"])){
376
-			$CallBackConf = $args["CallBack"];
377
-			$url = NULL;
378
-			$body = NULL;
379
-			if(isset($CallBackConf["Url"])){
380
-				$url = $CallBackConf["Url"];
381
-			}
382
-			if(empty($url))
383
-				throw new Ks3ClientException("Url is needed in CallBack");
384
-			if(isset($CallBackConf["BodyMagicVariables"])){
385
-				if(is_array($CallBackConf["BodyMagicVariables"])){
386
-					$magics = $CallBackConf["BodyMagicVariables"];
387
-					foreach ($magics as $key => $value) {
388
-						if(in_array($value,Consts::$CallBackMagics))
389
-							$body.=$key."=\${".$value."}&";
390
-					}
391
-				}
392
-			}
393
-			if(isset($CallBackConf["BodyVariables"])){
394
-				if(is_array($CallBackConf["BodyVariables"])){
395
-					$variables = $CallBackConf["BodyVariables"];
396
-					foreach ($variables as $key => $value) {
397
-						$body.=$key."=\${kss-".$key."}&";
398
-						$request->addHeader("kss-".$key,$value);
399
-					}
400
-				}
401
-			}
402
-			if(!empty($body)){
403
-				$body=substr($body,0,strlen($body)-1);
404
-				$request->addHeader(Headers::$XKssCallbackBody,$body);
405
-			}
406
-			$request->addHeader(Headers::$XKssCallbackUrl,$url);
407
-		}
408
-	}
373
+    public function sign(Ks3Request $request,$args=array()){
374
+        $args = $args["args"];
375
+        if(isset($args["CallBack"])&&is_array($args["CallBack"])){
376
+            $CallBackConf = $args["CallBack"];
377
+            $url = NULL;
378
+            $body = NULL;
379
+            if(isset($CallBackConf["Url"])){
380
+                $url = $CallBackConf["Url"];
381
+            }
382
+            if(empty($url))
383
+                throw new Ks3ClientException("Url is needed in CallBack");
384
+            if(isset($CallBackConf["BodyMagicVariables"])){
385
+                if(is_array($CallBackConf["BodyMagicVariables"])){
386
+                    $magics = $CallBackConf["BodyMagicVariables"];
387
+                    foreach ($magics as $key => $value) {
388
+                        if(in_array($value,Consts::$CallBackMagics))
389
+                            $body.=$key."=\${".$value."}&";
390
+                    }
391
+                }
392
+            }
393
+            if(isset($CallBackConf["BodyVariables"])){
394
+                if(is_array($CallBackConf["BodyVariables"])){
395
+                    $variables = $CallBackConf["BodyVariables"];
396
+                    foreach ($variables as $key => $value) {
397
+                        $body.=$key."=\${kss-".$key."}&";
398
+                        $request->addHeader("kss-".$key,$value);
399
+                    }
400
+                }
401
+            }
402
+            if(!empty($body)){
403
+                $body=substr($body,0,strlen($body)-1);
404
+                $request->addHeader(Headers::$XKssCallbackBody,$body);
405
+            }
406
+            $request->addHeader(Headers::$XKssCallbackUrl,$url);
407
+        }
408
+    }
409 409
 }
410 410
 class SSESigner{
411
-	public function sign(Ks3Request $request,$args=array()){
412
-		$args = $args["args"];
413
-		if(isset($args["SSE"])){
414
-			if(isset($args["SSE"]["Algm"]))
415
-				$algm = $args["SSE"]["Algm"];
416
-			if(isset($args["SSE"]["KMSId"]))
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);
422
-			}
423
-		}
424
-	}
411
+    public function sign(Ks3Request $request,$args=array()){
412
+        $args = $args["args"];
413
+        if(isset($args["SSE"])){
414
+            if(isset($args["SSE"]["Algm"]))
415
+                $algm = $args["SSE"]["Algm"];
416
+            if(isset($args["SSE"]["KMSId"]))
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);
422
+            }
423
+        }
424
+    }
425 425
 }
426 426
 class SSECSigner{
427
-	public function sign(Ks3Request $request,$args=array()){
428
-		$args = $args["args"];
429
-		if(isset($args["SSEC"])){
430
-			if(isset($args["SSEC"]["Algm"]))
431
-				$algm = $args["SSEC"]["Algm"];
432
-			if(isset($args["SSEC"]["Key"]))
433
-				$key = $args["SSEC"]["Key"];
434
-			if(isset($args["SSEC"]["KeyBase64"]))
435
-				$keybase64 = $args["SSEC"]["KeyBase64"];
436
-			if(isset($args["SSEC"]["KeyMD5"]))
437
-				$md5 = $args["SSEC"]["KeyMD5"];
438
-			if(!empty($key)||!empty($keybase64)){
439
-				if(empty($key))
440
-					$key = base64_decode($keybase64);
441
-				if(empty($algm))
442
-					$algm = Consts::$SSEDefaultAlgm;
443
-				if(empty($md5))
444
-					$md5 = Utils::hex_to_base64(md5($key));
427
+    public function sign(Ks3Request $request,$args=array()){
428
+        $args = $args["args"];
429
+        if(isset($args["SSEC"])){
430
+            if(isset($args["SSEC"]["Algm"]))
431
+                $algm = $args["SSEC"]["Algm"];
432
+            if(isset($args["SSEC"]["Key"]))
433
+                $key = $args["SSEC"]["Key"];
434
+            if(isset($args["SSEC"]["KeyBase64"]))
435
+                $keybase64 = $args["SSEC"]["KeyBase64"];
436
+            if(isset($args["SSEC"]["KeyMD5"]))
437
+                $md5 = $args["SSEC"]["KeyMD5"];
438
+            if(!empty($key)||!empty($keybase64)){
439
+                if(empty($key))
440
+                    $key = base64_decode($keybase64);
441
+                if(empty($algm))
442
+                    $algm = Consts::$SSEDefaultAlgm;
443
+                if(empty($md5))
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);
449
-			}
450
-		}
451
-	}	
446
+                $request->addHeader(Headers::$SSECAlgm,$algm);
447
+                $request->addHeader(Headers::$SSECKey,base64_encode($key));
448
+                $request->addHeader(Headers::$SSECMD5,$md5);
449
+            }
450
+        }
451
+    }	
452 452
 }
453 453
 class SSECSourceSigner{
454
-	public function sign(Ks3Request $request,$args=array()){
455
-		$args = $args["args"];
456
-		if(isset($args["SSECSource"])){
457
-			if(isset($args["SSECSource"]["Algm"]))
458
-				$algm = $args["SSECSource"]["Algm"];
459
-			if(isset($args["SSECSource"]["Key"]))
460
-				$key = $args["SSECSource"]["Key"];
461
-			if(isset($args["SSECSource"]["KeyBase64"]))
462
-				$keybase64 = $args["SSECSource"]["KeyBase64"];
463
-			if(isset($args["SSECSource"]["KeyMD5"]))
464
-				$md5 = $args["SSECSource"]["KeyMD5"];
465
-			if(!empty($key)||!empty($keybase64)){
466
-				if(empty($key))
467
-					$key = base64_decode($keybase64);
468
-				if(empty($algm))
469
-					$algm = Consts::$SSEDefaultAlgm;
470
-				if(empty($md5))
471
-					$md5 = Utils::hex_to_base64(md5($key));
454
+    public function sign(Ks3Request $request,$args=array()){
455
+        $args = $args["args"];
456
+        if(isset($args["SSECSource"])){
457
+            if(isset($args["SSECSource"]["Algm"]))
458
+                $algm = $args["SSECSource"]["Algm"];
459
+            if(isset($args["SSECSource"]["Key"]))
460
+                $key = $args["SSECSource"]["Key"];
461
+            if(isset($args["SSECSource"]["KeyBase64"]))
462
+                $keybase64 = $args["SSECSource"]["KeyBase64"];
463
+            if(isset($args["SSECSource"]["KeyMD5"]))
464
+                $md5 = $args["SSECSource"]["KeyMD5"];
465
+            if(!empty($key)||!empty($keybase64)){
466
+                if(empty($key))
467
+                    $key = base64_decode($keybase64);
468
+                if(empty($algm))
469
+                    $algm = Consts::$SSEDefaultAlgm;
470
+                if(empty($md5))
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);
476
-			}
477
-		}
478
-	}
473
+                $request->addHeader(Headers::$SSECSourceAlgm,$algm);
474
+                $request->addHeader(Headers::$SSECSourceKey,base64_encode($key));
475
+                $request->addHeader(Headers::$SSECSourceMD5,$md5);
476
+            }
477
+        }
478
+    }
479 479
 }
480 480
 class AllHeaderSigner{
481
-	public function sign(Ks3Request $request,$args=array()){
482
-		$args = $args["args"];
483
-		$headers = isset($args["Headers"])?$args["Headers"]:"";
484
-		if(!empty($headers)&&is_array($headers)){
485
-			foreach ($headers as $key => $value) {
486
-				$request->addHeader($key,$value);
487
-			}
488
-		}
489
-	}
481
+    public function sign(Ks3Request $request,$args=array()){
482
+        $args = $args["args"];
483
+        $headers = isset($args["Headers"])?$args["Headers"]:"";
484
+        if(!empty($headers)&&is_array($headers)){
485
+            foreach ($headers as $key => $value) {
486
+                $request->addHeader($key,$value);
487
+            }
488
+        }
489
+    }
490 490
 }
491 491
 class AuthUtils{
492
-	public static function canonicalizedKssHeaders(Ks3Request $request){
493
-		$header = "";
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;
499
-			}			
500
-		}
501
-		$header = substr($header, 1);
502
-		return $header;
503
-	}
504
-	public static function canonicalizedResource(Ks3Request $request){
505
-		$resource = "/";
506
-		$bucket = $request->bucket;
507
-		$key = $request->key;
508
-		$subResource = $request->subResource;
509
-		if(!empty($bucket)){
510
-			$resource.=$request->bucket."/";
511
-		}
512
-		if(!empty($key)){
513
-			$resource.=Utils::encodeUrl($request->key);
514
-		}
492
+    public static function canonicalizedKssHeaders(Ks3Request $request){
493
+        $header = "";
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;
499
+            }			
500
+        }
501
+        $header = substr($header, 1);
502
+        return $header;
503
+    }
504
+    public static function canonicalizedResource(Ks3Request $request){
505
+        $resource = "/";
506
+        $bucket = $request->bucket;
507
+        $key = $request->key;
508
+        $subResource = $request->subResource;
509
+        if(!empty($bucket)){
510
+            $resource.=$request->bucket."/";
511
+        }
512
+        if(!empty($key)){
513
+            $resource.=Utils::encodeUrl($request->key);
514
+        }
515 515
 
516
-		$encodeParams = "";
517
-		$querys = $request->queryParams;
518
-		if(!empty($subResource)){
519
-			$querys[$subResource] = NULL;
520
-		}
521
-		ksort($querys,SORT_STRING);
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;
528
-				}
529
-			}
530
-		}
531
-		$encodeParams = substr($encodeParams,1);
516
+        $encodeParams = "";
517
+        $querys = $request->queryParams;
518
+        if(!empty($subResource)){
519
+            $querys[$subResource] = NULL;
520
+        }
521
+        ksort($querys,SORT_STRING);
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;
528
+                }
529
+            }
530
+        }
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;
537
-		}
538
-		return $resource;
539
-	}
535
+        if(!empty($encodeParams)){
536
+            $resource.="?".$encodeParams;
537
+        }
538
+        return $resource;
539
+    }
540 540
 }
541 541
 ?>
542 542
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +227 added lines, -227 removed lines patch added patch discarded remove patch
@@ -5,53 +5,53 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 	}
Please login to merge, or discard this patch.
Braces   +95 added lines, -67 removed lines patch added patch discarded remove patch
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
 			$acl = $args["ACL"];
115 115
 			if(!in_array($acl, Consts::$Acl)){
116 116
 				throw new Ks3ClientException("unsupport acl :".$acl);
117
-			}else{
117
+			} else{
118 118
 				$request->addHeader(Headers::$Acl,$acl);
119 119
 			}
120 120
 		}
@@ -135,8 +135,9 @@  discard block
 block discarded – undo
135 135
 			if(!empty($body)){
136 136
 				$length = $request->getHeader(Headers::$ContentLength);
137 137
 				if(empty($length)){
138
-					if(isset($args["ObjectMeta"][Headers::$ContentLength]))
139
-						$length = $args["ObjectMeta"][Headers::$ContentLength];
138
+					if(isset($args["ObjectMeta"][Headers::$ContentLength])) {
139
+											$length = $args["ObjectMeta"][Headers::$ContentLength];
140
+					}
140 141
 				}
141 142
 				if(!empty($length)){
142 143
 					$body = substr($body,0,$length);
@@ -144,8 +145,9 @@  discard block
 block discarded – undo
144 145
 				$contentmd5 = Utils::hex_to_base64(md5($body));
145 146
 			}
146 147
 		}
147
-		if(!empty($contentmd5))
148
-			$request->addHeader(Headers::$ContentMd5,$contentmd5);
148
+		if(!empty($contentmd5)) {
149
+					$request->addHeader(Headers::$ContentMd5,$contentmd5);
150
+		}
149 151
 	}
150 152
 }
151 153
 class ContentLengthSigner implements Signer{
@@ -161,8 +163,9 @@  discard block
 block discarded – undo
161 163
 				$contentlength = strlen($body);
162 164
 			}
163 165
 		}
164
-		if(!empty($contentlength))
165
-			$request->addHeader(Headers::$ContentLength,$contentlength);
166
+		if(!empty($contentlength)) {
167
+					$request->addHeader(Headers::$ContentLength,$contentlength);
168
+		}
166 169
 	}
167 170
 }
168 171
 class ObjectMetaSigner implements Signer{
@@ -216,10 +219,12 @@  discard block
 block discarded – undo
216 219
 		if(isset($args["CopySource"])){
217 220
 			$CopySource = $args["CopySource"];
218 221
 			if(is_array($CopySource)){
219
-				if(!isset($CopySource["Bucket"]))
220
-					throw new Ks3ClientException("you should provide copy source bucket");
221
-				if(!isset($CopySource["Key"]))
222
-					throw new Ks3ClientException("you should provide copy source key");
222
+				if(!isset($CopySource["Bucket"])) {
223
+									throw new Ks3ClientException("you should provide copy source bucket");
224
+				}
225
+				if(!isset($CopySource["Key"])) {
226
+									throw new Ks3ClientException("you should provide copy source key");
227
+				}
223 228
 				$bucket = $CopySource["Bucket"];
224 229
 				$key = Utils::encodeUrl($CopySource["Key"]);
225 230
 				$request->addHeader(Headers::$CopySource,"/".$bucket."/".$key);
@@ -243,11 +248,12 @@  discard block
 block discarded – undo
243 248
 				if(Utils::chk_chinese($content)&&!Utils::check_char($content)){
244 249
 					$content = iconv('utf-8','gbk',$content);
245 250
 				}
246
-				if(!file_exists($content))
247
-					throw new Ks3ClientException("the specified file does not exist ");
251
+				if(!file_exists($content)) {
252
+									throw new Ks3ClientException("the specified file does not exist ");
253
+				}
248 254
 				$length = Utils::getFileSize($content);
249 255
 				$content = fopen($content,"r");
250
-			}else{
256
+			} else{
251 257
 				$stats = fstat($content);
252 258
 				if ($stats && $stats["size"] >= 0){
253 259
 					$length = $stats["size"];	
@@ -258,10 +264,11 @@  discard block
 block discarded – undo
258 264
 			//优先取用户设置seek_position,没有的话取ftell
259 265
 			if(isset($args["Content"]["seek_position"])&&$args["Content"]["seek_position"]>0){
260 266
 				$seek_position = $args["Content"]["seek_position"];
261
-			}else if(!$isFile){
267
+			} else if(!$isFile){
262 268
 				$seek_position = ftell($content);
263
-				if($seek_position<0)
264
-					$seek_position = 0;
269
+				if($seek_position<0) {
270
+									$seek_position = 0;
271
+				}
265 272
 				fseek($content,0);
266 273
 			}
267 274
 
@@ -271,16 +278,17 @@  discard block
 block discarded – undo
271 278
 			}
272 279
 			if($lengthInMeta > 0){
273 280
 				$length = $lengthInMeta;
274
-			}else if($resourceLength > 0){
281
+			} else if($resourceLength > 0){
275 282
 				//根据seek_position计算实际长度
276 283
 				$length = $resourceLength - $seek_position;
277 284
 			}
278
-			if($length <= 0)
279
-				throw new Ks3ClientException("calculate content length failed,unexpected contetn length ".$length);
285
+			if($length <= 0) {
286
+							throw new Ks3ClientException("calculate content length failed,unexpected contetn length ".$length);
287
+			}
280 288
 			$request->read_stream = $content;
281 289
 			$request->addHeader(Headers::$ContentLength,$length);
282 290
 			$request->seek_position = $seek_position;
283
-		}else{
291
+		} else{
284 292
 			throw new Ks3ClientException("please specifie upload content in args");
285 293
 		}
286 294
 	}
@@ -295,8 +303,9 @@  discard block
 block discarded – undo
295 303
 				$end = $Range["end"];
296 304
 				$range = "bytes=".$start."-".$end;
297 305
 				$request->addHeader(Headers::$Range,$range);
298
-			}else
299
-				$request->addHeader(Headers::$Range,$Range);
306
+			} else {
307
+							$request->addHeader(Headers::$Range,$Range);
308
+			}
300 309
 		}
301 310
 	}
302 311
 }
@@ -307,7 +316,7 @@  discard block
 block discarded – undo
307 316
 			$WriteTo = $args["WriteTo"];
308 317
 			if(is_resource($WriteTo)){
309 318
 				$request->write_stream = $WriteTo;
310
-			}else{
319
+			} else{
311 320
 				//如果之前用户已经转化为GBK则不转换
312 321
 				if(Utils::chk_chinese($WriteTo)&&!Utils::check_char($WriteTo)){
313 322
 					$WriteTo = iconv('utf-8','gbk',$WriteTo);
@@ -325,12 +334,12 @@  discard block
 block discarded – undo
325 334
 			if(is_array($AdpConf)){
326 335
 				if(isset($AdpConf["NotifyURL"])){
327 336
 					$NotifyURL = $AdpConf["NotifyURL"];
328
-				}else{
337
+				} else{
329 338
 					throw new Ks3ClientException("adp should provide NotifyURL");
330 339
 				}
331 340
 				if(isset($AdpConf["Adps"])){
332 341
 					$Adps = $AdpConf["Adps"];
333
-				}else{
342
+				} else{
334 343
 					throw new Ks3ClientException("adp should provide Adps");
335 344
 				}
336 345
 				$AdpString = "";
@@ -352,9 +361,9 @@  discard block
 block discarded – undo
352 361
 						if(!(empty($bucket)&&empty($key))){
353 362
 							if(empty($bucket)){
354 363
 								$AdpString.="|tag=saveas&object=".base64_encode($key);
355
-							}elseif (empty($key)) {
364
+							} elseif (empty($key)) {
356 365
 								$AdpString.="|tag=saveas&bucket=".$bucket;
357
-							}else{
366
+							} else{
358 367
 								$AdpString.="|tag=saveas&bucket=".$bucket."&"."object=".base64_encode($key);
359 368
 							}
360 369
 						}
@@ -379,14 +388,16 @@  discard block
 block discarded – undo
379 388
 			if(isset($CallBackConf["Url"])){
380 389
 				$url = $CallBackConf["Url"];
381 390
 			}
382
-			if(empty($url))
383
-				throw new Ks3ClientException("Url is needed in CallBack");
391
+			if(empty($url)) {
392
+							throw new Ks3ClientException("Url is needed in CallBack");
393
+			}
384 394
 			if(isset($CallBackConf["BodyMagicVariables"])){
385 395
 				if(is_array($CallBackConf["BodyMagicVariables"])){
386 396
 					$magics = $CallBackConf["BodyMagicVariables"];
387 397
 					foreach ($magics as $key => $value) {
388
-						if(in_array($value,Consts::$CallBackMagics))
389
-							$body.=$key."=\${".$value."}&";
398
+						if(in_array($value,Consts::$CallBackMagics)) {
399
+													$body.=$key."=\${".$value."}&";
400
+						}
390 401
 					}
391 402
 				}
392 403
 			}
@@ -411,14 +422,17 @@  discard block
 block discarded – undo
411 422
 	public function sign(Ks3Request $request,$args=array()){
412 423
 		$args = $args["args"];
413 424
 		if(isset($args["SSE"])){
414
-			if(isset($args["SSE"]["Algm"]))
415
-				$algm = $args["SSE"]["Algm"];
416
-			if(isset($args["SSE"]["KMSId"]))
417
-				$id = $args["SSE"]["KMSId"];
425
+			if(isset($args["SSE"]["Algm"])) {
426
+							$algm = $args["SSE"]["Algm"];
427
+			}
428
+			if(isset($args["SSE"]["KMSId"])) {
429
+							$id = $args["SSE"]["KMSId"];
430
+			}
418 431
 			if(!empty($algm)){		
419 432
 				$request->addHeader(Headers::$SSEAlgm,$algm);
420
-				if(!empty($id))
421
-					$request->addHeader(Headers::$SSEKMSId,$id);
433
+				if(!empty($id)) {
434
+									$request->addHeader(Headers::$SSEKMSId,$id);
435
+				}
422 436
 			}
423 437
 		}
424 438
 	}
@@ -427,21 +441,28 @@  discard block
 block discarded – undo
427 441
 	public function sign(Ks3Request $request,$args=array()){
428 442
 		$args = $args["args"];
429 443
 		if(isset($args["SSEC"])){
430
-			if(isset($args["SSEC"]["Algm"]))
431
-				$algm = $args["SSEC"]["Algm"];
432
-			if(isset($args["SSEC"]["Key"]))
433
-				$key = $args["SSEC"]["Key"];
434
-			if(isset($args["SSEC"]["KeyBase64"]))
435
-				$keybase64 = $args["SSEC"]["KeyBase64"];
436
-			if(isset($args["SSEC"]["KeyMD5"]))
437
-				$md5 = $args["SSEC"]["KeyMD5"];
444
+			if(isset($args["SSEC"]["Algm"])) {
445
+							$algm = $args["SSEC"]["Algm"];
446
+			}
447
+			if(isset($args["SSEC"]["Key"])) {
448
+							$key = $args["SSEC"]["Key"];
449
+			}
450
+			if(isset($args["SSEC"]["KeyBase64"])) {
451
+							$keybase64 = $args["SSEC"]["KeyBase64"];
452
+			}
453
+			if(isset($args["SSEC"]["KeyMD5"])) {
454
+							$md5 = $args["SSEC"]["KeyMD5"];
455
+			}
438 456
 			if(!empty($key)||!empty($keybase64)){
439
-				if(empty($key))
440
-					$key = base64_decode($keybase64);
441
-				if(empty($algm))
442
-					$algm = Consts::$SSEDefaultAlgm;
443
-				if(empty($md5))
444
-					$md5 = Utils::hex_to_base64(md5($key));
457
+				if(empty($key)) {
458
+									$key = base64_decode($keybase64);
459
+				}
460
+				if(empty($algm)) {
461
+									$algm = Consts::$SSEDefaultAlgm;
462
+				}
463
+				if(empty($md5)) {
464
+									$md5 = Utils::hex_to_base64(md5($key));
465
+				}
445 466
 
446 467
 				$request->addHeader(Headers::$SSECAlgm,$algm);
447 468
 				$request->addHeader(Headers::$SSECKey,base64_encode($key));
@@ -454,21 +475,28 @@  discard block
 block discarded – undo
454 475
 	public function sign(Ks3Request $request,$args=array()){
455 476
 		$args = $args["args"];
456 477
 		if(isset($args["SSECSource"])){
457
-			if(isset($args["SSECSource"]["Algm"]))
458
-				$algm = $args["SSECSource"]["Algm"];
459
-			if(isset($args["SSECSource"]["Key"]))
460
-				$key = $args["SSECSource"]["Key"];
461
-			if(isset($args["SSECSource"]["KeyBase64"]))
462
-				$keybase64 = $args["SSECSource"]["KeyBase64"];
463
-			if(isset($args["SSECSource"]["KeyMD5"]))
464
-				$md5 = $args["SSECSource"]["KeyMD5"];
478
+			if(isset($args["SSECSource"]["Algm"])) {
479
+							$algm = $args["SSECSource"]["Algm"];
480
+			}
481
+			if(isset($args["SSECSource"]["Key"])) {
482
+							$key = $args["SSECSource"]["Key"];
483
+			}
484
+			if(isset($args["SSECSource"]["KeyBase64"])) {
485
+							$keybase64 = $args["SSECSource"]["KeyBase64"];
486
+			}
487
+			if(isset($args["SSECSource"]["KeyMD5"])) {
488
+							$md5 = $args["SSECSource"]["KeyMD5"];
489
+			}
465 490
 			if(!empty($key)||!empty($keybase64)){
466
-				if(empty($key))
467
-					$key = base64_decode($keybase64);
468
-				if(empty($algm))
469
-					$algm = Consts::$SSEDefaultAlgm;
470
-				if(empty($md5))
471
-					$md5 = Utils::hex_to_base64(md5($key));
491
+				if(empty($key)) {
492
+									$key = base64_decode($keybase64);
493
+				}
494
+				if(empty($algm)) {
495
+									$algm = Consts::$SSEDefaultAlgm;
496
+				}
497
+				if(empty($md5)) {
498
+									$md5 = Utils::hex_to_base64(md5($key));
499
+				}
472 500
 
473 501
 				$request->addHeader(Headers::$SSECSourceAlgm,$algm);
474 502
 				$request->addHeader(Headers::$SSECSourceKey,base64_encode($key));
@@ -523,7 +551,7 @@  discard block
 block discarded – undo
523 551
 			if(in_array($key,Consts::$SubResource)||in_array($key,Consts::$QueryParam)){
524 552
 				if(empty($value)){
525 553
 					$encodeParams.="&".$key;
526
-				}else{
554
+				} else{
527 555
 					$encodeParams.="&".$key."=".$value;
528 556
 				}
529 557
 			}
Please login to merge, or discard this patch.
src/service/ksyun/bin/core/MessageHolder.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@
 block discarded – undo
1 1
 <?php
2 2
 class MessageHolder{
3
-	public $msg;
3
+    public $msg;
4 4
 }
5 5
 ?>
6 6
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@
 block discarded – undo
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
Please login to merge, or discard this patch.
src/service/ksyun/bin/core/Ks3Request.class.php 3 patches
Indentation   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -2,83 +2,83 @@
 block discarded – undo
2 2
 require_once KS3_API_PATH.DIRECTORY_SEPARATOR."core".DIRECTORY_SEPARATOR."Utils.class.php";
3 3
 
4 4
 class Ks3Request{
5
-	private $bucket;
6
-	private $key;
7
-	private $queryParams=array();
8
-	private $headers=array();
9
-	private $subResource;
10
-	private $method;
11
-	private $endpoint;
12
-	private $scheme;
13
-	private $body;
14
-	private $read_stream;
15
-	private $seek_position;
16
-	private $write_stream;
5
+    private $bucket;
6
+    private $key;
7
+    private $queryParams=array();
8
+    private $headers=array();
9
+    private $subResource;
10
+    private $method;
11
+    private $endpoint;
12
+    private $scheme;
13
+    private $body;
14
+    private $read_stream;
15
+    private $seek_position;
16
+    private $write_stream;
17 17
 
18
-	public function __set($property_name, $value){
19
-		$this->$property_name=$value;
20
-	}
21
-	public function __get($property_name){
22
-		if(isset($this->$property_name))
23
-		{
24
-			return($this->$property_name);
25
-		}else
26
-		{
27
-			return(NULL);
28
-		}
29
-	}
30
-	public function getHeader($key){
31
-		if(isset($this->headers[$key])){
32
-			return  $this->headers[$key];
33
-		}else{
34
-			return(NULL);
35
-		}
36
-	}
37
-	public function addHeader($key,$value){
38
-		$this->headers[$key] = $value;
39
-	}
18
+    public function __set($property_name, $value){
19
+        $this->$property_name=$value;
20
+    }
21
+    public function __get($property_name){
22
+        if(isset($this->$property_name))
23
+        {
24
+            return($this->$property_name);
25
+        }else
26
+        {
27
+            return(NULL);
28
+        }
29
+    }
30
+    public function getHeader($key){
31
+        if(isset($this->headers[$key])){
32
+            return  $this->headers[$key];
33
+        }else{
34
+            return(NULL);
35
+        }
36
+    }
37
+    public function addHeader($key,$value){
38
+        $this->headers[$key] = $value;
39
+    }
40 40
 
41
-	public function getQueryParams($key){
42
-		if(isset($this->queryParams[$key])){
43
-			return  $this->queryParams[$key];
44
-		}else{
45
-			return(NULL);
46
-		}
47
-	}
48
-	public function addQueryParams($key,$value){
49
-		$this->queryParams[$key] = $value;
50
-	}
51
-	public function toUrl($endpoint){
52
-		$url = "";
53
-		$bucket = $this->bucket;
54
-		$key = $this->key;
55
-		$subResource = $this->subResource;
56
-		if(!empty($bucket)){
57
-			if(KS3_API_VHOST){
58
-				$url.=$bucket.".".$endpoint;
59
-			}else{
60
-				$url.=$endpoint."/".$bucket;
61
-			}
62
-		}else{
63
-			$url.=$endpoint;
64
-		}
65
-		if(!empty($key)){
66
-			$url.="/".Utils::encodeUrl($key);
67
-		}
68
-		$url = str_replace("//","/%2F", $url);
69
-		$queryString = "";
70
-		if(!empty($subResource)){
71
-			$queryString.="&".$subResource;
72
-		}
73
-		foreach ($this->queryParams as $key => $value) {
74
-			$queryString.="&".$key."=".rawurlencode($value);
75
-		}
76
-		$queryString = substr($queryString, 1);
77
-		if(!empty($queryString)){
78
-			$url.="?".$queryString;
79
-		}
80
-		$url = $this->scheme.$url;
81
-		return $url;
82
-	}
41
+    public function getQueryParams($key){
42
+        if(isset($this->queryParams[$key])){
43
+            return  $this->queryParams[$key];
44
+        }else{
45
+            return(NULL);
46
+        }
47
+    }
48
+    public function addQueryParams($key,$value){
49
+        $this->queryParams[$key] = $value;
50
+    }
51
+    public function toUrl($endpoint){
52
+        $url = "";
53
+        $bucket = $this->bucket;
54
+        $key = $this->key;
55
+        $subResource = $this->subResource;
56
+        if(!empty($bucket)){
57
+            if(KS3_API_VHOST){
58
+                $url.=$bucket.".".$endpoint;
59
+            }else{
60
+                $url.=$endpoint."/".$bucket;
61
+            }
62
+        }else{
63
+            $url.=$endpoint;
64
+        }
65
+        if(!empty($key)){
66
+            $url.="/".Utils::encodeUrl($key);
67
+        }
68
+        $url = str_replace("//","/%2F", $url);
69
+        $queryString = "";
70
+        if(!empty($subResource)){
71
+            $queryString.="&".$subResource;
72
+        }
73
+        foreach ($this->queryParams as $key => $value) {
74
+            $queryString.="&".$key."=".rawurlencode($value);
75
+        }
76
+        $queryString = substr($queryString, 1);
77
+        if(!empty($queryString)){
78
+            $url.="?".$queryString;
79
+        }
80
+        $url = $this->scheme.$url;
81
+        return $url;
82
+    }
83 83
 }
84 84
 ?>
85 85
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -1,11 +1,11 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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;
Please login to merge, or discard this patch.
Braces   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 		if(isset($this->$property_name))
23 23
 		{
24 24
 			return($this->$property_name);
25
-		}else
25
+		} else
26 26
 		{
27 27
 			return(NULL);
28 28
 		}
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 	public function getHeader($key){
31 31
 		if(isset($this->headers[$key])){
32 32
 			return  $this->headers[$key];
33
-		}else{
33
+		} else{
34 34
 			return(NULL);
35 35
 		}
36 36
 	}
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 	public function getQueryParams($key){
42 42
 		if(isset($this->queryParams[$key])){
43 43
 			return  $this->queryParams[$key];
44
-		}else{
44
+		} else{
45 45
 			return(NULL);
46 46
 		}
47 47
 	}
@@ -56,10 +56,10 @@  discard block
 block discarded – undo
56 56
 		if(!empty($bucket)){
57 57
 			if(KS3_API_VHOST){
58 58
 				$url.=$bucket.".".$endpoint;
59
-			}else{
59
+			} else{
60 60
 				$url.=$endpoint."/".$bucket;
61 61
 			}
62
-		}else{
62
+		} else{
63 63
 			$url.=$endpoint;
64 64
 		}
65 65
 		if(!empty($key)){
Please login to merge, or discard this patch.
src/service/ksyun/bin/core/Utils.class.php 3 patches
Indentation   +223 added lines, -223 removed lines patch added patch discarded remove patch
@@ -2,234 +2,234 @@
 block discarded – undo
2 2
 require_once KS3_API_PATH.DIRECTORY_SEPARATOR."exceptions".DIRECTORY_SEPARATOR."Exceptions.php";
3 3
 
4 4
 class Utils{
5
-	public static function encodeUrl($url,$path=TRUE){
6
-		$url = rawurlencode($url);
7
-		$url = str_replace("+", "%20", $url);
8
-		$url = str_replace("*", "%2A", $url);
9
-		$url = str_replace("%7A", "~", $url);
10
-		if($path){
11
-			$url = str_replace("%2F", "/", $url);
12
-		}
13
-		return $url;
14
-	}
15
-	public static function hex_to_base64($str){
16
-		$result = '';
5
+    public static function encodeUrl($url,$path=TRUE){
6
+        $url = rawurlencode($url);
7
+        $url = str_replace("+", "%20", $url);
8
+        $url = str_replace("*", "%2A", $url);
9
+        $url = str_replace("%7A", "~", $url);
10
+        if($path){
11
+            $url = str_replace("%2F", "/", $url);
12
+        }
13
+        return $url;
14
+    }
15
+    public static function hex_to_base64($str){
16
+        $result = '';
17 17
 
18
-		for ($i = 0; $i < strlen($str); $i += 2){
19
-			$result .= chr(hexdec(substr($str, $i, 2)));
20
-		}
18
+        for ($i = 0; $i < strlen($str); $i += 2){
19
+            $result .= chr(hexdec(substr($str, $i, 2)));
20
+        }
21 21
 
22
-		return base64_encode($result);
23
-	}
24
-	public static function replaceNS2($str){
25
-		$str = str_replace("<ns2:", "<", $str);
26
-		$str = str_replace("</ns2:", "</", $str);
27
-		return $str;
28
-	}
29
-	public static $mime_types = array (
30
-			'apk' => 'application/vnd.android.package-archive',
31
-			'3gp' => 'video/3gpp', 'ai' => 'application/postscript', 
32
-			'aif' => 'audio/x-aiff', 'aifc' => 'audio/x-aiff', 
33
-			'aiff' => 'audio/x-aiff', 'asc' => 'text/plain', 
34
-			'atom' => 'application/atom+xml', 'au' => 'audio/basic', 
35
-			'avi' => 'video/x-msvideo', 'bcpio' => 'application/x-bcpio', 
36
-			'bin' => 'application/octet-stream', 'bmp' => 'image/bmp', 
37
-			'cdf' => 'application/x-netcdf', 'cgm' => 'image/cgm', 
38
-			'class' => 'application/octet-stream', 
39
-			'cpio' => 'application/x-cpio', 
40
-			'cpt' => 'application/mac-compactpro', 
41
-			'csh' => 'application/x-csh', 'css' => 'text/css', 
42
-			'dcr' => 'application/x-director', 'dif' => 'video/x-dv', 
43
-			'dir' => 'application/x-director', 'djv' => 'image/vnd.djvu', 
44
-			'djvu' => 'image/vnd.djvu', 
45
-			'dll' => 'application/octet-stream', 
46
-			'dmg' => 'application/octet-stream', 
47
-			'dms' => 'application/octet-stream', 
48
-			'doc' => 'application/msword', 'dtd' => 'application/xml-dtd', 
49
-			'dv' => 'video/x-dv', 'dvi' => 'application/x-dvi', 
50
-			'dxr' => 'application/x-director', 
51
-			'eps' => 'application/postscript', 'etx' => 'text/x-setext', 
52
-			'exe' => 'application/octet-stream', 
53
-			'ez' => 'application/andrew-inset', 'flv' => 'video/x-flv', 
54
-			'gif' => 'image/gif', 'gram' => 'application/srgs', 
55
-			'grxml' => 'application/srgs+xml', 
56
-			'gtar' => 'application/x-gtar', 'gz' => 'application/x-gzip', 
57
-			'hdf' => 'application/x-hdf', 
58
-			'hqx' => 'application/mac-binhex40', 'htm' => 'text/html', 
59
-			'html' => 'text/html', 'ice' => 'x-conference/x-cooltalk', 
60
-			'ico' => 'image/x-icon', 'ics' => 'text/calendar', 
61
-			'ief' => 'image/ief', 'ifb' => 'text/calendar', 
62
-			'iges' => 'model/iges', 'igs' => 'model/iges', 
63
-			'jnlp' => 'application/x-java-jnlp-file', 'jp2' => 'image/jp2', 
64
-			'jpe' => 'image/jpeg', 'jpeg' => 'image/jpeg', 
65
-			'jpg' => 'image/jpeg', 'js' => 'application/x-javascript', 
66
-			'kar' => 'audio/midi', 'latex' => 'application/x-latex', 
67
-			'lha' => 'application/octet-stream', 
68
-			'lzh' => 'application/octet-stream', 
69
-			'm3u' => 'audio/x-mpegurl', 'm4a' => 'audio/mp4a-latm', 
70
-			'm4p' => 'audio/mp4a-latm', 'm4u' => 'video/vnd.mpegurl', 
71
-			'm4v' => 'video/x-m4v', 'mac' => 'image/x-macpaint', 
72
-			'man' => 'application/x-troff-man', 
73
-			'mathml' => 'application/mathml+xml', 
74
-			'me' => 'application/x-troff-me', 'mesh' => 'model/mesh', 
75
-			'mid' => 'audio/midi', 'midi' => 'audio/midi', 
76
-			'mif' => 'application/vnd.mif', 'mov' => 'video/quicktime', 
77
-			'movie' => 'video/x-sgi-movie', 'mp2' => 'audio/mpeg', 
78
-			'mp3' => 'audio/mpeg', 'mp4' => 'video/mp4', 
79
-			'mpe' => 'video/mpeg', 'mpeg' => 'video/mpeg', 
80
-			'mpg' => 'video/mpeg', 'mpga' => 'audio/mpeg', 
81
-			'ms' => 'application/x-troff-ms', 'msh' => 'model/mesh', 
82
-			'mxu' => 'video/vnd.mpegurl', 'nc' => 'application/x-netcdf', 
83
-			'oda' => 'application/oda', 'ogg' => 'application/ogg', 
84
-			'ogv' => 'video/ogv', 'pbm' => 'image/x-portable-bitmap', 
85
-			'pct' => 'image/pict', 'pdb' => 'chemical/x-pdb', 
86
-			'pdf' => 'application/pdf', 
87
-			'pgm' => 'image/x-portable-graymap', 
88
-			'pgn' => 'application/x-chess-pgn', 'pic' => 'image/pict', 
89
-			'pict' => 'image/pict', 'png' => 'image/png', 
90
-			'pnm' => 'image/x-portable-anymap', 
91
-			'pnt' => 'image/x-macpaint', 'pntg' => 'image/x-macpaint', 
92
-			'ppm' => 'image/x-portable-pixmap', 
93
-			'ppt' => 'application/vnd.ms-powerpoint', 
94
-			'ps' => 'application/postscript', 'qt' => 'video/quicktime', 
95
-			'qti' => 'image/x-quicktime', 'qtif' => 'image/x-quicktime', 
96
-			'ra' => 'audio/x-pn-realaudio', 
97
-			'ram' => 'audio/x-pn-realaudio', 'ras' => 'image/x-cmu-raster', 
98
-			'rdf' => 'application/rdf+xml', 'rgb' => 'image/x-rgb', 
99
-			'rm' => 'application/vnd.rn-realmedia', 
100
-			'roff' => 'application/x-troff', 'rtf' => 'text/rtf', 
101
-			'rtx' => 'text/richtext', 'sgm' => 'text/sgml', 
102
-			'sgml' => 'text/sgml', 'sh' => 'application/x-sh', 
103
-			'shar' => 'application/x-shar', 'silo' => 'model/mesh', 
104
-			'sit' => 'application/x-stuffit', 
105
-			'skd' => 'application/x-koan', 'skm' => 'application/x-koan', 
106
-			'skp' => 'application/x-koan', 'skt' => 'application/x-koan', 
107
-			'smi' => 'application/smil', 'smil' => 'application/smil', 
108
-			'snd' => 'audio/basic', 'so' => 'application/octet-stream', 
109
-			'spl' => 'application/x-futuresplash', 
110
-			'src' => 'application/x-wais-source', 
111
-			'sv4cpio' => 'application/x-sv4cpio', 
112
-			'sv4crc' => 'application/x-sv4crc', 'svg' => 'image/svg+xml', 
113
-			'swf' => 'application/x-shockwave-flash', 
114
-			't' => 'application/x-troff', 'tar' => 'application/x-tar', 
115
-			'tcl' => 'application/x-tcl', 'tex' => 'application/x-tex', 
116
-			'texi' => 'application/x-texinfo', 
117
-			'texinfo' => 'application/x-texinfo', 'tif' => 'image/tiff', 
118
-			'tiff' => 'image/tiff', 'tr' => 'application/x-troff', 
119
-			'tsv' => 'text/tab-separated-values', 'txt' => 'text/plain', 
120
-			'ustar' => 'application/x-ustar', 
121
-			'vcd' => 'application/x-cdlink', 'vrml' => 'model/vrml', 
122
-			'vxml' => 'application/voicexml+xml', 'wav' => 'audio/x-wav', 
123
-			'wbmp' => 'image/vnd.wap.wbmp', 
124
-			'wbxml' => 'application/vnd.wap.wbxml', 'webm' => 'video/webm', 
125
-			'wml' => 'text/vnd.wap.wml', 
126
-			'wmlc' => 'application/vnd.wap.wmlc', 
127
-			'wmls' => 'text/vnd.wap.wmlscript', 
128
-			'wmlsc' => 'application/vnd.wap.wmlscriptc', 
129
-			'wmv' => 'video/x-ms-wmv', 'wrl' => 'model/vrml', 
130
-			'xbm' => 'image/x-xbitmap', 'xht' => 'application/xhtml+xml', 
131
-			'xhtml' => 'application/xhtml+xml', 
132
-			'xls' => 'application/vnd.ms-excel', 
133
-			'xml' => 'application/xml', 'xpm' => 'image/x-xpixmap', 
134
-			'xsl' => 'application/xml', 'xslt' => 'application/xslt+xml', 
135
-			'xul' => 'application/vnd.mozilla.xul+xml', 
136
-			'xwd' => 'image/x-xwindowdump', 'xyz' => 'chemical/x-xyz', 
137
-			'zip' => 'application/zip' );
22
+        return base64_encode($result);
23
+    }
24
+    public static function replaceNS2($str){
25
+        $str = str_replace("<ns2:", "<", $str);
26
+        $str = str_replace("</ns2:", "</", $str);
27
+        return $str;
28
+    }
29
+    public static $mime_types = array (
30
+            'apk' => 'application/vnd.android.package-archive',
31
+            '3gp' => 'video/3gpp', 'ai' => 'application/postscript', 
32
+            'aif' => 'audio/x-aiff', 'aifc' => 'audio/x-aiff', 
33
+            'aiff' => 'audio/x-aiff', 'asc' => 'text/plain', 
34
+            'atom' => 'application/atom+xml', 'au' => 'audio/basic', 
35
+            'avi' => 'video/x-msvideo', 'bcpio' => 'application/x-bcpio', 
36
+            'bin' => 'application/octet-stream', 'bmp' => 'image/bmp', 
37
+            'cdf' => 'application/x-netcdf', 'cgm' => 'image/cgm', 
38
+            'class' => 'application/octet-stream', 
39
+            'cpio' => 'application/x-cpio', 
40
+            'cpt' => 'application/mac-compactpro', 
41
+            'csh' => 'application/x-csh', 'css' => 'text/css', 
42
+            'dcr' => 'application/x-director', 'dif' => 'video/x-dv', 
43
+            'dir' => 'application/x-director', 'djv' => 'image/vnd.djvu', 
44
+            'djvu' => 'image/vnd.djvu', 
45
+            'dll' => 'application/octet-stream', 
46
+            'dmg' => 'application/octet-stream', 
47
+            'dms' => 'application/octet-stream', 
48
+            'doc' => 'application/msword', 'dtd' => 'application/xml-dtd', 
49
+            'dv' => 'video/x-dv', 'dvi' => 'application/x-dvi', 
50
+            'dxr' => 'application/x-director', 
51
+            'eps' => 'application/postscript', 'etx' => 'text/x-setext', 
52
+            'exe' => 'application/octet-stream', 
53
+            'ez' => 'application/andrew-inset', 'flv' => 'video/x-flv', 
54
+            'gif' => 'image/gif', 'gram' => 'application/srgs', 
55
+            'grxml' => 'application/srgs+xml', 
56
+            'gtar' => 'application/x-gtar', 'gz' => 'application/x-gzip', 
57
+            'hdf' => 'application/x-hdf', 
58
+            'hqx' => 'application/mac-binhex40', 'htm' => 'text/html', 
59
+            'html' => 'text/html', 'ice' => 'x-conference/x-cooltalk', 
60
+            'ico' => 'image/x-icon', 'ics' => 'text/calendar', 
61
+            'ief' => 'image/ief', 'ifb' => 'text/calendar', 
62
+            'iges' => 'model/iges', 'igs' => 'model/iges', 
63
+            'jnlp' => 'application/x-java-jnlp-file', 'jp2' => 'image/jp2', 
64
+            'jpe' => 'image/jpeg', 'jpeg' => 'image/jpeg', 
65
+            'jpg' => 'image/jpeg', 'js' => 'application/x-javascript', 
66
+            'kar' => 'audio/midi', 'latex' => 'application/x-latex', 
67
+            'lha' => 'application/octet-stream', 
68
+            'lzh' => 'application/octet-stream', 
69
+            'm3u' => 'audio/x-mpegurl', 'm4a' => 'audio/mp4a-latm', 
70
+            'm4p' => 'audio/mp4a-latm', 'm4u' => 'video/vnd.mpegurl', 
71
+            'm4v' => 'video/x-m4v', 'mac' => 'image/x-macpaint', 
72
+            'man' => 'application/x-troff-man', 
73
+            'mathml' => 'application/mathml+xml', 
74
+            'me' => 'application/x-troff-me', 'mesh' => 'model/mesh', 
75
+            'mid' => 'audio/midi', 'midi' => 'audio/midi', 
76
+            'mif' => 'application/vnd.mif', 'mov' => 'video/quicktime', 
77
+            'movie' => 'video/x-sgi-movie', 'mp2' => 'audio/mpeg', 
78
+            'mp3' => 'audio/mpeg', 'mp4' => 'video/mp4', 
79
+            'mpe' => 'video/mpeg', 'mpeg' => 'video/mpeg', 
80
+            'mpg' => 'video/mpeg', 'mpga' => 'audio/mpeg', 
81
+            'ms' => 'application/x-troff-ms', 'msh' => 'model/mesh', 
82
+            'mxu' => 'video/vnd.mpegurl', 'nc' => 'application/x-netcdf', 
83
+            'oda' => 'application/oda', 'ogg' => 'application/ogg', 
84
+            'ogv' => 'video/ogv', 'pbm' => 'image/x-portable-bitmap', 
85
+            'pct' => 'image/pict', 'pdb' => 'chemical/x-pdb', 
86
+            'pdf' => 'application/pdf', 
87
+            'pgm' => 'image/x-portable-graymap', 
88
+            'pgn' => 'application/x-chess-pgn', 'pic' => 'image/pict', 
89
+            'pict' => 'image/pict', 'png' => 'image/png', 
90
+            'pnm' => 'image/x-portable-anymap', 
91
+            'pnt' => 'image/x-macpaint', 'pntg' => 'image/x-macpaint', 
92
+            'ppm' => 'image/x-portable-pixmap', 
93
+            'ppt' => 'application/vnd.ms-powerpoint', 
94
+            'ps' => 'application/postscript', 'qt' => 'video/quicktime', 
95
+            'qti' => 'image/x-quicktime', 'qtif' => 'image/x-quicktime', 
96
+            'ra' => 'audio/x-pn-realaudio', 
97
+            'ram' => 'audio/x-pn-realaudio', 'ras' => 'image/x-cmu-raster', 
98
+            'rdf' => 'application/rdf+xml', 'rgb' => 'image/x-rgb', 
99
+            'rm' => 'application/vnd.rn-realmedia', 
100
+            'roff' => 'application/x-troff', 'rtf' => 'text/rtf', 
101
+            'rtx' => 'text/richtext', 'sgm' => 'text/sgml', 
102
+            'sgml' => 'text/sgml', 'sh' => 'application/x-sh', 
103
+            'shar' => 'application/x-shar', 'silo' => 'model/mesh', 
104
+            'sit' => 'application/x-stuffit', 
105
+            'skd' => 'application/x-koan', 'skm' => 'application/x-koan', 
106
+            'skp' => 'application/x-koan', 'skt' => 'application/x-koan', 
107
+            'smi' => 'application/smil', 'smil' => 'application/smil', 
108
+            'snd' => 'audio/basic', 'so' => 'application/octet-stream', 
109
+            'spl' => 'application/x-futuresplash', 
110
+            'src' => 'application/x-wais-source', 
111
+            'sv4cpio' => 'application/x-sv4cpio', 
112
+            'sv4crc' => 'application/x-sv4crc', 'svg' => 'image/svg+xml', 
113
+            'swf' => 'application/x-shockwave-flash', 
114
+            't' => 'application/x-troff', 'tar' => 'application/x-tar', 
115
+            'tcl' => 'application/x-tcl', 'tex' => 'application/x-tex', 
116
+            'texi' => 'application/x-texinfo', 
117
+            'texinfo' => 'application/x-texinfo', 'tif' => 'image/tiff', 
118
+            'tiff' => 'image/tiff', 'tr' => 'application/x-troff', 
119
+            'tsv' => 'text/tab-separated-values', 'txt' => 'text/plain', 
120
+            'ustar' => 'application/x-ustar', 
121
+            'vcd' => 'application/x-cdlink', 'vrml' => 'model/vrml', 
122
+            'vxml' => 'application/voicexml+xml', 'wav' => 'audio/x-wav', 
123
+            'wbmp' => 'image/vnd.wap.wbmp', 
124
+            'wbxml' => 'application/vnd.wap.wbxml', 'webm' => 'video/webm', 
125
+            'wml' => 'text/vnd.wap.wml', 
126
+            'wmlc' => 'application/vnd.wap.wmlc', 
127
+            'wmls' => 'text/vnd.wap.wmlscript', 
128
+            'wmlsc' => 'application/vnd.wap.wmlscriptc', 
129
+            'wmv' => 'video/x-ms-wmv', 'wrl' => 'model/vrml', 
130
+            'xbm' => 'image/x-xbitmap', 'xht' => 'application/xhtml+xml', 
131
+            'xhtml' => 'application/xhtml+xml', 
132
+            'xls' => 'application/vnd.ms-excel', 
133
+            'xml' => 'application/xml', 'xpm' => 'image/x-xpixmap', 
134
+            'xsl' => 'application/xml', 'xslt' => 'application/xslt+xml', 
135
+            'xul' => 'application/vnd.mozilla.xul+xml', 
136
+            'xwd' => 'image/x-xwindowdump', 'xyz' => 'chemical/x-xyz', 
137
+            'zip' => 'application/zip' );
138 138
 	
139
-	public static function get_mimetype($ext) {
140
-		return (isset ( self::$mime_types [$ext] ) ? self::$mime_types [$ext] : 'application/octet-stream');
141
-	}
142
-	/**
143
-	 * 检测是否含有中文
144
-	 * @param string $subject
145
-	 * @return boolean
146
-	 */
147
-	public static function chk_chinese($str){
148
-		return preg_match('/[\x80-\xff]./', $str);
149
-	}
139
+    public static function get_mimetype($ext) {
140
+        return (isset ( self::$mime_types [$ext] ) ? self::$mime_types [$ext] : 'application/octet-stream');
141
+    }
142
+    /**
143
+     * 检测是否含有中文
144
+     * @param string $subject
145
+     * @return boolean
146
+     */
147
+    public static function chk_chinese($str){
148
+        return preg_match('/[\x80-\xff]./', $str);
149
+    }
150 150
 	
151
-	/**
152
-	 * 检测是否GB2312编码
153
-	 * @param string $str 
154
-	 * @return boolean false UTF-8编码  TRUE GB2312编码
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编码  
166
-	                else  
167
-	                    return true;    //GB编码  
168
-	            }  
169
-	        }  
170
-	    }  
171
-	} 
151
+    /**
152
+     * 检测是否GB2312编码
153
+     * @param string $str 
154
+     * @return boolean false UTF-8编码  TRUE GB2312编码
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编码  
166
+                    else  
167
+                        return true;    //GB编码  
168
+                }  
169
+            }  
170
+        }  
171
+    } 
172 172
 
173 173
 
174
-	/**
175
-	 * 检测是否GBK编码
176
-	 * @param string $str 
177
-	 * @param boolean $gbk
178
-	 * @return boolean 
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;
191
-	                 }
192
-	            }
193
-	        }
194
-	    }
195
-	   return $gbk?TRUE:FALSE;
196
-	}
197
-	public static function iso8601($time=false) {
198
-    	if ($time === false) $time = time();
199
-   		$date = date('Y-m-d\TH:i:s\.Z', $time);
200
-   		return (substr($date, 0, strlen($date)-2).'Z');
201
-	}
202
-	public static function getFileSize($path){
203
-		$success = FALSE;
204
-		$isresource = FALSE;
205
-		if(!is_resource($path)){
206
-			$isresource = FALSE;
207
-			$resource = fopen($path,"r");
208
-		}else{
209
-			$isresource = TRUE;
210
-			$resource = $path;
211
-		}
212
-		$stat = fstat($resource);
213
-		$size = $stat["size"];
214
-		if($size<0){
215
-			$success = FALSE;
216
-		}else{
217
-			$success = TRUE;
218
-		}
219
-		if($success)
220
-			return $size;
221
-		else if($isresource)
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")){
227
-				throw new Ks3ClientException("please add 'extension=php_com_dotnet.dll' and set 'com.allow_dcom = true' in php.ini and restart");
228
-			}
229
-			 $fs = new COM("Scripting.FileSystemObject");
230
-   			 $size=$fs->GetFile($path)->Size;
231
-		}
232
-		return $size;
233
-	}
174
+    /**
175
+     * 检测是否GBK编码
176
+     * @param string $str 
177
+     * @param boolean $gbk
178
+     * @return boolean 
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;
191
+                        }
192
+                }
193
+            }
194
+        }
195
+        return $gbk?TRUE:FALSE;
196
+    }
197
+    public static function iso8601($time=false) {
198
+        if ($time === false) $time = time();
199
+            $date = date('Y-m-d\TH:i:s\.Z', $time);
200
+            return (substr($date, 0, strlen($date)-2).'Z');
201
+    }
202
+    public static function getFileSize($path){
203
+        $success = FALSE;
204
+        $isresource = FALSE;
205
+        if(!is_resource($path)){
206
+            $isresource = FALSE;
207
+            $resource = fopen($path,"r");
208
+        }else{
209
+            $isresource = TRUE;
210
+            $resource = $path;
211
+        }
212
+        $stat = fstat($resource);
213
+        $size = $stat["size"];
214
+        if($size<0){
215
+            $success = FALSE;
216
+        }else{
217
+            $success = TRUE;
218
+        }
219
+        if($success)
220
+            return $size;
221
+        else if($isresource)
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")){
227
+                throw new Ks3ClientException("please add 'extension=php_com_dotnet.dll' and set 'com.allow_dcom = true' in php.ini and restart");
228
+            }
229
+                $fs = new COM("Scripting.FileSystemObject");
230
+                $size=$fs->GetFile($path)->Size;
231
+        }
232
+        return $size;
233
+    }
234 234
 }
235 235
 ?>
236 236
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -1,32 +1,32 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 	}
Please login to merge, or discard this patch.
Braces   +28 added lines, -15 removed lines patch added patch discarded remove patch
@@ -158,13 +158,20 @@  discard block
 block discarded – undo
158 158
 	        $v = ord( $str[$i] );  
159 159
 	        if( $v > 127) {  
160 160
 	            if( ($v >= 228) && ($v <= 233) ){  
161
-	                if( ($i+2) >= (strlen($str) - 1)) return true;  // not enough characters  
161
+	                if( ($i+2) >= (strlen($str) - 1)) {
162
+	                    return true;
163
+	                }
164
+	                // not enough characters  
162 165
 	                $v1 = ord( $str[$i+1] );  
163 166
 	                $v2 = ord( $str[$i+2] );  
164
-	                if( ($v1 >= 128) && ($v1 <=191) && ($v2 >=128) && ($v2 <= 191) )  
165
-	                    return false;   //UTF-8编码  
166
-	                else  
167
-	                    return true;    //GB编码  
167
+	                if( ($v1 >= 128) && ($v1 <=191) && ($v2 >=128) && ($v2 <= 191) ) {
168
+	                	                    return false;
169
+	                }
170
+	                //UTF-8编码  
171
+	                else {
172
+	                	                    return true;
173
+	                }
174
+	                //GB编码  
168 175
 	            }  
169 176
 	        }  
170 177
 	    }  
@@ -182,11 +189,14 @@  discard block
 block discarded – undo
182 189
 	        $v = ord( $str[$i] );
183 190
 	        if( $v > 127){
184 191
 	            if( ($v >= 228) && ($v <= 233) ){
185
-	                 if(($i+2)>= (strlen($str)-1)) return $gbk?true:FALSE;  // not enough characters
192
+	                 if(($i+2)>= (strlen($str)-1)) {
193
+	                     return $gbk?true:FALSE;
194
+	                 }
195
+	                 // not enough characters
186 196
 	                 $v1 = ord( $str[$i+1] ); $v2 = ord( $str[$i+2] );
187 197
 	                 if($gbk){
188 198
 	                      return (($v1 >= 128) && ($v1 <=191) && ($v2 >=128) && ($v2 <= 191))?FALSE:TRUE;//GBK
189
-	                 }else{
199
+	                 } else{
190 200
 	                      return (($v1 >= 128) && ($v1 <=191) && ($v2 >=128) && ($v2 <= 191))?TRUE:FALSE;
191 201
 	                 }
192 202
 	            }
@@ -195,7 +205,9 @@  discard block
 block discarded – undo
195 205
 	   return $gbk?TRUE:FALSE;
196 206
 	}
197 207
 	public static function iso8601($time=false) {
198
-    	if ($time === false) $time = time();
208
+    	if ($time === false) {
209
+    	    $time = time();
210
+    	}
199 211
    		$date = date('Y-m-d\TH:i:s\.Z', $time);
200 212
    		return (substr($date, 0, strlen($date)-2).'Z');
201 213
 	}
@@ -205,7 +217,7 @@  discard block
 block discarded – undo
205 217
 		if(!is_resource($path)){
206 218
 			$isresource = FALSE;
207 219
 			$resource = fopen($path,"r");
208
-		}else{
220
+		} else{
209 221
 			$isresource = TRUE;
210 222
 			$resource = $path;
211 223
 		}
@@ -213,16 +225,17 @@  discard block
 block discarded – undo
213 225
 		$size = $stat["size"];
214 226
 		if($size<0){
215 227
 			$success = FALSE;
216
-		}else{
228
+		} else{
217 229
 			$success = TRUE;
218 230
 		}
219
-		if($success)
220
-			return $size;
221
-		else if($isresource)
222
-			throw new Ks3ClientException("please use file path instead resource");
231
+		if($success) {
232
+					return $size;
233
+		} else if($isresource) {
234
+					throw new Ks3ClientException("please use file path instead resource");
235
+		}
223 236
 		if(!((strtoupper(substr(PHP_OS,0,3))=="WIN"))){//如果不是windows系统,尝试使用stat命令
224 237
 			$size=trim(`stat -c%s $path`);
225
-		}else{//如果是windows系统,尝试cmd命令
238
+		} else{//如果是windows系统,尝试cmd命令
226 239
 			if(!class_exists("COM")){
227 240
 				throw new Ks3ClientException("please add 'extension=php_com_dotnet.dll' and set 'com.allow_dcom = true' in php.ini and restart");
228 241
 			}
Please login to merge, or discard this patch.
src/service/ksyun/bin/core/API.php 2 patches
Indentation   +259 added lines, -259 removed lines patch added patch discarded remove patch
@@ -8,264 +8,264 @@
 block discarded – undo
8 8
 handler:结果处理链
9 9
 */
10 10
 class API{
11
-	public static $API = array(
12
-		"getService"=>array(
13
-			"redirect"=>"listBuckets"
14
-		),
15
-		"listBuckets"=> array(
16
-			"method"=>"GET",
17
-			"needBucket"=>FALSE,
18
-			"needObject"=>FALSE,
19
-			"signer"=>"DefaultUserAgentSigner->DefaultContentTypeSigner->HeaderAuthSigner",
20
-			"handler"=>"ErrorResponseHandler->ListBucketsHandler"
21
-		),
22
-		"deleteBucket"=>array(
23
-			"method"=>"DELETE",
24
-			"needBucket"=>TRUE,
25
-			"needObject"=>FALSE,
26
-			"signer"=>"DefaultUserAgentSigner->DefaultContentTypeSigner->HeaderAuthSigner",
27
-			"handler"=>"ErrorResponseHandler->BooleanHandler"
28
-		),
29
-		"deleteBucketCORS"=>array(
30
-			"method"=>"DELETE",
31
-			"needBucket"=>TRUE,
32
-			"needObject"=>FALSE,
33
-			"subResource"=>"cors",
34
-			"signer"=>"DefaultUserAgentSigner->DefaultContentTypeSigner->HeaderAuthSigner",
35
-			"handler"=>"ErrorResponseHandler->BooleanHandler"
36
-		),
37
-		"createBucket"=>array(
38
-			"method"=>"PUT",
39
-			"needBucket"=>TRUE,
40
-			"needObject"=>FALSE,
41
-			"signer"=>"DefaultUserAgentSigner->ACLSigner->DefaultContentTypeSigner->HeaderAuthSigner",
42
-			"body"=>Array("builder"=>"LocationBuilder"),
43
-			"handler"=>"ErrorResponseHandler->BooleanHandler"
44
-		),
45
-		"setBucketAcl"=>array(
46
-			"method"=>"PUT",
47
-			"needBucket"=>TRUE,
48
-			"needObject"=>FALSE,
49
-			"signer"=>"DefaultUserAgentSigner->ACLSigner->DefaultContentTypeSigner->HeaderAuthSigner",
50
-			"subResource"=>"acl",
51
-			"handler"=>"ErrorResponseHandler->BooleanHandler"
52
-		),
53
-		"setBucketCORS"=>array(
54
-			"method"=>"PUT",
55
-			"needBucket"=>TRUE,
56
-			"needObject"=>FALSE,
57
-			"signer"=>"DefaultUserAgentSigner->DefaultContentTypeSigner->ContentMD5Signer->HeaderAuthSigner",
58
-			"subResource"=>"cors",
59
-			"body"=>Array("builder"=>"CORSBuilder"),
60
-			"handler"=>"ErrorResponseHandler->BooleanHandler"
61
-		),
62
-		"setBucketLogging"=>array(
63
-			"method"=>"PUT",
64
-			"needBucket"=>TRUE,
65
-			"needObject"=>FALSE,
66
-			"signer"=>"DefaultUserAgentSigner->DefaultContentTypeSigner->HeaderAuthSigner",
67
-			"subResource"=>"logging",
68
-			"body"=>Array("builder"=>"BucketLoggingBuilder"),
69
-			"handler"=>"ErrorResponseHandler->BooleanHandler"
70
-		),
71
-		"listObjects" => array(
72
-			"method"=>"GET",
73
-			"needBucket"=>TRUE,
74
-			"needObject"=>FALSE,
75
-			"signer"=>"DefaultUserAgentSigner->DefaultContentTypeSigner->HeaderAuthSigner",
76
-			"queryParams"=>array("Options->prefix","Options->delimiter","Options->marker","Options->max-keys"),
77
-			"handler"=>"ErrorResponseHandler->ListObjectsHandler"
78
-		),
79
-		"getBucketAcl" => array(
80
-			"method"=>"GET",
81
-			"needBucket"=>TRUE,
82
-			"needObject"=>FALSE,
83
-			"subResource"=>"acl",
84
-			"signer"=>"DefaultUserAgentSigner->DefaultContentTypeSigner->HeaderAuthSigner",
85
-			"handler"=>"ErrorResponseHandler->GetAclHandler"
86
-		),
87
-		"getBucketCORS"=>array(
88
-			"method"=>"GET",
89
-			"needBucket"=>TRUE,
90
-			"needObject"=>FALSE,
91
-			"subResource"=>"cors",
92
-			"signer"=>"DefaultUserAgentSigner->DefaultContentTypeSigner->HeaderAuthSigner",
93
-			"handler"=>"ErrorResponseHandler->GetBucketCORSHandler"
94
-		),
95
-		"getBucketLocation"=>array(
96
-			"method"=>"GET",
97
-			"needBucket"=>TRUE,
98
-			"needObject"=>FALSE,
99
-			"subResource"=>"location",
100
-			"signer"=>"DefaultUserAgentSigner->DefaultContentTypeSigner->HeaderAuthSigner",
101
-			"handler"=>"ErrorResponseHandler->GetBucketLocationHandler"
102
-		),
103
-		"getBucketLogging"=>array(
104
-			"method"=>"GET",
105
-			"needBucket"=>TRUE,
106
-			"needObject"=>FALSE,
107
-			"subResource"=>"logging",
108
-			"signer"=>"DefaultUserAgentSigner->DefaultContentTypeSigner->HeaderAuthSigner",
109
-			"handler"=>"ErrorResponseHandler->GetBucketLoggingHandler"
110
-		),
111
-		"listMutipartUploads"=>array(
112
-			"method"=>"GET",
113
-			"needBucket"=>TRUE,
114
-			"needObject"=>FALSE,
115
-			"subResource"=>"uploads",
116
-			"queryParams"=>array("Options->max-uploads","Options->key-marker","Options->prefix","Options->upload-id-​marker","Options->delimiter"),
117
-			"signer"=>"DefaultUserAgentSigner->DefaultContentTypeSigner->HeaderAuthSigner",
118
-			"handler"=>"ErrorResponseHandler->ListMutipartUploadsHandler"
119
-		),
120
-		"bucketExists"=>array(
121
-			"method"=>"HEAD",
122
-			"needBucket"=>TRUE,
123
-			"needObject"=>FALSE,
124
-			"signer"=>"DefaultUserAgentSigner->DefaultContentTypeSigner->HeaderAuthSigner",
125
-			"handler"=>"ExistsHandler"
126
-		),
127
-		"putObjectByContent"=>array(
128
-			"method"=>"PUT",
129
-			"needBucket"=>TRUE,
130
-			"needObject"=>TRUE,
131
-			//将ContentMD5Signer放在最后的原因是,ContentMD5需要根据Content-Length计算
132
-			"signer"=>"DefaultUserAgentSigner->ACLSigner->SuffixContentTypeSigner->ContentLengthSigner->ObjectMetaSigner->ContentMD5Signer->UserMetaSigner->AdpSigner->CallBackSigner->SSESigner->SSECSigner->HeaderAuthSigner",
133
-			"handler"=>"ErrorResponseHandler->UploadHandler",
134
-			"body"=>array("position"=>"Content")
135
-		),
136
-		"putObjectByFile"=>array(
137
-			"method"=>"PUT",
138
-			"needBucket"=>TRUE,
139
-			"needObject"=>TRUE,
140
-			"signer"=>"DefaultUserAgentSigner->ACLSigner->SuffixContentTypeSigner->ObjectMetaSigner->UserMetaSigner->AdpSigner->CallBackSigner->SSESigner->SSECSigner->StreamUploadSigner->HeaderAuthSigner",
141
-			"handler"=>"ErrorResponseHandler->UploadHandler"
142
-		),
143
-		"setObjectAcl"=>array(
144
-			"method"=>"PUT",
145
-			"needBucket"=>TRUE,
146
-			"needObject"=>TRUE,
147
-			"signer"=>"DefaultUserAgentSigner->ACLSigner->DefaultContentTypeSigner->HeaderAuthSigner",
148
-			"subResource"=>"acl",
149
-			"handler"=>"ErrorResponseHandler->BooleanHandler"
150
-		),
151
-		"copyObject"=>array(
152
-			"method"=>"PUT",
153
-			"needBucket"=>TRUE,
154
-			"needObject"=>TRUE,
155
-			"signer"=>"DefaultUserAgentSigner->CopySourceSigner->DefaultContentTypeSigner->CallBackSigner->SSESigner->SSECSigner->SSECSourceSigner->HeaderAuthSigner",
156
-			"handler"=>"ErrorResponseHandler->CopyHandler"
157
-		),
158
-		"getObjectMeta"=>array(
159
-			"method"=>"HEAD",
160
-			"needBucket"=>TRUE,
161
-			"needObject"=>TRUE,
162
-			"signer"=>"DefaultUserAgentSigner->DefaultContentTypeSigner->SSECSigner->HeaderAuthSigner",
163
-			"handler"=>"ErrorResponseHandler->ObjectMetaHandler"
164
-		),
165
-		"objectExists"=>array(
166
-			"method"=>"HEAD",
167
-			"needBucket"=>TRUE,
168
-			"needObject"=>TRUE,
169
-			"signer"=>"DefaultUserAgentSigner->DefaultContentTypeSigner->SSECSigner->HeaderAuthSigner",
170
-			"handler"=>"ExistsHandler"
171
-		),
172
-		"deleteObject"=>array(
173
-			"method"=>"DELETE",
174
-			"needBucket"=>TRUE,
175
-			"needObject"=>TRUE,
176
-			"signer"=>"DefaultUserAgentSigner->DefaultContentTypeSigner->HeaderAuthSigner",
177
-			"handler"=>"ErrorResponseHandler->BooleanHandler"			
178
-		),
179
-		"deleteObjects"=>array(
180
-			"method"=>"POST",
181
-			"needBucket"=>TRUE,
182
-			"needObject"=>FALSE,
183
-			"subResource"=>"delete",
184
-			"signer"=>"DefaultUserAgentSigner->DefaultContentTypeSigner->ContentMD5Signer->ContentLengthSigner->HeaderAuthSigner",
185
-			"body"=>array("builder"=>"DeleteObjectsBuilder"),
186
-			"handler"=>"ErrorResponseHandler->BooleanHandler"
187
-		),
188
-		"getObject"=>array(
189
-			"method"=>"GET",
190
-			"needBucket"=>TRUE,
191
-			"needObject"=>TRUE,
192
-			"signer"=>"DefaultUserAgentSigner->DefaultContentTypeSigner->RangeSigner->SSECSigner->GetObjectSigner->HeaderAuthSigner",
193
-			"handler"=>"ErrorResponseHandler->getObjectHandler"
194
-		),
195
-		"getObjectAcl" => array(
196
-			"method"=>"GET",
197
-			"needBucket"=>TRUE,
198
-			"needObject"=>TRUE,
199
-			"subResource"=>"acl",
200
-			"signer"=>"DefaultUserAgentSigner->DefaultContentTypeSigner->HeaderAuthSigner",
201
-			"handler"=>"ErrorResponseHandler->GetAclHandler"
202
-		),
203
-		"initMultipartUpload"=>array(
204
-			"method"=>"POST",
205
-			"needBucket"=>TRUE,
206
-			"needObject"=>TRUE,
207
-			"subResource"=>"uploads",
208
-			"signer"=>"DefaultUserAgentSigner->ACLSigner->SuffixContentTypeSigner->MultipartObjectMetaSigner->UserMetaSigner->SSESigner->SSECSigner->HeaderAuthSigner",
209
-			"handler"=>"ErrorResponseHandler->InitMultipartUploadHandler"
210
-		),
211
-		"uploadPart"=>array(
212
-			"method"=>"PUT",
213
-			"needBucket"=>TRUE,
214
-			"needObject"=>TRUE,
215
-			"queryParams"=>array("!Options->uploadId","!Options->partNumber"),
216
-			//这个请求没有body,所以使用了ContentLengthSigner->ContentMD5Signer而没用ObjectMetaSigner
217
-			"signer"=>"DefaultUserAgentSigner->ACLSigner->StreamContentTypeSigner->ContentLengthSigner->ContentMD5Signer->SSECSigner->StreamUploadSigner->HeaderAuthSigner",
218
-			"handler"=>"ErrorResponseHandler->UploadHandler"
219
-		),
220
-		"abortMultipartUpload"=>array(
221
-			"method"=>"DELETE",
222
-			"needBucket"=>TRUE,
223
-			"needObject"=>TRUE,
224
-			"queryParams"=>array("!Options->uploadId"),
225
-			"signer"=>"DefaultUserAgentSigner->DefaultContentTypeSigner->HeaderAuthSigner",
226
-			"handler"=>"ErrorResponseHandler->BooleanHandler"
227
-		),
228
-		"listParts"=>array(
229
-			"method"=>"GET",
230
-			"needBucket"=>TRUE,
231
-			"needObject"=>TRUE,
232
-			"queryParams"=>array("!Options->uploadId","Options->max-parts","Options->part-number​-marker"),
233
-			"signer"=>"DefaultUserAgentSigner->DefaultContentTypeSigner->HeaderAuthSigner",
234
-			"handler"=>"ErrorResponseHandler->ListPartsHandler"
235
-		),
236
-		"completeMultipartUpload"=>array(
237
-			"method"=>"POST",
238
-			"needBucket"=>TRUE,
239
-			"needObject"=>TRUE,
240
-			"queryParams"=>array("!Options->uploadId"),
241
-			"signer"=>"DefaultUserAgentSigner->DefaultContentTypeSigner->ContentLengthSigner->AdpSigner->CallBackSigner->HeaderAuthSigner",
242
-			"handler"=>"ErrorResponseHandler->UploadHandler",
243
-			"body"=>array("builder"=>"CompleteMultipartUploadBuilder")
244
-		),
245
-		"generatePresignedUrl"=>array(
246
-			"method"=>"Method",
247
-			"needBucket"=>FALSE,
248
-			"needObject"=>FALSE,
249
-			"queryParams"=>array("!Options->Expires","Options->*"),
250
-			"signer"=>"AllHeaderSigner->QueryAuthSigner",
251
-		),
252
-		"putAdp"=>array(
253
-			"method"=>"PUT",
254
-			"needBucket"=>TRUE,
255
-			"needObject"=>TRUE,
256
-			"subResource"=>"adp",
257
-			"signer"=>"DefaultUserAgentSigner->DefaultContentTypeSigner->AdpSigner->HeaderAuthSigner",
258
-			"handler"=>"ErrorResponseHandler->UploadHandler"
259
-		),
260
-		"getAdp"=>array(
261
-			"method"=>"GET",
262
-			"needBucket"=>FALSE,
263
-			"needObject"=>TRUE,
264
-			"objectPostion"=>"TaskID",//专门为这个接口定义的属性
265
-			"subResource"=>"queryadp",
266
-			"signer"=>"DefaultUserAgentSigner",
267
-			"handler"=>"ErrorResponseHandler->AdpHandler"
268
-		)
269
-	);
11
+    public static $API = array(
12
+        "getService"=>array(
13
+            "redirect"=>"listBuckets"
14
+        ),
15
+        "listBuckets"=> array(
16
+            "method"=>"GET",
17
+            "needBucket"=>FALSE,
18
+            "needObject"=>FALSE,
19
+            "signer"=>"DefaultUserAgentSigner->DefaultContentTypeSigner->HeaderAuthSigner",
20
+            "handler"=>"ErrorResponseHandler->ListBucketsHandler"
21
+        ),
22
+        "deleteBucket"=>array(
23
+            "method"=>"DELETE",
24
+            "needBucket"=>TRUE,
25
+            "needObject"=>FALSE,
26
+            "signer"=>"DefaultUserAgentSigner->DefaultContentTypeSigner->HeaderAuthSigner",
27
+            "handler"=>"ErrorResponseHandler->BooleanHandler"
28
+        ),
29
+        "deleteBucketCORS"=>array(
30
+            "method"=>"DELETE",
31
+            "needBucket"=>TRUE,
32
+            "needObject"=>FALSE,
33
+            "subResource"=>"cors",
34
+            "signer"=>"DefaultUserAgentSigner->DefaultContentTypeSigner->HeaderAuthSigner",
35
+            "handler"=>"ErrorResponseHandler->BooleanHandler"
36
+        ),
37
+        "createBucket"=>array(
38
+            "method"=>"PUT",
39
+            "needBucket"=>TRUE,
40
+            "needObject"=>FALSE,
41
+            "signer"=>"DefaultUserAgentSigner->ACLSigner->DefaultContentTypeSigner->HeaderAuthSigner",
42
+            "body"=>Array("builder"=>"LocationBuilder"),
43
+            "handler"=>"ErrorResponseHandler->BooleanHandler"
44
+        ),
45
+        "setBucketAcl"=>array(
46
+            "method"=>"PUT",
47
+            "needBucket"=>TRUE,
48
+            "needObject"=>FALSE,
49
+            "signer"=>"DefaultUserAgentSigner->ACLSigner->DefaultContentTypeSigner->HeaderAuthSigner",
50
+            "subResource"=>"acl",
51
+            "handler"=>"ErrorResponseHandler->BooleanHandler"
52
+        ),
53
+        "setBucketCORS"=>array(
54
+            "method"=>"PUT",
55
+            "needBucket"=>TRUE,
56
+            "needObject"=>FALSE,
57
+            "signer"=>"DefaultUserAgentSigner->DefaultContentTypeSigner->ContentMD5Signer->HeaderAuthSigner",
58
+            "subResource"=>"cors",
59
+            "body"=>Array("builder"=>"CORSBuilder"),
60
+            "handler"=>"ErrorResponseHandler->BooleanHandler"
61
+        ),
62
+        "setBucketLogging"=>array(
63
+            "method"=>"PUT",
64
+            "needBucket"=>TRUE,
65
+            "needObject"=>FALSE,
66
+            "signer"=>"DefaultUserAgentSigner->DefaultContentTypeSigner->HeaderAuthSigner",
67
+            "subResource"=>"logging",
68
+            "body"=>Array("builder"=>"BucketLoggingBuilder"),
69
+            "handler"=>"ErrorResponseHandler->BooleanHandler"
70
+        ),
71
+        "listObjects" => array(
72
+            "method"=>"GET",
73
+            "needBucket"=>TRUE,
74
+            "needObject"=>FALSE,
75
+            "signer"=>"DefaultUserAgentSigner->DefaultContentTypeSigner->HeaderAuthSigner",
76
+            "queryParams"=>array("Options->prefix","Options->delimiter","Options->marker","Options->max-keys"),
77
+            "handler"=>"ErrorResponseHandler->ListObjectsHandler"
78
+        ),
79
+        "getBucketAcl" => array(
80
+            "method"=>"GET",
81
+            "needBucket"=>TRUE,
82
+            "needObject"=>FALSE,
83
+            "subResource"=>"acl",
84
+            "signer"=>"DefaultUserAgentSigner->DefaultContentTypeSigner->HeaderAuthSigner",
85
+            "handler"=>"ErrorResponseHandler->GetAclHandler"
86
+        ),
87
+        "getBucketCORS"=>array(
88
+            "method"=>"GET",
89
+            "needBucket"=>TRUE,
90
+            "needObject"=>FALSE,
91
+            "subResource"=>"cors",
92
+            "signer"=>"DefaultUserAgentSigner->DefaultContentTypeSigner->HeaderAuthSigner",
93
+            "handler"=>"ErrorResponseHandler->GetBucketCORSHandler"
94
+        ),
95
+        "getBucketLocation"=>array(
96
+            "method"=>"GET",
97
+            "needBucket"=>TRUE,
98
+            "needObject"=>FALSE,
99
+            "subResource"=>"location",
100
+            "signer"=>"DefaultUserAgentSigner->DefaultContentTypeSigner->HeaderAuthSigner",
101
+            "handler"=>"ErrorResponseHandler->GetBucketLocationHandler"
102
+        ),
103
+        "getBucketLogging"=>array(
104
+            "method"=>"GET",
105
+            "needBucket"=>TRUE,
106
+            "needObject"=>FALSE,
107
+            "subResource"=>"logging",
108
+            "signer"=>"DefaultUserAgentSigner->DefaultContentTypeSigner->HeaderAuthSigner",
109
+            "handler"=>"ErrorResponseHandler->GetBucketLoggingHandler"
110
+        ),
111
+        "listMutipartUploads"=>array(
112
+            "method"=>"GET",
113
+            "needBucket"=>TRUE,
114
+            "needObject"=>FALSE,
115
+            "subResource"=>"uploads",
116
+            "queryParams"=>array("Options->max-uploads","Options->key-marker","Options->prefix","Options->upload-id-​marker","Options->delimiter"),
117
+            "signer"=>"DefaultUserAgentSigner->DefaultContentTypeSigner->HeaderAuthSigner",
118
+            "handler"=>"ErrorResponseHandler->ListMutipartUploadsHandler"
119
+        ),
120
+        "bucketExists"=>array(
121
+            "method"=>"HEAD",
122
+            "needBucket"=>TRUE,
123
+            "needObject"=>FALSE,
124
+            "signer"=>"DefaultUserAgentSigner->DefaultContentTypeSigner->HeaderAuthSigner",
125
+            "handler"=>"ExistsHandler"
126
+        ),
127
+        "putObjectByContent"=>array(
128
+            "method"=>"PUT",
129
+            "needBucket"=>TRUE,
130
+            "needObject"=>TRUE,
131
+            //将ContentMD5Signer放在最后的原因是,ContentMD5需要根据Content-Length计算
132
+            "signer"=>"DefaultUserAgentSigner->ACLSigner->SuffixContentTypeSigner->ContentLengthSigner->ObjectMetaSigner->ContentMD5Signer->UserMetaSigner->AdpSigner->CallBackSigner->SSESigner->SSECSigner->HeaderAuthSigner",
133
+            "handler"=>"ErrorResponseHandler->UploadHandler",
134
+            "body"=>array("position"=>"Content")
135
+        ),
136
+        "putObjectByFile"=>array(
137
+            "method"=>"PUT",
138
+            "needBucket"=>TRUE,
139
+            "needObject"=>TRUE,
140
+            "signer"=>"DefaultUserAgentSigner->ACLSigner->SuffixContentTypeSigner->ObjectMetaSigner->UserMetaSigner->AdpSigner->CallBackSigner->SSESigner->SSECSigner->StreamUploadSigner->HeaderAuthSigner",
141
+            "handler"=>"ErrorResponseHandler->UploadHandler"
142
+        ),
143
+        "setObjectAcl"=>array(
144
+            "method"=>"PUT",
145
+            "needBucket"=>TRUE,
146
+            "needObject"=>TRUE,
147
+            "signer"=>"DefaultUserAgentSigner->ACLSigner->DefaultContentTypeSigner->HeaderAuthSigner",
148
+            "subResource"=>"acl",
149
+            "handler"=>"ErrorResponseHandler->BooleanHandler"
150
+        ),
151
+        "copyObject"=>array(
152
+            "method"=>"PUT",
153
+            "needBucket"=>TRUE,
154
+            "needObject"=>TRUE,
155
+            "signer"=>"DefaultUserAgentSigner->CopySourceSigner->DefaultContentTypeSigner->CallBackSigner->SSESigner->SSECSigner->SSECSourceSigner->HeaderAuthSigner",
156
+            "handler"=>"ErrorResponseHandler->CopyHandler"
157
+        ),
158
+        "getObjectMeta"=>array(
159
+            "method"=>"HEAD",
160
+            "needBucket"=>TRUE,
161
+            "needObject"=>TRUE,
162
+            "signer"=>"DefaultUserAgentSigner->DefaultContentTypeSigner->SSECSigner->HeaderAuthSigner",
163
+            "handler"=>"ErrorResponseHandler->ObjectMetaHandler"
164
+        ),
165
+        "objectExists"=>array(
166
+            "method"=>"HEAD",
167
+            "needBucket"=>TRUE,
168
+            "needObject"=>TRUE,
169
+            "signer"=>"DefaultUserAgentSigner->DefaultContentTypeSigner->SSECSigner->HeaderAuthSigner",
170
+            "handler"=>"ExistsHandler"
171
+        ),
172
+        "deleteObject"=>array(
173
+            "method"=>"DELETE",
174
+            "needBucket"=>TRUE,
175
+            "needObject"=>TRUE,
176
+            "signer"=>"DefaultUserAgentSigner->DefaultContentTypeSigner->HeaderAuthSigner",
177
+            "handler"=>"ErrorResponseHandler->BooleanHandler"			
178
+        ),
179
+        "deleteObjects"=>array(
180
+            "method"=>"POST",
181
+            "needBucket"=>TRUE,
182
+            "needObject"=>FALSE,
183
+            "subResource"=>"delete",
184
+            "signer"=>"DefaultUserAgentSigner->DefaultContentTypeSigner->ContentMD5Signer->ContentLengthSigner->HeaderAuthSigner",
185
+            "body"=>array("builder"=>"DeleteObjectsBuilder"),
186
+            "handler"=>"ErrorResponseHandler->BooleanHandler"
187
+        ),
188
+        "getObject"=>array(
189
+            "method"=>"GET",
190
+            "needBucket"=>TRUE,
191
+            "needObject"=>TRUE,
192
+            "signer"=>"DefaultUserAgentSigner->DefaultContentTypeSigner->RangeSigner->SSECSigner->GetObjectSigner->HeaderAuthSigner",
193
+            "handler"=>"ErrorResponseHandler->getObjectHandler"
194
+        ),
195
+        "getObjectAcl" => array(
196
+            "method"=>"GET",
197
+            "needBucket"=>TRUE,
198
+            "needObject"=>TRUE,
199
+            "subResource"=>"acl",
200
+            "signer"=>"DefaultUserAgentSigner->DefaultContentTypeSigner->HeaderAuthSigner",
201
+            "handler"=>"ErrorResponseHandler->GetAclHandler"
202
+        ),
203
+        "initMultipartUpload"=>array(
204
+            "method"=>"POST",
205
+            "needBucket"=>TRUE,
206
+            "needObject"=>TRUE,
207
+            "subResource"=>"uploads",
208
+            "signer"=>"DefaultUserAgentSigner->ACLSigner->SuffixContentTypeSigner->MultipartObjectMetaSigner->UserMetaSigner->SSESigner->SSECSigner->HeaderAuthSigner",
209
+            "handler"=>"ErrorResponseHandler->InitMultipartUploadHandler"
210
+        ),
211
+        "uploadPart"=>array(
212
+            "method"=>"PUT",
213
+            "needBucket"=>TRUE,
214
+            "needObject"=>TRUE,
215
+            "queryParams"=>array("!Options->uploadId","!Options->partNumber"),
216
+            //这个请求没有body,所以使用了ContentLengthSigner->ContentMD5Signer而没用ObjectMetaSigner
217
+            "signer"=>"DefaultUserAgentSigner->ACLSigner->StreamContentTypeSigner->ContentLengthSigner->ContentMD5Signer->SSECSigner->StreamUploadSigner->HeaderAuthSigner",
218
+            "handler"=>"ErrorResponseHandler->UploadHandler"
219
+        ),
220
+        "abortMultipartUpload"=>array(
221
+            "method"=>"DELETE",
222
+            "needBucket"=>TRUE,
223
+            "needObject"=>TRUE,
224
+            "queryParams"=>array("!Options->uploadId"),
225
+            "signer"=>"DefaultUserAgentSigner->DefaultContentTypeSigner->HeaderAuthSigner",
226
+            "handler"=>"ErrorResponseHandler->BooleanHandler"
227
+        ),
228
+        "listParts"=>array(
229
+            "method"=>"GET",
230
+            "needBucket"=>TRUE,
231
+            "needObject"=>TRUE,
232
+            "queryParams"=>array("!Options->uploadId","Options->max-parts","Options->part-number​-marker"),
233
+            "signer"=>"DefaultUserAgentSigner->DefaultContentTypeSigner->HeaderAuthSigner",
234
+            "handler"=>"ErrorResponseHandler->ListPartsHandler"
235
+        ),
236
+        "completeMultipartUpload"=>array(
237
+            "method"=>"POST",
238
+            "needBucket"=>TRUE,
239
+            "needObject"=>TRUE,
240
+            "queryParams"=>array("!Options->uploadId"),
241
+            "signer"=>"DefaultUserAgentSigner->DefaultContentTypeSigner->ContentLengthSigner->AdpSigner->CallBackSigner->HeaderAuthSigner",
242
+            "handler"=>"ErrorResponseHandler->UploadHandler",
243
+            "body"=>array("builder"=>"CompleteMultipartUploadBuilder")
244
+        ),
245
+        "generatePresignedUrl"=>array(
246
+            "method"=>"Method",
247
+            "needBucket"=>FALSE,
248
+            "needObject"=>FALSE,
249
+            "queryParams"=>array("!Options->Expires","Options->*"),
250
+            "signer"=>"AllHeaderSigner->QueryAuthSigner",
251
+        ),
252
+        "putAdp"=>array(
253
+            "method"=>"PUT",
254
+            "needBucket"=>TRUE,
255
+            "needObject"=>TRUE,
256
+            "subResource"=>"adp",
257
+            "signer"=>"DefaultUserAgentSigner->DefaultContentTypeSigner->AdpSigner->HeaderAuthSigner",
258
+            "handler"=>"ErrorResponseHandler->UploadHandler"
259
+        ),
260
+        "getAdp"=>array(
261
+            "method"=>"GET",
262
+            "needBucket"=>FALSE,
263
+            "needObject"=>TRUE,
264
+            "objectPostion"=>"TaskID",//专门为这个接口定义的属性
265
+            "subResource"=>"queryadp",
266
+            "signer"=>"DefaultUserAgentSigner",
267
+            "handler"=>"ErrorResponseHandler->AdpHandler"
268
+        )
269
+    );
270 270
 }
271 271
 ?>
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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"
Please login to merge, or discard this patch.
src/service/ksyun/bin/core/Handlers.php 3 patches
Indentation   +289 added lines, -289 removed lines patch added patch discarded remove patch
@@ -2,342 +2,342 @@
 block discarded – undo
2 2
 require_once KS3_API_PATH.DIRECTORY_SEPARATOR."exceptions".DIRECTORY_SEPARATOR."Exceptions.php";
3 3
 
4 4
 interface Handler{
5
-	public function handle(ResponseCore $response);
5
+    public function handle(ResponseCore $response);
6 6
 }
7 7
 class ErrorResponseHandler implements Handler{
8
-	public function handle(ResponseCore $response){
9
-		$code = $response->status;
10
-		if($code >= 400){
11
-			$exception = new Ks3ServiceException();
12
-			$exception->statusCode=$code;
13
-			if(!empty($response->body)){
14
-				$xml = new SimpleXMLElement($response->body);
15
-				$exception ->requestId = $xml->RequestId->__toString();
16
-				$exception->errorCode = $xml->Code->__toString();
17
-				$exception->errorMessage=$xml->Message->__toString();
18
-				$exception->resource=$xml->Resource->__toString();
19
-			}
20
-			throw $exception;
21
-		}else{
22
-			return $response;
23
-		}
24
-	}
8
+    public function handle(ResponseCore $response){
9
+        $code = $response->status;
10
+        if($code >= 400){
11
+            $exception = new Ks3ServiceException();
12
+            $exception->statusCode=$code;
13
+            if(!empty($response->body)){
14
+                $xml = new SimpleXMLElement($response->body);
15
+                $exception ->requestId = $xml->RequestId->__toString();
16
+                $exception->errorCode = $xml->Code->__toString();
17
+                $exception->errorMessage=$xml->Message->__toString();
18
+                $exception->resource=$xml->Resource->__toString();
19
+            }
20
+            throw $exception;
21
+        }else{
22
+            return $response;
23
+        }
24
+    }
25 25
 }
26 26
 class ListBucketsHandler implements Handler{
27 27
 
28
-	public function handle(ResponseCore $response){
29
-		$result = array();
30
-		$xml = new SimpleXMLElement($response->body);
31
-		foreach ($xml->Buckets->Bucket as $bucketXml) {
32
-			$bucket = array();
33
-			foreach ($bucketXml->children() as $key => $value) {
34
-				$bucket[$key]=$value->__toString();
35
-			}
36
-			array_push($result, $bucket);
37
-		}
38
-		return $result;
39
-	}
28
+    public function handle(ResponseCore $response){
29
+        $result = array();
30
+        $xml = new SimpleXMLElement($response->body);
31
+        foreach ($xml->Buckets->Bucket as $bucketXml) {
32
+            $bucket = array();
33
+            foreach ($bucketXml->children() as $key => $value) {
34
+                $bucket[$key]=$value->__toString();
35
+            }
36
+            array_push($result, $bucket);
37
+        }
38
+        return $result;
39
+    }
40 40
 }
41 41
 class ListObjectsHandler implements Handler{
42
-	public function handle(ResponseCore $response){
43
-		$result = array();
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();
52
-		$contents = array();
53
-		foreach ($xml->Contents as $contentXml) {
54
-			$content = array();
55
-			foreach ($contentXml->children() as $key => $value) {
56
-				$owner = array();
57
-				if($key === "Owner"){
58
-					foreach ($value->children() as $ownerkey => $ownervalue) {
59
-						$owner[$ownerkey]=$ownervalue->__toString();
60
-					}
61
-					$content["Owner"] = $owner;
62
-				}else{
63
-					$content[$key]=$value->__toString();
64
-				}
65
-			}
66
-			array_push($contents, $content);
67
-		}
68
-		$result["Contents"] = $contents;
42
+    public function handle(ResponseCore $response){
43
+        $result = array();
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();
52
+        $contents = array();
53
+        foreach ($xml->Contents as $contentXml) {
54
+            $content = array();
55
+            foreach ($contentXml->children() as $key => $value) {
56
+                $owner = array();
57
+                if($key === "Owner"){
58
+                    foreach ($value->children() as $ownerkey => $ownervalue) {
59
+                        $owner[$ownerkey]=$ownervalue->__toString();
60
+                    }
61
+                    $content["Owner"] = $owner;
62
+                }else{
63
+                    $content[$key]=$value->__toString();
64
+                }
65
+            }
66
+            array_push($contents, $content);
67
+        }
68
+        $result["Contents"] = $contents;
69 69
 
70
-		$commonprefix = array();
71
-		foreach ($xml->CommonPrefixes as $commonprefixXml) {
72
-			foreach ($commonprefixXml->children() as $key => $value) {
73
-				array_push($commonprefix, $value->__toString());
74
-			}
75
-		}
76
-		$result["CommonPrefixes"] = $commonprefix;
77
-		return $result;
78
-	}
70
+        $commonprefix = array();
71
+        foreach ($xml->CommonPrefixes as $commonprefixXml) {
72
+            foreach ($commonprefixXml->children() as $key => $value) {
73
+                array_push($commonprefix, $value->__toString());
74
+            }
75
+        }
76
+        $result["CommonPrefixes"] = $commonprefix;
77
+        return $result;
78
+    }
79 79
 }
80 80
 class GetBucketCORSHandler implements Handler{
81
-	public function handle(ResponseCore $response){
82
-		$xml = new SimpleXMLElement($response->body);
83
-		$cors = array();
84
-		foreach ($xml->CORSRule as $rule) {
85
-			$acors = array();
86
-			foreach ($rule as $key => $value) {
87
-				if($key === "MaxAgeSeconds")
88
-				{
89
-					$acors[$key] = $value->__toString();
90
-				}else{
91
-					if(!isset($acors[$key])){
92
-						$acors[$key] = array();
93
-					}
94
-					array_push($acors[$key],$value->__toString());
95
-				}
96
-			}
97
-			array_push($cors,$acors);
98
-		}
99
-		return $cors;
100
-	}
81
+    public function handle(ResponseCore $response){
82
+        $xml = new SimpleXMLElement($response->body);
83
+        $cors = array();
84
+        foreach ($xml->CORSRule as $rule) {
85
+            $acors = array();
86
+            foreach ($rule as $key => $value) {
87
+                if($key === "MaxAgeSeconds")
88
+                {
89
+                    $acors[$key] = $value->__toString();
90
+                }else{
91
+                    if(!isset($acors[$key])){
92
+                        $acors[$key] = array();
93
+                    }
94
+                    array_push($acors[$key],$value->__toString());
95
+                }
96
+            }
97
+            array_push($cors,$acors);
98
+        }
99
+        return $cors;
100
+    }
101 101
 }
102 102
 class GetBucketLocationHandler implements Handler{
103
-	public function handle(ResponseCore $response){
104
-		$xml = new SimpleXMLElement($response->body);
105
-		$location = $xml->__toString();
103
+    public function handle(ResponseCore $response){
104
+        $xml = new SimpleXMLElement($response->body);
105
+        $location = $xml->__toString();
106 106
 
107
-		return $location;
108
-	}
107
+        return $location;
108
+    }
109 109
 }
110 110
 class GetBucketLoggingHandler implements Handler{
111
-	public function handle(ResponseCore $response){
112
-		$logging = array();
113
-		$xml = new SimpleXMLElement($response->body);
114
-		$loggingXml = $xml->LoggingEnabled;
115
-		if($loggingXml&&$loggingXml!==NULL)
116
-		{
117
-			foreach ($loggingXml->children() as $key => $value) {
118
-				$logging["Enable"] = TRUE;
119
-				$logging[$key] = $value->__toString();
120
-			}
121
-		}else{
122
-			$logging["Enable"] = FALSE;
123
-		}
124
-		return $logging;
125
-	}
111
+    public function handle(ResponseCore $response){
112
+        $logging = array();
113
+        $xml = new SimpleXMLElement($response->body);
114
+        $loggingXml = $xml->LoggingEnabled;
115
+        if($loggingXml&&$loggingXml!==NULL)
116
+        {
117
+            foreach ($loggingXml->children() as $key => $value) {
118
+                $logging["Enable"] = TRUE;
119
+                $logging[$key] = $value->__toString();
120
+            }
121
+        }else{
122
+            $logging["Enable"] = FALSE;
123
+        }
124
+        return $logging;
125
+    }
126 126
 }
127 127
 class ObjectMetaHandler implements Handler{
128
-	public function handle(ResponseCore $response){
129
-		$ObjectMeta = array();
130
-		$UserMeta = array();
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;
136
-			}
137
-		}
138
-		$Meta = array(
139
-			"ObjectMeta"=>$ObjectMeta,
140
-			"UserMeta"=>$UserMeta
141
-			);
142
-		return $Meta;
143
-	}
128
+    public function handle(ResponseCore $response){
129
+        $ObjectMeta = array();
130
+        $UserMeta = array();
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;
136
+            }
137
+        }
138
+        $Meta = array(
139
+            "ObjectMeta"=>$ObjectMeta,
140
+            "UserMeta"=>$UserMeta
141
+            );
142
+        return $Meta;
143
+    }
144 144
 }
145 145
 class getObjectHandler implements Handler{
146
-	public function handle(ResponseCore $response){
147
-		$ObjectMeta = array();
148
-		$UserMeta = array();
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;
154
-			}
155
-		}
156
-		$Meta = array(
157
-			"ObjectMeta"=>$ObjectMeta,
158
-			"UserMeta"=>$UserMeta
159
-			);
160
-		$ks3Object = array(
161
-			"Content"=>$response->body,
162
-			"Meta"=>$Meta
163
-			);
164
-		return $ks3Object;
165
-	}
146
+    public function handle(ResponseCore $response){
147
+        $ObjectMeta = array();
148
+        $UserMeta = array();
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;
154
+            }
155
+        }
156
+        $Meta = array(
157
+            "ObjectMeta"=>$ObjectMeta,
158
+            "UserMeta"=>$UserMeta
159
+            );
160
+        $ks3Object = array(
161
+            "Content"=>$response->body,
162
+            "Meta"=>$Meta
163
+            );
164
+        return $ks3Object;
165
+    }
166 166
 }
167 167
 class CopyHandler implements Handler{
168
-	public function handle(ResponseCore $response){
169
-		$headers = array();
168
+    public function handle(ResponseCore $response){
169
+        $headers = array();
170 170
 
171
-		foreach ($response->header as $key => $value) {
172
-			if(isset(Consts::$SSEHandler[strtolower($key)])&&!empty($value)){
173
-				$headers[Consts::$SSEHandler[strtolower($key)]]=$value;
174
-			}
175
-		}
171
+        foreach ($response->header as $key => $value) {
172
+            if(isset(Consts::$SSEHandler[strtolower($key)])&&!empty($value)){
173
+                $headers[Consts::$SSEHandler[strtolower($key)]]=$value;
174
+            }
175
+        }
176 176
 
177
-		return $headers;
178
-	}	
177
+        return $headers;
178
+    }	
179 179
 }
180 180
 class InitMultipartUploadHandler implements Handler{
181
-	public function handle(ResponseCore $response){
182
-		$upload = array();
183
-		$xml = new SimpleXMLElement($response->body);
184
-		foreach ($xml->children() as $key => $value) {
185
-			$upload[$key] = $value->__toString();
186
-		}
181
+    public function handle(ResponseCore $response){
182
+        $upload = array();
183
+        $xml = new SimpleXMLElement($response->body);
184
+        foreach ($xml->children() as $key => $value) {
185
+            $upload[$key] = $value->__toString();
186
+        }
187 187
 
188
-		foreach ($response->header as $key => $value) {
189
-			if(isset(Consts::$SSEHandler[strtolower($key)])&&!empty($value)){
190
-				$upload[Consts::$SSEHandler[strtolower($key)]]=$value;
191
-			}
192
-		}
188
+        foreach ($response->header as $key => $value) {
189
+            if(isset(Consts::$SSEHandler[strtolower($key)])&&!empty($value)){
190
+                $upload[Consts::$SSEHandler[strtolower($key)]]=$value;
191
+            }
192
+        }
193 193
 
194
-		return $upload;
195
-	}
194
+        return $upload;
195
+    }
196 196
 }
197 197
 class ListPartsHandler implements Handler{
198
-	public function handle(ResponseCore $response){
199
-		$listParts = array();
200
-		$xml = new SimpleXMLElement($response->body);
198
+    public function handle(ResponseCore $response){
199
+        $listParts = array();
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
-		$initer = array();
212
-		$owner = array();
211
+        $initer = array();
212
+        $owner = array();
213 213
 
214
-		foreach ($xml->Initiator->children() as $key => $value) {
215
-			$initer[$key] = $value->__toString();
216
-		}
217
-		foreach ($xml->Owner->children() as $key => $value) {
218
-			$owner[$key] = $value->__toString();
219
-		}
220
-		$listParts["Owner"] = $owner;
221
-		$listParts["Initiator"]=$initer;
214
+        foreach ($xml->Initiator->children() as $key => $value) {
215
+            $initer[$key] = $value->__toString();
216
+        }
217
+        foreach ($xml->Owner->children() as $key => $value) {
218
+            $owner[$key] = $value->__toString();
219
+        }
220
+        $listParts["Owner"] = $owner;
221
+        $listParts["Initiator"]=$initer;
222 222
 
223
-		$parts = array();
224
-		foreach ($xml->Part as $partxml) {
225
-			$part = array();
226
-			foreach ($partxml->children() as $key => $value) {
227
-				$part[$key] = $value->__toString();
228
-			}
229
-			array_push($parts,$part);
230
-		}
231
-		$listParts["Parts"] = $parts;
232
-		return $listParts;
233
-	}
223
+        $parts = array();
224
+        foreach ($xml->Part as $partxml) {
225
+            $part = array();
226
+            foreach ($partxml->children() as $key => $value) {
227
+                $part[$key] = $value->__toString();
228
+            }
229
+            array_push($parts,$part);
230
+        }
231
+        $listParts["Parts"] = $parts;
232
+        return $listParts;
233
+    }
234 234
 }
235 235
 class UploadHandler implements Handler{
236
-	public function handle(ResponseCore $response){
237
-		$Headers = array();
238
-		foreach ($response->header as $key => $value) {
239
-			if(isset(Consts::$UploadHandler[strtolower($key)])&&!empty($value)){
240
-				$Headers[Consts::$UploadHandler[strtolower($key)]]=$value;
241
-			}
242
-		}
243
-		return $Headers;
244
-	}
236
+    public function handle(ResponseCore $response){
237
+        $Headers = array();
238
+        foreach ($response->header as $key => $value) {
239
+            if(isset(Consts::$UploadHandler[strtolower($key)])&&!empty($value)){
240
+                $Headers[Consts::$UploadHandler[strtolower($key)]]=$value;
241
+            }
242
+        }
243
+        return $Headers;
244
+    }
245 245
 }
246 246
 class GetAclHandler implements Handler{
247
-	public function handle(ResponseCore $response){
248
-		$hasread = FALSE;
249
-		$haswrite = FALSE;
250
-		$xml = new SimpleXMLElement($response->body);
251
-		$acl = $xml->AccessControlList;
252
-		foreach ($acl->children() as $grant) {
253
-			$permission = $grant->Permission->__toString();
254
-			$hasURI = FALSE;
255
-			$grantee = $grant->Grantee;
256
-			foreach ($grantee->children() as $key => $value) {
257
-				if($key === "URI"&&$value->__toString() === Consts::$Grantee_Group_All){
258
-					$hasURI = TRUE;
259
-				}
260
-			}
261
-			if($hasURI){
262
-				if($permission===Consts::$Permission_Read){
263
-					$hasread = TRUE;
264
-				}elseif($permission===Consts::$Permission_Write){
265
-					$haswrite = TRUE;
266
-				}
267
-			}
268
-		}
269
-		if($hasread&&$haswrite){
270
-			return "public-read-write";
271
-		}else{
272
-			if($hasread)
273
-				return "public-read";
274
-			else
275
-				return "private";
276
-		}
277
-	}
247
+    public function handle(ResponseCore $response){
248
+        $hasread = FALSE;
249
+        $haswrite = FALSE;
250
+        $xml = new SimpleXMLElement($response->body);
251
+        $acl = $xml->AccessControlList;
252
+        foreach ($acl->children() as $grant) {
253
+            $permission = $grant->Permission->__toString();
254
+            $hasURI = FALSE;
255
+            $grantee = $grant->Grantee;
256
+            foreach ($grantee->children() as $key => $value) {
257
+                if($key === "URI"&&$value->__toString() === Consts::$Grantee_Group_All){
258
+                    $hasURI = TRUE;
259
+                }
260
+            }
261
+            if($hasURI){
262
+                if($permission===Consts::$Permission_Read){
263
+                    $hasread = TRUE;
264
+                }elseif($permission===Consts::$Permission_Write){
265
+                    $haswrite = TRUE;
266
+                }
267
+            }
268
+        }
269
+        if($hasread&&$haswrite){
270
+            return "public-read-write";
271
+        }else{
272
+            if($hasread)
273
+                return "public-read";
274
+            else
275
+                return "private";
276
+        }
277
+    }
278 278
 }
279 279
 class ListMutipartUploadsHandler implements Handler{
280
-	public function handle(ResponseCore $response){
281
-		$mutiUploads = array();
282
-		$xml = new SimpleXMLElement($response->body);
280
+    public function handle(ResponseCore $response){
281
+        $mutiUploads = array();
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
-		$uploads = array();
294
-		foreach ($xml->Upload as $uploadxml) {
295
-			$upload = array();
296
-			foreach ($uploadxml->children() as $key => $value) {
297
-				if($key === "Initiator"){
298
-					$initer = array();
299
-					foreach ($value->children() as $key1 => $value1) {
300
-						$initer[$key1] = $value1->__toString();
301
-					}
302
-					$upload["Initiator"] = $initer;
303
-				}elseif($key === "Owner"){
304
-					$owner = array();
305
-					foreach ($value->children() as $key1 => $value1) {
306
-						$owner[$key1] = $value1->__toString();
307
-					}
308
-					$upload["Owner"] = $owner;
309
-				}else{
310
-					$upload[$key] = $value->__toString();
311
-				}
312
-			}
313
-			array_push($uploads,$upload);
314
-		}
315
-		$mutiUploads["Uploads"] = $uploads;
316
-		return $mutiUploads;
317
-	}
293
+        $uploads = array();
294
+        foreach ($xml->Upload as $uploadxml) {
295
+            $upload = array();
296
+            foreach ($uploadxml->children() as $key => $value) {
297
+                if($key === "Initiator"){
298
+                    $initer = array();
299
+                    foreach ($value->children() as $key1 => $value1) {
300
+                        $initer[$key1] = $value1->__toString();
301
+                    }
302
+                    $upload["Initiator"] = $initer;
303
+                }elseif($key === "Owner"){
304
+                    $owner = array();
305
+                    foreach ($value->children() as $key1 => $value1) {
306
+                        $owner[$key1] = $value1->__toString();
307
+                    }
308
+                    $upload["Owner"] = $owner;
309
+                }else{
310
+                    $upload[$key] = $value->__toString();
311
+                }
312
+            }
313
+            array_push($uploads,$upload);
314
+        }
315
+        $mutiUploads["Uploads"] = $uploads;
316
+        return $mutiUploads;
317
+    }
318 318
 }
319 319
 class AdpHandler implements Handler{
320
-	public function handle(ResponseCore $response){
321
-		return $response->body;
322
-	}
320
+    public function handle(ResponseCore $response){
321
+        return $response->body;
322
+    }
323 323
 }
324 324
 class BooleanHandler implements Handler{
325
-	public function handle(ResponseCore $response){
326
-		if($response->isOk()){
327
-			return TRUE;
328
-		}else{
329
-			return FALSE;
330
-		}
331
-	}
325
+    public function handle(ResponseCore $response){
326
+        if($response->isOk()){
327
+            return TRUE;
328
+        }else{
329
+            return FALSE;
330
+        }
331
+    }
332 332
 }
333 333
 class ExistsHandler implements Handler{
334
-	public function handle(ResponseCore $response){
335
-		$status = $response->status;
336
-		if($status === 404){
337
-			return FALSE;
338
-		}else{
339
-			return TRUE;
340
-		}
341
-	}
334
+    public function handle(ResponseCore $response){
335
+        $status = $response->status;
336
+        if($status === 404){
337
+            return FALSE;
338
+        }else{
339
+            return TRUE;
340
+        }
341
+    }
342 342
 }
343 343
 ?>
344 344
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +106 added lines, -106 removed lines patch added patch discarded remove patch
@@ -1,66 +1,66 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 	}
Please login to merge, or discard this patch.
Braces   +17 added lines, -16 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
 				$exception->resource=$xml->Resource->__toString();
19 19
 			}
20 20
 			throw $exception;
21
-		}else{
21
+		} else{
22 22
 			return $response;
23 23
 		}
24 24
 	}
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 						$owner[$ownerkey]=$ownervalue->__toString();
60 60
 					}
61 61
 					$content["Owner"] = $owner;
62
-				}else{
62
+				} else{
63 63
 					$content[$key]=$value->__toString();
64 64
 				}
65 65
 			}
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 				if($key === "MaxAgeSeconds")
88 88
 				{
89 89
 					$acors[$key] = $value->__toString();
90
-				}else{
90
+				} else{
91 91
 					if(!isset($acors[$key])){
92 92
 						$acors[$key] = array();
93 93
 					}
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
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;
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
 		foreach ($response->header as $key => $value) {
132 132
 			if (substr(strtolower($key), 0, 10) === Consts::$UserMetaPrefix){
133 133
 				$UserMeta[$key]=$value;
134
-			}else if(isset(Consts::$ResponseObjectMeta[strtolower($key)])){
134
+			} else if(isset(Consts::$ResponseObjectMeta[strtolower($key)])){
135 135
 				$ObjectMeta[Consts::$ResponseObjectMeta[strtolower($key)]]=$value;
136 136
 			}
137 137
 		}
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
 		foreach ($response->header as $key => $value) {
150 150
 			if (substr(strtolower($key), 0, 10) === Consts::$UserMetaPrefix){
151 151
 				$UserMeta[$key]=$value;
152
-			}else if(isset(Consts::$ResponseObjectMeta[strtolower($key)])){
152
+			} else if(isset(Consts::$ResponseObjectMeta[strtolower($key)])){
153 153
 				$ObjectMeta[Consts::$ResponseObjectMeta[strtolower($key)]]=$value;
154 154
 			}
155 155
 		}
@@ -261,18 +261,19 @@  discard block
 block discarded – undo
261 261
 			if($hasURI){
262 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 269
 		if($hasread&&$haswrite){
270 270
 			return "public-read-write";
271
-		}else{
272
-			if($hasread)
273
-				return "public-read";
274
-			else
275
-				return "private";
271
+		} else{
272
+			if($hasread) {
273
+							return "public-read";
274
+			} else {
275
+							return "private";
276
+			}
276 277
 		}
277 278
 	}
278 279
 }
@@ -300,13 +301,13 @@  discard block
 block discarded – undo
300 301
 						$initer[$key1] = $value1->__toString();
301 302
 					}
302 303
 					$upload["Initiator"] = $initer;
303
-				}elseif($key === "Owner"){
304
+				} elseif($key === "Owner"){
304 305
 					$owner = array();
305 306
 					foreach ($value->children() as $key1 => $value1) {
306 307
 						$owner[$key1] = $value1->__toString();
307 308
 					}
308 309
 					$upload["Owner"] = $owner;
309
-				}else{
310
+				} else{
310 311
 					$upload[$key] = $value->__toString();
311 312
 				}
312 313
 			}
@@ -325,7 +326,7 @@  discard block
 block discarded – undo
325 326
 	public function handle(ResponseCore $response){
326 327
 		if($response->isOk()){
327 328
 			return TRUE;
328
-		}else{
329
+		} else{
329 330
 			return FALSE;
330 331
 		}
331 332
 	}
@@ -335,7 +336,7 @@  discard block
 block discarded – undo
335 336
 		$status = $response->status;
336 337
 		if($status === 404){
337 338
 			return FALSE;
338
-		}else{
339
+		} else{
339 340
 			return TRUE;
340 341
 		}
341 342
 	}
Please login to merge, or discard this patch.
src/service/ksyun/bin/lib/RequestCore.class.php 3 patches
Indentation   +999 added lines, -999 removed lines patch added patch discarded remove patch
@@ -13,958 +13,958 @@  discard block
 block discarded – undo
13 13
  */
14 14
 class RequestCore
15 15
 {
16
-	/**
17
-	 * The URL being requested.
18
-	 */
19
-	public $request_url;
20
-
21
-	/**
22
-	 * The headers being sent in the request.
23
-	 */
24
-	public $request_headers;
25
-
26
-	/**
27
-	 * The body being sent in the request.
28
-	 */
29
-	public $request_body;
30
-
31
-	/**
32
-	 * The response returned by the request.
33
-	 */
34
-	public $response;
35
-
36
-	/**
37
-	 * The headers returned by the request.
38
-	 */
39
-	public $response_headers;
40
-
41
-	/**
42
-	 * The body returned by the request.
43
-	 */
44
-	public $response_body;
45
-
46
-	/**
47
-	 * The HTTP status code returned by the request.
48
-	 */
49
-	public $response_code;
50
-
51
-	/**
52
-	 * Additional response data.
53
-	 */
54
-	public $response_info;
55
-
56
-	/**
57
-	 * The handle for the cURL object.
58
-	 */
59
-	public $curl_handle;
60
-
61
-	/**
62
-	 * The method by which the request is being made.
63
-	 */
64
-	public $method;
65
-
66
-	/**
67
-	 * Stores the proxy settings to use for the request.
68
-	 */
69
-	public $proxy = null;
70
-
71
-	/**
72
-	 * The username to use for the request.
73
-	 */
74
-	public $username = null;
75
-
76
-	/**
77
-	 * The password to use for the request.
78
-	 */
79
-	public $password = null;
80
-
81
-	/**
82
-	 * Custom CURLOPT settings.
83
-	 */
84
-	public $curlopts = null;
85
-
86
-	/**
87
-	 * The state of debug mode.
88
-	 */
89
-	public $debug_mode = false;
90
-
91
-	/**
92
-	 * The default class to use for HTTP Requests (defaults to <RequestCore>).
93
-	 */
94
-	public $request_class = 'RequestCore';
95
-
96
-	/**
97
-	 * The default class to use for HTTP Responses (defaults to <ResponseCore>).
98
-	 */
99
-	public $response_class = 'ResponseCore';
100
-
101
-	/**
102
-	 * Default useragent string to use.
103
-	 */
104
-	public $useragent = 'RequestCore/1.4.3';
105
-
106
-	/**
107
-	 * File to read from while streaming up.
108
-	 */
109
-	public $read_file = null;
110
-
111
-	/**
112
-	 * The resource to read from while streaming up.
113
-	 */
114
-	public $read_stream = null;
115
-
116
-	/**
117
-	 * The size of the stream to read from.
118
-	 */
119
-	public $read_stream_size = null;
120
-
121
-	/**
122
-	 * The length already read from the stream.
123
-	 */
124
-	public $read_stream_read = 0;
125
-
126
-	/**
127
-	 * File to write to while streaming down.
128
-	 */
129
-	public $write_file = null;
130
-
131
-	/**
132
-	 * The resource to write to while streaming down.
133
-	 */
134
-	public $write_stream = null;
135
-
136
-	/**
137
-	 * Stores the intended starting seek position.
138
-	 */
139
-	public $seek_position = null;
140
-
141
-	/**
142
-	 * The location of the cacert.pem file to use.
143
-	 */
144
-	public $cacert_location = false;
145
-
146
-	/**
147
-	 * The state of SSL certificate verification.
148
-	 */
149
-	public $ssl_verification = true;
150
-
151
-	/**
152
-	 * The user-defined callback function to call when a stream is read from.
153
-	 */
154
-	public $registered_streaming_read_callback = null;
155
-
156
-	/**
157
-	 * The user-defined callback function to call when a stream is written to.
158
-	 */
159
-	public $registered_streaming_write_callback = null;
160
-
161
-	/*%******************************************************************************************%*/
162
-	// CONSTANTS
163
-
164
-	/**
165
-	 * GET HTTP Method
166
-	 */
167
-	const HTTP_GET = 'GET';
168
-
169
-	/**
170
-	 * POST HTTP Method
171
-	 */
172
-	const HTTP_POST = 'POST';
173
-
174
-	/**
175
-	 * PUT HTTP Method
176
-	 */
177
-	const HTTP_PUT = 'PUT';
178
-
179
-	/**
180
-	 * DELETE HTTP Method
181
-	 */
182
-	const HTTP_DELETE = 'DELETE';
183
-
184
-	/**
185
-	 * HEAD HTTP Method
186
-	 */
187
-	const HTTP_HEAD = 'HEAD';
188
-
189
-
190
-	/*%******************************************************************************************%*/
191
-	// CONSTRUCTOR/DESTRUCTOR
192
-
193
-	/**
194
-	 * Constructs a new instance of this class.
195
-	 *
196
-	 * @param string $url (Optional) The URL to request or service endpoint to query.
197
-	 * @param string $proxy (Optional) The faux-url to use for proxy settings. Takes the following format: `proxy://user:pass@hostname:port`
198
-	 * @param array $helpers (Optional) An associative array of classnames to use for request, and response functionality. Gets passed in automatically by the calling class.
199
-	 * @return $this A reference to the current instance.
200
-	 */
201
-	public function __construct($url = null, $proxy = null, $helpers = null)
202
-	{
203
-		// Set some default values.
204
-		$this->request_url = $url;
205
-		$this->method = self::HTTP_GET;
206
-		$this->request_headers = array();
207
-		$this->request_body = '';
208
-
209
-		// Set a new Request class if one was set.
210
-		if (isset($helpers['request']) && !empty($helpers['request']))
211
-		{
212
-			$this->request_class = $helpers['request'];
213
-		}
214
-
215
-		// Set a new Request class if one was set.
216
-		if (isset($helpers['response']) && !empty($helpers['response']))
217
-		{
218
-			$this->response_class = $helpers['response'];
219
-		}
220
-
221
-		if ($proxy)
222
-		{
223
-			$this->set_proxy($proxy);
224
-		}
225
-
226
-		return $this;
227
-	}
228
-
229
-	/**
230
-	 * Destructs the instance. Closes opened file handles.
231
-	 *
232
-	 * @return $this A reference to the current instance.
233
-	 */
234
-	public function __destruct()
235
-	{
236
-		if (isset($this->read_file) && isset($this->read_stream))
237
-		{
238
-			fclose($this->read_stream);
239
-		}
240
-
241
-		if (isset($this->write_file) && isset($this->write_stream))
242
-		{
243
-			fclose($this->write_stream);
244
-		}
245
-
246
-		return $this;
247
-	}
248
-
249
-
250
-	/*%******************************************************************************************%*/
251
-	// REQUEST METHODS
252
-
253
-	/**
254
-	 * Sets the credentials to use for authentication.
255
-	 *
256
-	 * @param string $user (Required) The username to authenticate with.
257
-	 * @param string $pass (Required) The password to authenticate with.
258
-	 * @return $this A reference to the current instance.
259
-	 */
260
-	public function set_credentials($user, $pass)
261
-	{
262
-		$this->username = $user;
263
-		$this->password = $pass;
264
-		return $this;
265
-	}
266
-
267
-	/**
268
-	 * Adds a custom HTTP header to the cURL request.
269
-	 *
270
-	 * @param string $key (Required) The custom HTTP header to set.
271
-	 * @param mixed $value (Required) The value to assign to the custom HTTP header.
272
-	 * @return $this A reference to the current instance.
273
-	 */
274
-	public function add_header($key, $value)
275
-	{
276
-		$this->request_headers[$key] = $value;
277
-		return $this;
278
-	}
279
-
280
-	/**
281
-	 * Removes an HTTP header from the cURL request.
282
-	 *
283
-	 * @param string $key (Required) The custom HTTP header to set.
284
-	 * @return $this A reference to the current instance.
285
-	 */
286
-	public function remove_header($key)
287
-	{
288
-		if (isset($this->request_headers[$key]))
289
-		{
290
-			unset($this->request_headers[$key]);
291
-		}
292
-		return $this;
293
-	}
294
-
295
-	/**
296
-	 * Set the method type for the request.
297
-	 *
298
-	 * @param string $method (Required) One of the following constants: <HTTP_GET>, <HTTP_POST>, <HTTP_PUT>, <HTTP_HEAD>, <HTTP_DELETE>.
299
-	 * @return $this A reference to the current instance.
300
-	 */
301
-	public function set_method($method)
302
-	{
303
-		$this->method = strtoupper($method);
304
-		return $this;
305
-	}
306
-
307
-	/**
308
-	 * Sets a custom useragent string for the class.
309
-	 *
310
-	 * @param string $ua (Required) The useragent string to use.
311
-	 * @return $this A reference to the current instance.
312
-	 */
313
-	public function set_useragent($ua)
314
-	{
315
-		$this->useragent = $ua;
316
-		return $this;
317
-	}
318
-
319
-	/**
320
-	 * Set the body to send in the request.
321
-	 *
322
-	 * @param string $body (Required) The textual content to send along in the body of the request.
323
-	 * @return $this A reference to the current instance.
324
-	 */
325
-	public function set_body($body)
326
-	{
327
-		$this->request_body = $body;
328
-		return $this;
329
-	}
330
-
331
-	/**
332
-	 * Set the URL to make the request to.
333
-	 *
334
-	 * @param string $url (Required) The URL to make the request to.
335
-	 * @return $this A reference to the current instance.
336
-	 */
337
-	public function set_request_url($url)
338
-	{
339
-		$this->request_url = $url;
340
-		return $this;
341
-	}
342
-
343
-	/**
344
-	 * Set additional CURLOPT settings. These will merge with the default settings, and override if
345
-	 * there is a duplicate.
346
-	 *
347
-	 * @param array $curlopts (Optional) A set of key-value pairs that set `CURLOPT` options. These will merge with the existing CURLOPTs, and ones passed here will override the defaults. Keys should be the `CURLOPT_*` constants, not strings.
348
-	 * @return $this A reference to the current instance.
349
-	 */
350
-	public function set_curlopts($curlopts)
351
-	{
352
-		$this->curlopts = $curlopts;
353
-		return $this;
354
-	}
355
-
356
-	/**
357
-	 * Sets the length in bytes to read from the stream while streaming up.
358
-	 *
359
-	 * @param integer $size (Required) The length in bytes to read from the stream.
360
-	 * @return $this A reference to the current instance.
361
-	 */
362
-	public function set_read_stream_size($size)
363
-	{
364
-		$this->read_stream_size = $size;
365
-
366
-		return $this;
367
-	}
368
-
369
-	/**
370
-	 * Sets the resource to read from while streaming up. Reads the stream from its current position until
371
-	 * EOF or `$size` bytes have been read. If `$size` is not given it will be determined by <php:fstat()> and
372
-	 * <php:ftell()>.
373
-	 *
374
-	 * @param resource $resource (Required) The readable resource to read from.
375
-	 * @param integer $size (Optional) The size of the stream to read.
376
-	 * @return $this A reference to the current instance.
377
-	 */
378
-	public function set_read_stream($resource, $size = null)
379
-	{
380
-		if (!isset($size) || $size < 0)
381
-		{
382
-			$stats = fstat($resource);
383
-
384
-			if ($stats && $stats['size'] >= 0)
385
-			{
386
-				$position = ftell($resource);
387
-
388
-				if ($position !== false && $position >= 0)
389
-				{
390
-					$size = $stats['size'] - $position;
391
-				}
392
-			}
393
-		}
394
-
395
-		$this->read_stream = $resource;
396
-
397
-		return $this->set_read_stream_size($size);
398
-	}
399
-
400
-	/**
401
-	 * Sets the file to read from while streaming up.
402
-	 *
403
-	 * @param string $location (Required) The readable location to read from.
404
-	 * @return $this A reference to the current instance.
405
-	 */
406
-	public function set_read_file($location)
407
-	{
408
-		$this->read_file = $location;
409
-		$read_file_handle = fopen($location, 'r');
410
-
411
-		return $this->set_read_stream($read_file_handle);
412
-	}
413
-
414
-	/**
415
-	 * Sets the resource to write to while streaming down.
416
-	 *
417
-	 * @param resource $resource (Required) The writeable resource to write to.
418
-	 * @return $this A reference to the current instance.
419
-	 */
420
-	public function set_write_stream($resource)
421
-	{
422
-		$this->write_stream = $resource;
423
-
424
-		return $this;
425
-	}
426
-
427
-	/**
428
-	 * Sets the file to write to while streaming down.
429
-	 *
430
-	 * @param string $location (Required) The writeable location to write to.
431
-	 * @return $this A reference to the current instance.
432
-	 */
433
-	public function set_write_file($location)
434
-	{
435
-		$this->write_file = $location;
436
-		$write_file_handle = fopen($location, 'w');
437
-
438
-		return $this->set_write_stream($write_file_handle);
439
-	}
440
-
441
-	/**
442
-	 * Set the proxy to use for making requests.
443
-	 *
444
-	 * @param string $proxy (Required) The faux-url to use for proxy settings. Takes the following format: `proxy://user:pass@hostname:port`
445
-	 * @return $this A reference to the current instance.
446
-	 */
447
-	public function set_proxy($proxy)
448
-	{
449
-		$proxy = parse_url($proxy);
450
-		$proxy['user'] = isset($proxy['user']) ? $proxy['user'] : null;
451
-		$proxy['pass'] = isset($proxy['pass']) ? $proxy['pass'] : null;
452
-		$proxy['port'] = isset($proxy['port']) ? $proxy['port'] : null;
453
-		$this->proxy = $proxy;
454
-		return $this;
455
-	}
456
-
457
-	/**
458
-	 * Set the intended starting seek position.
459
-	 *
460
-	 * @param integer $position (Required) The byte-position of the stream to begin reading from.
461
-	 * @return $this A reference to the current instance.
462
-	 */
463
-	public function set_seek_position($position)
464
-	{
465
-		$this->seek_position = isset($position) ? (integer) $position : null;
466
-
467
-		return $this;
468
-	}
469
-
470
-	/**
471
-	 * Register a callback function to execute whenever a data stream is read from using
472
-	 * <CFRequest::streaming_read_callback()>.
473
-	 *
474
-	 * The user-defined callback function should accept three arguments:
475
-	 *
476
-	 * <ul>
477
-	 * 	<li><code>$curl_handle</code> - <code>resource</code> - Required - The cURL handle resource that represents the in-progress transfer.</li>
478
-	 * 	<li><code>$file_handle</code> - <code>resource</code> - Required - The file handle resource that represents the file on the local file system.</li>
479
-	 * 	<li><code>$length</code> - <code>integer</code> - Required - The length in kilobytes of the data chunk that was transferred.</li>
480
-	 * </ul>
481
-	 *
482
-	 * @param string|array|function $callback (Required) The callback function is called by <php:call_user_func()>, so you can pass the following values: <ul>
483
-	 * 	<li>The name of a global function to execute, passed as a string.</li>
484
-	 * 	<li>A method to execute, passed as <code>array('ClassName', 'MethodName')</code>.</li>
485
-	 * 	<li>An anonymous function (PHP 5.3+).</li></ul>
486
-	 * @return $this A reference to the current instance.
487
-	 */
488
-	public function register_streaming_read_callback($callback)
489
-	{
490
-		$this->registered_streaming_read_callback = $callback;
491
-
492
-		return $this;
493
-	}
494
-
495
-	/**
496
-	 * Register a callback function to execute whenever a data stream is written to using
497
-	 * <CFRequest::streaming_write_callback()>.
498
-	 *
499
-	 * The user-defined callback function should accept two arguments:
500
-	 *
501
-	 * <ul>
502
-	 * 	<li><code>$curl_handle</code> - <code>resource</code> - Required - The cURL handle resource that represents the in-progress transfer.</li>
503
-	 * 	<li><code>$length</code> - <code>integer</code> - Required - The length in kilobytes of the data chunk that was transferred.</li>
504
-	 * </ul>
505
-	 *
506
-	 * @param string|array|function $callback (Required) The callback function is called by <php:call_user_func()>, so you can pass the following values: <ul>
507
-	 * 	<li>The name of a global function to execute, passed as a string.</li>
508
-	 * 	<li>A method to execute, passed as <code>array('ClassName', 'MethodName')</code>.</li>
509
-	 * 	<li>An anonymous function (PHP 5.3+).</li></ul>
510
-	 * @return $this A reference to the current instance.
511
-	 */
512
-	public function register_streaming_write_callback($callback)
513
-	{
514
-		$this->registered_streaming_write_callback = $callback;
515
-
516
-		return $this;
517
-	}
518
-
519
-
520
-	/*%******************************************************************************************%*/
521
-	// PREPARE, SEND, AND PROCESS REQUEST
522
-
523
-	/**
524
-	 * A callback function that is invoked by cURL for streaming up.
525
-	 *
526
-	 * @param resource $curl_handle (Required) The cURL handle for the request.
527
-	 * @param resource $file_handle (Required) The open file handle resource.
528
-	 * @param integer $length (Required) The maximum number of bytes to read.
529
-	 * @return binary Binary data from a stream.
530
-	 */
531
-	public function streaming_read_callback($curl_handle, $file_handle, $length)
532
-	{
533
-		// Execute callback function
534
-		if ($this->registered_streaming_read_callback)
535
-		{
536
-			return $this->registered_streaming_read_callback->streaming_read_callback($curl_handle, $file_handle, $length,$this->read_stream,$this->seek_position);
537
-		}
538
-		// Once we've sent as much as we're supposed to send...
539
-		if ($this->read_stream_read >= $this->read_stream_size)
540
-		{
541
-			// Send EOF
542
-			return '';
543
-		}
544
-
545
-		// If we're at the beginning of an upload and need to seek...
546
-		if ($this->read_stream_read == 0 && isset($this->seek_position) && $this->seek_position !== ftell($this->read_stream))
547
-		{
548
-			if (fseek($this->read_stream, $this->seek_position) !== 0)
549
-			{
550
-				throw new RequestCore_Exception('The stream does not support seeking and is either not at the requested position or the position is unknown.');
551
-			}
552
-		}
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
555
-		$this->read_stream_read += strlen($read);
556
-
557
-		$out = $read === false ? '' : $read;
558
-
559
-		return $out;
560
-	}
561
-
562
-	/**
563
-	 * A callback function that is invoked by cURL for streaming down.
564
-	 *
565
-	 * @param resource $curl_handle (Required) The cURL handle for the request.
566
-	 * @param binary $data (Required) The data to write.
567
-	 * @return integer The number of bytes written.
568
-	 */
569
-	public function streaming_write_callback($curl_handle, $data)
570
-	{
571
-		if ($this->registered_streaming_write_callback){
572
-			return $this->registered_streaming_write_callback->streaming_write_callback($curl_handle,$data,$this->write_stream);
573
-		}
574
-		$length = strlen($data);
575
-		$written_total = 0;
576
-		$written_last = 0;
577
-
578
-		while ($written_total < $length)
579
-		{
580
-			$written_last = fwrite($this->write_stream, substr($data, $written_total));
581
-
582
-			if ($written_last === false)
583
-			{
584
-				return $written_total;
585
-			}
586
-
587
-			$written_total += $written_last;
588
-		}
589
-
590
-		return $written_total;
591
-	}
592
-
593
-	/**
594
-	 * Prepares and adds the details of the cURL request. This can be passed along to a <php:curl_multi_exec()>
595
-	 * function.
596
-	 *
597
-	 * @return resource The handle for the cURL object.
598
-	 */
599
-	public function prep_request()
600
-	{
601
-		$curl_handle = curl_init();
602
-
603
-		// Set default options.
604
-		curl_setopt($curl_handle, CURLOPT_URL, $this->request_url);
605
-		curl_setopt($curl_handle, CURLOPT_FILETIME, true);
606
-		curl_setopt($curl_handle, CURLOPT_FRESH_CONNECT, false);
607
-		//为了兼容PHP 5.6,PHP 5.6把 CURLOPT_CLOSEPOLICY 这个变量删除了
608
-		//curl_setopt($curl_handle, CURLOPT_CLOSEPOLICY, CURLCLOSEPOLICY_LEAST_RECENTLY_USED);
609
-		curl_setopt($curl_handle, CURLOPT_MAXREDIRS, 5);
610
-		curl_setopt($curl_handle, CURLOPT_HEADER, true);
611
-		curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true);
612
-		curl_setopt($curl_handle, CURLOPT_TIMEOUT, 5184000);
613
-		curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 120);
614
-		curl_setopt($curl_handle, CURLOPT_NOSIGNAL, true);
615
-		curl_setopt($curl_handle, CURLOPT_REFERER, $this->request_url);
616
-		curl_setopt($curl_handle, CURLOPT_USERAGENT, $this->useragent);
617
-		curl_setopt($curl_handle, CURLOPT_READFUNCTION, array($this, 'streaming_read_callback'));
618
-
619
-		// Verification of the SSL cert
620
-		if ($this->ssl_verification)
621
-		{
622
-			curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, true);
623
-			curl_setopt($curl_handle, CURLOPT_SSL_VERIFYHOST, 2);
624
-		}
625
-		else
626
-		{
627
-			curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, false);
628
-			curl_setopt($curl_handle, CURLOPT_SSL_VERIFYHOST, false);
629
-		}
630
-
631
-		// chmod the file as 0755
632
-		if ($this->cacert_location === true)
633
-		{
634
-			curl_setopt($curl_handle, CURLOPT_CAINFO, dirname(__FILE__) . '/cacert.pem');
635
-		}
636
-		elseif (is_string($this->cacert_location))
637
-		{
638
-			curl_setopt($curl_handle, CURLOPT_CAINFO, $this->cacert_location);
639
-		}
640
-
641
-		// Debug mode
642
-		if ($this->debug_mode)
643
-		{
644
-			curl_setopt($curl_handle, CURLOPT_VERBOSE, true);
645
-		}
646
-
647
-		// Handle open_basedir & safe mode
648
-		if (!ini_get('safe_mode') && !ini_get('open_basedir'))
649
-		{
650
-			curl_setopt($curl_handle, CURLOPT_FOLLOWLOCATION, FALSE);
651
-		}
652
-
653
-		// Enable a proxy connection if requested.
654
-		if ($this->proxy)
655
-		{
656
-			curl_setopt($curl_handle, CURLOPT_HTTPPROXYTUNNEL, true);
657
-
658
-			$host = $this->proxy['host'];
659
-			$host .= ($this->proxy['port']) ? ':' . $this->proxy['port'] : '';
660
-			curl_setopt($curl_handle, CURLOPT_PROXY, $host);
661
-
662
-			if (isset($this->proxy['user']) && isset($this->proxy['pass']))
663
-			{
664
-				curl_setopt($curl_handle, CURLOPT_PROXYUSERPWD, $this->proxy['user'] . ':' . $this->proxy['pass']);
665
-			}
666
-		}
667
-
668
-		// Set credentials for HTTP Basic/Digest Authentication.
669
-		if ($this->username && $this->password)
670
-		{
671
-			curl_setopt($curl_handle, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
672
-			curl_setopt($curl_handle, CURLOPT_USERPWD, $this->username . ':' . $this->password);
673
-		}
674
-
675
-		// Handle the encoding if we can.
676
-		if (extension_loaded('zlib'))
677
-		{
678
-			curl_setopt($curl_handle, CURLOPT_ENCODING, '');
679
-		}
680
-
681
-		// Process custom headers
682
-		if (isset($this->request_headers) && count($this->request_headers))
683
-		{
684
-			$temp_headers = array();
685
-
686
-			foreach ($this->request_headers as $k => $v)
687
-			{
688
-				$temp_headers[] = $k . ': ' . $v;
689
-			}
690
-
691
-			curl_setopt($curl_handle, CURLOPT_HTTPHEADER, $temp_headers);
692
-		}
693
-
694
-		switch ($this->method)
695
-		{
696
-			case self::HTTP_PUT:
697
-				//unset($this->read_stream);
698
-				curl_setopt($curl_handle, CURLOPT_CUSTOMREQUEST, 'PUT');
699
-				if (isset($this->read_stream))
700
-				{
701
-					if (!isset($this->read_stream_size) || $this->read_stream_size < 0)
702
-					{
703
-						throw new RequestCore_Exception('The stream size for the streaming upload cannot be determined.');
704
-					}
705
-
706
-					curl_setopt($curl_handle, CURLOPT_INFILESIZE, $this->read_stream_size);
707
-					curl_setopt($curl_handle, CURLOPT_UPLOAD, true);
708
-				}
709
-				else
710
-				{
711
-					curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $this->request_body);
712
-				}
713
-				break;
714
-
715
-			case self::HTTP_POST:
716
-				curl_setopt($curl_handle, CURLOPT_POST, true);
717
-				curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $this->request_body);
718
-				break;
719
-
720
-			case self::HTTP_HEAD:
721
-				curl_setopt($curl_handle, CURLOPT_CUSTOMREQUEST, self::HTTP_HEAD);
722
-				curl_setopt($curl_handle, CURLOPT_NOBODY, 1);
723
-				break;
724
-
725
-			default: // Assumed GET
726
-				curl_setopt($curl_handle, CURLOPT_CUSTOMREQUEST, $this->method);
727
-				if (isset($this->write_stream))
728
-				{
729
-					curl_setopt($curl_handle, CURLOPT_WRITEFUNCTION, array($this, 'streaming_write_callback'));
730
-					curl_setopt($curl_handle, CURLOPT_HEADER, false);
731
-				}
732
-				else
733
-				{
734
-					curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $this->request_body);
735
-				}
736
-				break;
737
-		}
738
-
739
-		// Merge in the CURLOPTs
740
-		if (isset($this->curlopts) && sizeof($this->curlopts) > 0)
741
-		{
742
-			foreach ($this->curlopts as $k => $v)
743
-			{
744
-				curl_setopt($curl_handle, $k, $v);
745
-			}
746
-		}
747
-
748
-		return $curl_handle;
749
-	}
750
-
751
-	/**
752
-	 * Take the post-processed cURL data and break it down into useful header/body/info chunks. Uses the
753
-	 * data stored in the `curl_handle` and `response` properties unless replacement data is passed in via
754
-	 * parameters.
755
-	 *
756
-	 * @param resource $curl_handle (Optional) The reference to the already executed cURL request.
757
-	 * @param string $response (Optional) The actual response content itself that needs to be parsed.
758
-	 * @return ResponseCore A <ResponseCore> object containing a parsed HTTP response.
759
-	 */
760
-	public function process_response($curl_handle = null, $response = null)
761
-	{
762
-		// Accept a custom one if it's passed.
763
-		if ($curl_handle && $response)
764
-		{
765
-			$this->curl_handle = $curl_handle;
766
-			$this->response = $response;
767
-		}
768
-
769
-		// As long as this came back as a valid resource...
770
-		if (is_resource($this->curl_handle))
771
-		{
772
-			// Determine what's what.
773
-			$header_size = curl_getinfo($this->curl_handle, CURLINFO_HEADER_SIZE);
774
-			$this->response_headers = substr($this->response, 0, $header_size);
775
-			$this->response_body = substr($this->response, $header_size);
776
-			$this->response_code = curl_getinfo($this->curl_handle, CURLINFO_HTTP_CODE);
777
-			$this->response_info = curl_getinfo($this->curl_handle);
778
-
779
-			// Parse out the headers
780
-			$this->response_headers = explode("\r\n\r\n", trim($this->response_headers));
781
-			$this->response_headers = array_pop($this->response_headers);
782
-			$this->response_headers = explode("\r\n", $this->response_headers);
783
-			array_shift($this->response_headers);
784
-
785
-			// Loop through and split up the headers.
786
-			$header_assoc = array();
787
-			foreach ($this->response_headers as $header)
788
-			{
789
-				$kv = explode(': ', $header);
790
-				$header_assoc[strtolower($kv[0])] = isset($kv[1])?$kv[1]:'';
791
-			}
792
-
793
-			// Reset the headers to the appropriate property.
794
-			$this->response_headers = $header_assoc;
795
-			$this->response_headers['_info'] = $this->response_info;
796
-			$this->response_headers['_info']['method'] = $this->method;
797
-
798
-			if ($curl_handle && $response)
799
-			{
800
-				return new $this->response_class($this->response_headers, $this->response_body, $this->response_code, $this->curl_handle);
801
-			}
802
-		}
803
-
804
-		// Return false
805
-		return false;
806
-	}
807
-
808
-	/**
809
-	 * Sends the request, calling necessary utility functions to update built-in properties.
810
-	 *
811
-	 * @param boolean $parse (Optional) Whether to parse the response with ResponseCore or not.
812
-	 * @return string The resulting unparsed data from the request.
813
-	 */
814
-	public function send_request($parse = false)
815
-	{
816
-		set_time_limit(0);
817
-
818
-		$curl_handle = $this->prep_request();
819
-		$this->response = curl_exec($curl_handle);
820
-
821
-		if ($this->response === false)
822
-		{
823
-			throw new RequestCore_Exception('cURL resource: ' . (string) $curl_handle . '; cURL error: ' . curl_error($curl_handle) . ' (' . curl_errno($curl_handle) . ')');
824
-		}
825
-
826
-		$parsed_response = $this->process_response($curl_handle, $this->response);
827
-
828
-		curl_close($curl_handle);
829
-
830
-		if ($parse)
831
-		{
832
-			return $parsed_response;
833
-		}
834
-
835
-		return $this->response;
836
-	}
837
-
838
-	/**
839
-	 * Sends the request using <php:curl_multi_exec()>, enabling parallel requests. Uses the "rolling" method.
840
-	 *
841
-	 * @param array $handles (Required) An indexed array of cURL handles to process simultaneously.
842
-	 * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
843
-	 * 	<li><code>callback</code> - <code>string|array</code> - Optional - The string name of a function to pass the response data to. If this is a method, pass an array where the <code>[0]</code> index is the class and the <code>[1]</code> index is the method name.</li>
844
-	 * 	<li><code>limit</code> - <code>integer</code> - Optional - The number of simultaneous requests to make. This can be useful for scaling around slow server responses. Defaults to trusting cURLs judgement as to how many to use.</li></ul>
845
-	 * @return array Post-processed cURL responses.
846
-	 */
847
-	public function send_multi_request($handles, $opt = null)
848
-	{
849
-		set_time_limit(0);
850
-
851
-		// Skip everything if there are no handles to process.
852
-		if (count($handles) === 0) return array();
853
-
854
-		if (!$opt) $opt = array();
855
-
856
-		// Initialize any missing options
857
-		$limit = isset($opt['limit']) ? $opt['limit'] : -1;
858
-
859
-		// Initialize
860
-		$handle_list = $handles;
861
-		$http = new $this->request_class();
862
-		$multi_handle = curl_multi_init();
863
-		$handles_post = array();
864
-		$added = count($handles);
865
-		$last_handle = null;
866
-		$count = 0;
867
-		$i = 0;
868
-
869
-		// Loop through the cURL handles and add as many as it set by the limit parameter.
870
-		while ($i < $added)
871
-		{
872
-			if ($limit > 0 && $i >= $limit) break;
873
-			curl_multi_add_handle($multi_handle, array_shift($handles));
874
-			$i++;
875
-		}
876
-
877
-		do
878
-		{
879
-			$active = false;
880
-
881
-			// Start executing and wait for a response.
882
-			while (($status = curl_multi_exec($multi_handle, $active)) === CURLM_CALL_MULTI_PERFORM)
883
-			{
884
-				// Start looking for possible responses immediately when we have to add more handles
885
-				if (count($handles) > 0) break;
886
-			}
887
-
888
-			// Figure out which requests finished.
889
-			$to_process = array();
890
-
891
-			while ($done = curl_multi_info_read($multi_handle))
892
-			{
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
-				if ($done['result'] > 0)
895
-				{
896
-					throw new RequestCore_Exception('cURL resource: ' . (string) $done['handle'] . '; cURL error: ' . curl_error($done['handle']) . ' (' . $done['result'] . ')');
897
-				}
898
-
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']]))
901
-				{
902
-					$to_process[(int) $done['handle']] = $done;
903
-				}
904
-			}
905
-
906
-			// Actually deal with the request
907
-			foreach ($to_process as $pkey => $done)
908
-			{
909
-				$response = $http->process_response($done['handle'], curl_multi_getcontent($done['handle']));
910
-				$key = array_search($done['handle'], $handle_list, true);
911
-				$handles_post[$key] = $response;
912
-
913
-				if (count($handles) > 0)
914
-				{
915
-					curl_multi_add_handle($multi_handle, array_shift($handles));
916
-				}
917
-
918
-				curl_multi_remove_handle($multi_handle, $done['handle']);
919
-				curl_close($done['handle']);
920
-			}
921
-		}
922
-		while ($active || count($handles_post) < $added);
923
-
924
-		curl_multi_close($multi_handle);
925
-
926
-		ksort($handles_post, SORT_NUMERIC);
927
-		return $handles_post;
928
-	}
929
-
930
-
931
-	/*%******************************************************************************************%*/
932
-	// RESPONSE METHODS
933
-
934
-	/**
935
-	 * Get the HTTP response headers from the request.
936
-	 *
937
-	 * @param string $header (Optional) A specific header value to return. Defaults to all headers.
938
-	 * @return string|array All or selected header values.
939
-	 */
940
-	public function get_response_header($header = null)
941
-	{
942
-		if ($header)
943
-		{
944
-			return $this->response_headers[strtolower($header)];
945
-		}
946
-		return $this->response_headers;
947
-	}
948
-
949
-	/**
950
-	 * Get the HTTP response body from the request.
951
-	 *
952
-	 * @return string The response body.
953
-	 */
954
-	public function get_response_body()
955
-	{
956
-		return $this->response_body;
957
-	}
958
-
959
-	/**
960
-	 * Get the HTTP response code from the request.
961
-	 *
962
-	 * @return string The HTTP response code.
963
-	 */
964
-	public function get_response_code()
965
-	{
966
-		return $this->response_code;
967
-	}
16
+    /**
17
+     * The URL being requested.
18
+     */
19
+    public $request_url;
20
+
21
+    /**
22
+     * The headers being sent in the request.
23
+     */
24
+    public $request_headers;
25
+
26
+    /**
27
+     * The body being sent in the request.
28
+     */
29
+    public $request_body;
30
+
31
+    /**
32
+     * The response returned by the request.
33
+     */
34
+    public $response;
35
+
36
+    /**
37
+     * The headers returned by the request.
38
+     */
39
+    public $response_headers;
40
+
41
+    /**
42
+     * The body returned by the request.
43
+     */
44
+    public $response_body;
45
+
46
+    /**
47
+     * The HTTP status code returned by the request.
48
+     */
49
+    public $response_code;
50
+
51
+    /**
52
+     * Additional response data.
53
+     */
54
+    public $response_info;
55
+
56
+    /**
57
+     * The handle for the cURL object.
58
+     */
59
+    public $curl_handle;
60
+
61
+    /**
62
+     * The method by which the request is being made.
63
+     */
64
+    public $method;
65
+
66
+    /**
67
+     * Stores the proxy settings to use for the request.
68
+     */
69
+    public $proxy = null;
70
+
71
+    /**
72
+     * The username to use for the request.
73
+     */
74
+    public $username = null;
75
+
76
+    /**
77
+     * The password to use for the request.
78
+     */
79
+    public $password = null;
80
+
81
+    /**
82
+     * Custom CURLOPT settings.
83
+     */
84
+    public $curlopts = null;
85
+
86
+    /**
87
+     * The state of debug mode.
88
+     */
89
+    public $debug_mode = false;
90
+
91
+    /**
92
+     * The default class to use for HTTP Requests (defaults to <RequestCore>).
93
+     */
94
+    public $request_class = 'RequestCore';
95
+
96
+    /**
97
+     * The default class to use for HTTP Responses (defaults to <ResponseCore>).
98
+     */
99
+    public $response_class = 'ResponseCore';
100
+
101
+    /**
102
+     * Default useragent string to use.
103
+     */
104
+    public $useragent = 'RequestCore/1.4.3';
105
+
106
+    /**
107
+     * File to read from while streaming up.
108
+     */
109
+    public $read_file = null;
110
+
111
+    /**
112
+     * The resource to read from while streaming up.
113
+     */
114
+    public $read_stream = null;
115
+
116
+    /**
117
+     * The size of the stream to read from.
118
+     */
119
+    public $read_stream_size = null;
120
+
121
+    /**
122
+     * The length already read from the stream.
123
+     */
124
+    public $read_stream_read = 0;
125
+
126
+    /**
127
+     * File to write to while streaming down.
128
+     */
129
+    public $write_file = null;
130
+
131
+    /**
132
+     * The resource to write to while streaming down.
133
+     */
134
+    public $write_stream = null;
135
+
136
+    /**
137
+     * Stores the intended starting seek position.
138
+     */
139
+    public $seek_position = null;
140
+
141
+    /**
142
+     * The location of the cacert.pem file to use.
143
+     */
144
+    public $cacert_location = false;
145
+
146
+    /**
147
+     * The state of SSL certificate verification.
148
+     */
149
+    public $ssl_verification = true;
150
+
151
+    /**
152
+     * The user-defined callback function to call when a stream is read from.
153
+     */
154
+    public $registered_streaming_read_callback = null;
155
+
156
+    /**
157
+     * The user-defined callback function to call when a stream is written to.
158
+     */
159
+    public $registered_streaming_write_callback = null;
160
+
161
+    /*%******************************************************************************************%*/
162
+    // CONSTANTS
163
+
164
+    /**
165
+     * GET HTTP Method
166
+     */
167
+    const HTTP_GET = 'GET';
168
+
169
+    /**
170
+     * POST HTTP Method
171
+     */
172
+    const HTTP_POST = 'POST';
173
+
174
+    /**
175
+     * PUT HTTP Method
176
+     */
177
+    const HTTP_PUT = 'PUT';
178
+
179
+    /**
180
+     * DELETE HTTP Method
181
+     */
182
+    const HTTP_DELETE = 'DELETE';
183
+
184
+    /**
185
+     * HEAD HTTP Method
186
+     */
187
+    const HTTP_HEAD = 'HEAD';
188
+
189
+
190
+    /*%******************************************************************************************%*/
191
+    // CONSTRUCTOR/DESTRUCTOR
192
+
193
+    /**
194
+     * Constructs a new instance of this class.
195
+     *
196
+     * @param string $url (Optional) The URL to request or service endpoint to query.
197
+     * @param string $proxy (Optional) The faux-url to use for proxy settings. Takes the following format: `proxy://user:pass@hostname:port`
198
+     * @param array $helpers (Optional) An associative array of classnames to use for request, and response functionality. Gets passed in automatically by the calling class.
199
+     * @return $this A reference to the current instance.
200
+     */
201
+    public function __construct($url = null, $proxy = null, $helpers = null)
202
+    {
203
+        // Set some default values.
204
+        $this->request_url = $url;
205
+        $this->method = self::HTTP_GET;
206
+        $this->request_headers = array();
207
+        $this->request_body = '';
208
+
209
+        // Set a new Request class if one was set.
210
+        if (isset($helpers['request']) && !empty($helpers['request']))
211
+        {
212
+            $this->request_class = $helpers['request'];
213
+        }
214
+
215
+        // Set a new Request class if one was set.
216
+        if (isset($helpers['response']) && !empty($helpers['response']))
217
+        {
218
+            $this->response_class = $helpers['response'];
219
+        }
220
+
221
+        if ($proxy)
222
+        {
223
+            $this->set_proxy($proxy);
224
+        }
225
+
226
+        return $this;
227
+    }
228
+
229
+    /**
230
+     * Destructs the instance. Closes opened file handles.
231
+     *
232
+     * @return $this A reference to the current instance.
233
+     */
234
+    public function __destruct()
235
+    {
236
+        if (isset($this->read_file) && isset($this->read_stream))
237
+        {
238
+            fclose($this->read_stream);
239
+        }
240
+
241
+        if (isset($this->write_file) && isset($this->write_stream))
242
+        {
243
+            fclose($this->write_stream);
244
+        }
245
+
246
+        return $this;
247
+    }
248
+
249
+
250
+    /*%******************************************************************************************%*/
251
+    // REQUEST METHODS
252
+
253
+    /**
254
+     * Sets the credentials to use for authentication.
255
+     *
256
+     * @param string $user (Required) The username to authenticate with.
257
+     * @param string $pass (Required) The password to authenticate with.
258
+     * @return $this A reference to the current instance.
259
+     */
260
+    public function set_credentials($user, $pass)
261
+    {
262
+        $this->username = $user;
263
+        $this->password = $pass;
264
+        return $this;
265
+    }
266
+
267
+    /**
268
+     * Adds a custom HTTP header to the cURL request.
269
+     *
270
+     * @param string $key (Required) The custom HTTP header to set.
271
+     * @param mixed $value (Required) The value to assign to the custom HTTP header.
272
+     * @return $this A reference to the current instance.
273
+     */
274
+    public function add_header($key, $value)
275
+    {
276
+        $this->request_headers[$key] = $value;
277
+        return $this;
278
+    }
279
+
280
+    /**
281
+     * Removes an HTTP header from the cURL request.
282
+     *
283
+     * @param string $key (Required) The custom HTTP header to set.
284
+     * @return $this A reference to the current instance.
285
+     */
286
+    public function remove_header($key)
287
+    {
288
+        if (isset($this->request_headers[$key]))
289
+        {
290
+            unset($this->request_headers[$key]);
291
+        }
292
+        return $this;
293
+    }
294
+
295
+    /**
296
+     * Set the method type for the request.
297
+     *
298
+     * @param string $method (Required) One of the following constants: <HTTP_GET>, <HTTP_POST>, <HTTP_PUT>, <HTTP_HEAD>, <HTTP_DELETE>.
299
+     * @return $this A reference to the current instance.
300
+     */
301
+    public function set_method($method)
302
+    {
303
+        $this->method = strtoupper($method);
304
+        return $this;
305
+    }
306
+
307
+    /**
308
+     * Sets a custom useragent string for the class.
309
+     *
310
+     * @param string $ua (Required) The useragent string to use.
311
+     * @return $this A reference to the current instance.
312
+     */
313
+    public function set_useragent($ua)
314
+    {
315
+        $this->useragent = $ua;
316
+        return $this;
317
+    }
318
+
319
+    /**
320
+     * Set the body to send in the request.
321
+     *
322
+     * @param string $body (Required) The textual content to send along in the body of the request.
323
+     * @return $this A reference to the current instance.
324
+     */
325
+    public function set_body($body)
326
+    {
327
+        $this->request_body = $body;
328
+        return $this;
329
+    }
330
+
331
+    /**
332
+     * Set the URL to make the request to.
333
+     *
334
+     * @param string $url (Required) The URL to make the request to.
335
+     * @return $this A reference to the current instance.
336
+     */
337
+    public function set_request_url($url)
338
+    {
339
+        $this->request_url = $url;
340
+        return $this;
341
+    }
342
+
343
+    /**
344
+     * Set additional CURLOPT settings. These will merge with the default settings, and override if
345
+     * there is a duplicate.
346
+     *
347
+     * @param array $curlopts (Optional) A set of key-value pairs that set `CURLOPT` options. These will merge with the existing CURLOPTs, and ones passed here will override the defaults. Keys should be the `CURLOPT_*` constants, not strings.
348
+     * @return $this A reference to the current instance.
349
+     */
350
+    public function set_curlopts($curlopts)
351
+    {
352
+        $this->curlopts = $curlopts;
353
+        return $this;
354
+    }
355
+
356
+    /**
357
+     * Sets the length in bytes to read from the stream while streaming up.
358
+     *
359
+     * @param integer $size (Required) The length in bytes to read from the stream.
360
+     * @return $this A reference to the current instance.
361
+     */
362
+    public function set_read_stream_size($size)
363
+    {
364
+        $this->read_stream_size = $size;
365
+
366
+        return $this;
367
+    }
368
+
369
+    /**
370
+     * Sets the resource to read from while streaming up. Reads the stream from its current position until
371
+     * EOF or `$size` bytes have been read. If `$size` is not given it will be determined by <php:fstat()> and
372
+     * <php:ftell()>.
373
+     *
374
+     * @param resource $resource (Required) The readable resource to read from.
375
+     * @param integer $size (Optional) The size of the stream to read.
376
+     * @return $this A reference to the current instance.
377
+     */
378
+    public function set_read_stream($resource, $size = null)
379
+    {
380
+        if (!isset($size) || $size < 0)
381
+        {
382
+            $stats = fstat($resource);
383
+
384
+            if ($stats && $stats['size'] >= 0)
385
+            {
386
+                $position = ftell($resource);
387
+
388
+                if ($position !== false && $position >= 0)
389
+                {
390
+                    $size = $stats['size'] - $position;
391
+                }
392
+            }
393
+        }
394
+
395
+        $this->read_stream = $resource;
396
+
397
+        return $this->set_read_stream_size($size);
398
+    }
399
+
400
+    /**
401
+     * Sets the file to read from while streaming up.
402
+     *
403
+     * @param string $location (Required) The readable location to read from.
404
+     * @return $this A reference to the current instance.
405
+     */
406
+    public function set_read_file($location)
407
+    {
408
+        $this->read_file = $location;
409
+        $read_file_handle = fopen($location, 'r');
410
+
411
+        return $this->set_read_stream($read_file_handle);
412
+    }
413
+
414
+    /**
415
+     * Sets the resource to write to while streaming down.
416
+     *
417
+     * @param resource $resource (Required) The writeable resource to write to.
418
+     * @return $this A reference to the current instance.
419
+     */
420
+    public function set_write_stream($resource)
421
+    {
422
+        $this->write_stream = $resource;
423
+
424
+        return $this;
425
+    }
426
+
427
+    /**
428
+     * Sets the file to write to while streaming down.
429
+     *
430
+     * @param string $location (Required) The writeable location to write to.
431
+     * @return $this A reference to the current instance.
432
+     */
433
+    public function set_write_file($location)
434
+    {
435
+        $this->write_file = $location;
436
+        $write_file_handle = fopen($location, 'w');
437
+
438
+        return $this->set_write_stream($write_file_handle);
439
+    }
440
+
441
+    /**
442
+     * Set the proxy to use for making requests.
443
+     *
444
+     * @param string $proxy (Required) The faux-url to use for proxy settings. Takes the following format: `proxy://user:pass@hostname:port`
445
+     * @return $this A reference to the current instance.
446
+     */
447
+    public function set_proxy($proxy)
448
+    {
449
+        $proxy = parse_url($proxy);
450
+        $proxy['user'] = isset($proxy['user']) ? $proxy['user'] : null;
451
+        $proxy['pass'] = isset($proxy['pass']) ? $proxy['pass'] : null;
452
+        $proxy['port'] = isset($proxy['port']) ? $proxy['port'] : null;
453
+        $this->proxy = $proxy;
454
+        return $this;
455
+    }
456
+
457
+    /**
458
+     * Set the intended starting seek position.
459
+     *
460
+     * @param integer $position (Required) The byte-position of the stream to begin reading from.
461
+     * @return $this A reference to the current instance.
462
+     */
463
+    public function set_seek_position($position)
464
+    {
465
+        $this->seek_position = isset($position) ? (integer) $position : null;
466
+
467
+        return $this;
468
+    }
469
+
470
+    /**
471
+     * Register a callback function to execute whenever a data stream is read from using
472
+     * <CFRequest::streaming_read_callback()>.
473
+     *
474
+     * The user-defined callback function should accept three arguments:
475
+     *
476
+     * <ul>
477
+     * 	<li><code>$curl_handle</code> - <code>resource</code> - Required - The cURL handle resource that represents the in-progress transfer.</li>
478
+     * 	<li><code>$file_handle</code> - <code>resource</code> - Required - The file handle resource that represents the file on the local file system.</li>
479
+     * 	<li><code>$length</code> - <code>integer</code> - Required - The length in kilobytes of the data chunk that was transferred.</li>
480
+     * </ul>
481
+     *
482
+     * @param string|array|function $callback (Required) The callback function is called by <php:call_user_func()>, so you can pass the following values: <ul>
483
+     * 	<li>The name of a global function to execute, passed as a string.</li>
484
+     * 	<li>A method to execute, passed as <code>array('ClassName', 'MethodName')</code>.</li>
485
+     * 	<li>An anonymous function (PHP 5.3+).</li></ul>
486
+     * @return $this A reference to the current instance.
487
+     */
488
+    public function register_streaming_read_callback($callback)
489
+    {
490
+        $this->registered_streaming_read_callback = $callback;
491
+
492
+        return $this;
493
+    }
494
+
495
+    /**
496
+     * Register a callback function to execute whenever a data stream is written to using
497
+     * <CFRequest::streaming_write_callback()>.
498
+     *
499
+     * The user-defined callback function should accept two arguments:
500
+     *
501
+     * <ul>
502
+     * 	<li><code>$curl_handle</code> - <code>resource</code> - Required - The cURL handle resource that represents the in-progress transfer.</li>
503
+     * 	<li><code>$length</code> - <code>integer</code> - Required - The length in kilobytes of the data chunk that was transferred.</li>
504
+     * </ul>
505
+     *
506
+     * @param string|array|function $callback (Required) The callback function is called by <php:call_user_func()>, so you can pass the following values: <ul>
507
+     * 	<li>The name of a global function to execute, passed as a string.</li>
508
+     * 	<li>A method to execute, passed as <code>array('ClassName', 'MethodName')</code>.</li>
509
+     * 	<li>An anonymous function (PHP 5.3+).</li></ul>
510
+     * @return $this A reference to the current instance.
511
+     */
512
+    public function register_streaming_write_callback($callback)
513
+    {
514
+        $this->registered_streaming_write_callback = $callback;
515
+
516
+        return $this;
517
+    }
518
+
519
+
520
+    /*%******************************************************************************************%*/
521
+    // PREPARE, SEND, AND PROCESS REQUEST
522
+
523
+    /**
524
+     * A callback function that is invoked by cURL for streaming up.
525
+     *
526
+     * @param resource $curl_handle (Required) The cURL handle for the request.
527
+     * @param resource $file_handle (Required) The open file handle resource.
528
+     * @param integer $length (Required) The maximum number of bytes to read.
529
+     * @return binary Binary data from a stream.
530
+     */
531
+    public function streaming_read_callback($curl_handle, $file_handle, $length)
532
+    {
533
+        // Execute callback function
534
+        if ($this->registered_streaming_read_callback)
535
+        {
536
+            return $this->registered_streaming_read_callback->streaming_read_callback($curl_handle, $file_handle, $length,$this->read_stream,$this->seek_position);
537
+        }
538
+        // Once we've sent as much as we're supposed to send...
539
+        if ($this->read_stream_read >= $this->read_stream_size)
540
+        {
541
+            // Send EOF
542
+            return '';
543
+        }
544
+
545
+        // If we're at the beginning of an upload and need to seek...
546
+        if ($this->read_stream_read == 0 && isset($this->seek_position) && $this->seek_position !== ftell($this->read_stream))
547
+        {
548
+            if (fseek($this->read_stream, $this->seek_position) !== 0)
549
+            {
550
+                throw new RequestCore_Exception('The stream does not support seeking and is either not at the requested position or the position is unknown.');
551
+            }
552
+        }
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
555
+        $this->read_stream_read += strlen($read);
556
+
557
+        $out = $read === false ? '' : $read;
558
+
559
+        return $out;
560
+    }
561
+
562
+    /**
563
+     * A callback function that is invoked by cURL for streaming down.
564
+     *
565
+     * @param resource $curl_handle (Required) The cURL handle for the request.
566
+     * @param binary $data (Required) The data to write.
567
+     * @return integer The number of bytes written.
568
+     */
569
+    public function streaming_write_callback($curl_handle, $data)
570
+    {
571
+        if ($this->registered_streaming_write_callback){
572
+            return $this->registered_streaming_write_callback->streaming_write_callback($curl_handle,$data,$this->write_stream);
573
+        }
574
+        $length = strlen($data);
575
+        $written_total = 0;
576
+        $written_last = 0;
577
+
578
+        while ($written_total < $length)
579
+        {
580
+            $written_last = fwrite($this->write_stream, substr($data, $written_total));
581
+
582
+            if ($written_last === false)
583
+            {
584
+                return $written_total;
585
+            }
586
+
587
+            $written_total += $written_last;
588
+        }
589
+
590
+        return $written_total;
591
+    }
592
+
593
+    /**
594
+     * Prepares and adds the details of the cURL request. This can be passed along to a <php:curl_multi_exec()>
595
+     * function.
596
+     *
597
+     * @return resource The handle for the cURL object.
598
+     */
599
+    public function prep_request()
600
+    {
601
+        $curl_handle = curl_init();
602
+
603
+        // Set default options.
604
+        curl_setopt($curl_handle, CURLOPT_URL, $this->request_url);
605
+        curl_setopt($curl_handle, CURLOPT_FILETIME, true);
606
+        curl_setopt($curl_handle, CURLOPT_FRESH_CONNECT, false);
607
+        //为了兼容PHP 5.6,PHP 5.6把 CURLOPT_CLOSEPOLICY 这个变量删除了
608
+        //curl_setopt($curl_handle, CURLOPT_CLOSEPOLICY, CURLCLOSEPOLICY_LEAST_RECENTLY_USED);
609
+        curl_setopt($curl_handle, CURLOPT_MAXREDIRS, 5);
610
+        curl_setopt($curl_handle, CURLOPT_HEADER, true);
611
+        curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true);
612
+        curl_setopt($curl_handle, CURLOPT_TIMEOUT, 5184000);
613
+        curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 120);
614
+        curl_setopt($curl_handle, CURLOPT_NOSIGNAL, true);
615
+        curl_setopt($curl_handle, CURLOPT_REFERER, $this->request_url);
616
+        curl_setopt($curl_handle, CURLOPT_USERAGENT, $this->useragent);
617
+        curl_setopt($curl_handle, CURLOPT_READFUNCTION, array($this, 'streaming_read_callback'));
618
+
619
+        // Verification of the SSL cert
620
+        if ($this->ssl_verification)
621
+        {
622
+            curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, true);
623
+            curl_setopt($curl_handle, CURLOPT_SSL_VERIFYHOST, 2);
624
+        }
625
+        else
626
+        {
627
+            curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, false);
628
+            curl_setopt($curl_handle, CURLOPT_SSL_VERIFYHOST, false);
629
+        }
630
+
631
+        // chmod the file as 0755
632
+        if ($this->cacert_location === true)
633
+        {
634
+            curl_setopt($curl_handle, CURLOPT_CAINFO, dirname(__FILE__) . '/cacert.pem');
635
+        }
636
+        elseif (is_string($this->cacert_location))
637
+        {
638
+            curl_setopt($curl_handle, CURLOPT_CAINFO, $this->cacert_location);
639
+        }
640
+
641
+        // Debug mode
642
+        if ($this->debug_mode)
643
+        {
644
+            curl_setopt($curl_handle, CURLOPT_VERBOSE, true);
645
+        }
646
+
647
+        // Handle open_basedir & safe mode
648
+        if (!ini_get('safe_mode') && !ini_get('open_basedir'))
649
+        {
650
+            curl_setopt($curl_handle, CURLOPT_FOLLOWLOCATION, FALSE);
651
+        }
652
+
653
+        // Enable a proxy connection if requested.
654
+        if ($this->proxy)
655
+        {
656
+            curl_setopt($curl_handle, CURLOPT_HTTPPROXYTUNNEL, true);
657
+
658
+            $host = $this->proxy['host'];
659
+            $host .= ($this->proxy['port']) ? ':' . $this->proxy['port'] : '';
660
+            curl_setopt($curl_handle, CURLOPT_PROXY, $host);
661
+
662
+            if (isset($this->proxy['user']) && isset($this->proxy['pass']))
663
+            {
664
+                curl_setopt($curl_handle, CURLOPT_PROXYUSERPWD, $this->proxy['user'] . ':' . $this->proxy['pass']);
665
+            }
666
+        }
667
+
668
+        // Set credentials for HTTP Basic/Digest Authentication.
669
+        if ($this->username && $this->password)
670
+        {
671
+            curl_setopt($curl_handle, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
672
+            curl_setopt($curl_handle, CURLOPT_USERPWD, $this->username . ':' . $this->password);
673
+        }
674
+
675
+        // Handle the encoding if we can.
676
+        if (extension_loaded('zlib'))
677
+        {
678
+            curl_setopt($curl_handle, CURLOPT_ENCODING, '');
679
+        }
680
+
681
+        // Process custom headers
682
+        if (isset($this->request_headers) && count($this->request_headers))
683
+        {
684
+            $temp_headers = array();
685
+
686
+            foreach ($this->request_headers as $k => $v)
687
+            {
688
+                $temp_headers[] = $k . ': ' . $v;
689
+            }
690
+
691
+            curl_setopt($curl_handle, CURLOPT_HTTPHEADER, $temp_headers);
692
+        }
693
+
694
+        switch ($this->method)
695
+        {
696
+            case self::HTTP_PUT:
697
+                //unset($this->read_stream);
698
+                curl_setopt($curl_handle, CURLOPT_CUSTOMREQUEST, 'PUT');
699
+                if (isset($this->read_stream))
700
+                {
701
+                    if (!isset($this->read_stream_size) || $this->read_stream_size < 0)
702
+                    {
703
+                        throw new RequestCore_Exception('The stream size for the streaming upload cannot be determined.');
704
+                    }
705
+
706
+                    curl_setopt($curl_handle, CURLOPT_INFILESIZE, $this->read_stream_size);
707
+                    curl_setopt($curl_handle, CURLOPT_UPLOAD, true);
708
+                }
709
+                else
710
+                {
711
+                    curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $this->request_body);
712
+                }
713
+                break;
714
+
715
+            case self::HTTP_POST:
716
+                curl_setopt($curl_handle, CURLOPT_POST, true);
717
+                curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $this->request_body);
718
+                break;
719
+
720
+            case self::HTTP_HEAD:
721
+                curl_setopt($curl_handle, CURLOPT_CUSTOMREQUEST, self::HTTP_HEAD);
722
+                curl_setopt($curl_handle, CURLOPT_NOBODY, 1);
723
+                break;
724
+
725
+            default: // Assumed GET
726
+                curl_setopt($curl_handle, CURLOPT_CUSTOMREQUEST, $this->method);
727
+                if (isset($this->write_stream))
728
+                {
729
+                    curl_setopt($curl_handle, CURLOPT_WRITEFUNCTION, array($this, 'streaming_write_callback'));
730
+                    curl_setopt($curl_handle, CURLOPT_HEADER, false);
731
+                }
732
+                else
733
+                {
734
+                    curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $this->request_body);
735
+                }
736
+                break;
737
+        }
738
+
739
+        // Merge in the CURLOPTs
740
+        if (isset($this->curlopts) && sizeof($this->curlopts) > 0)
741
+        {
742
+            foreach ($this->curlopts as $k => $v)
743
+            {
744
+                curl_setopt($curl_handle, $k, $v);
745
+            }
746
+        }
747
+
748
+        return $curl_handle;
749
+    }
750
+
751
+    /**
752
+     * Take the post-processed cURL data and break it down into useful header/body/info chunks. Uses the
753
+     * data stored in the `curl_handle` and `response` properties unless replacement data is passed in via
754
+     * parameters.
755
+     *
756
+     * @param resource $curl_handle (Optional) The reference to the already executed cURL request.
757
+     * @param string $response (Optional) The actual response content itself that needs to be parsed.
758
+     * @return ResponseCore A <ResponseCore> object containing a parsed HTTP response.
759
+     */
760
+    public function process_response($curl_handle = null, $response = null)
761
+    {
762
+        // Accept a custom one if it's passed.
763
+        if ($curl_handle && $response)
764
+        {
765
+            $this->curl_handle = $curl_handle;
766
+            $this->response = $response;
767
+        }
768
+
769
+        // As long as this came back as a valid resource...
770
+        if (is_resource($this->curl_handle))
771
+        {
772
+            // Determine what's what.
773
+            $header_size = curl_getinfo($this->curl_handle, CURLINFO_HEADER_SIZE);
774
+            $this->response_headers = substr($this->response, 0, $header_size);
775
+            $this->response_body = substr($this->response, $header_size);
776
+            $this->response_code = curl_getinfo($this->curl_handle, CURLINFO_HTTP_CODE);
777
+            $this->response_info = curl_getinfo($this->curl_handle);
778
+
779
+            // Parse out the headers
780
+            $this->response_headers = explode("\r\n\r\n", trim($this->response_headers));
781
+            $this->response_headers = array_pop($this->response_headers);
782
+            $this->response_headers = explode("\r\n", $this->response_headers);
783
+            array_shift($this->response_headers);
784
+
785
+            // Loop through and split up the headers.
786
+            $header_assoc = array();
787
+            foreach ($this->response_headers as $header)
788
+            {
789
+                $kv = explode(': ', $header);
790
+                $header_assoc[strtolower($kv[0])] = isset($kv[1])?$kv[1]:'';
791
+            }
792
+
793
+            // Reset the headers to the appropriate property.
794
+            $this->response_headers = $header_assoc;
795
+            $this->response_headers['_info'] = $this->response_info;
796
+            $this->response_headers['_info']['method'] = $this->method;
797
+
798
+            if ($curl_handle && $response)
799
+            {
800
+                return new $this->response_class($this->response_headers, $this->response_body, $this->response_code, $this->curl_handle);
801
+            }
802
+        }
803
+
804
+        // Return false
805
+        return false;
806
+    }
807
+
808
+    /**
809
+     * Sends the request, calling necessary utility functions to update built-in properties.
810
+     *
811
+     * @param boolean $parse (Optional) Whether to parse the response with ResponseCore or not.
812
+     * @return string The resulting unparsed data from the request.
813
+     */
814
+    public function send_request($parse = false)
815
+    {
816
+        set_time_limit(0);
817
+
818
+        $curl_handle = $this->prep_request();
819
+        $this->response = curl_exec($curl_handle);
820
+
821
+        if ($this->response === false)
822
+        {
823
+            throw new RequestCore_Exception('cURL resource: ' . (string) $curl_handle . '; cURL error: ' . curl_error($curl_handle) . ' (' . curl_errno($curl_handle) . ')');
824
+        }
825
+
826
+        $parsed_response = $this->process_response($curl_handle, $this->response);
827
+
828
+        curl_close($curl_handle);
829
+
830
+        if ($parse)
831
+        {
832
+            return $parsed_response;
833
+        }
834
+
835
+        return $this->response;
836
+    }
837
+
838
+    /**
839
+     * Sends the request using <php:curl_multi_exec()>, enabling parallel requests. Uses the "rolling" method.
840
+     *
841
+     * @param array $handles (Required) An indexed array of cURL handles to process simultaneously.
842
+     * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
843
+     * 	<li><code>callback</code> - <code>string|array</code> - Optional - The string name of a function to pass the response data to. If this is a method, pass an array where the <code>[0]</code> index is the class and the <code>[1]</code> index is the method name.</li>
844
+     * 	<li><code>limit</code> - <code>integer</code> - Optional - The number of simultaneous requests to make. This can be useful for scaling around slow server responses. Defaults to trusting cURLs judgement as to how many to use.</li></ul>
845
+     * @return array Post-processed cURL responses.
846
+     */
847
+    public function send_multi_request($handles, $opt = null)
848
+    {
849
+        set_time_limit(0);
850
+
851
+        // Skip everything if there are no handles to process.
852
+        if (count($handles) === 0) return array();
853
+
854
+        if (!$opt) $opt = array();
855
+
856
+        // Initialize any missing options
857
+        $limit = isset($opt['limit']) ? $opt['limit'] : -1;
858
+
859
+        // Initialize
860
+        $handle_list = $handles;
861
+        $http = new $this->request_class();
862
+        $multi_handle = curl_multi_init();
863
+        $handles_post = array();
864
+        $added = count($handles);
865
+        $last_handle = null;
866
+        $count = 0;
867
+        $i = 0;
868
+
869
+        // Loop through the cURL handles and add as many as it set by the limit parameter.
870
+        while ($i < $added)
871
+        {
872
+            if ($limit > 0 && $i >= $limit) break;
873
+            curl_multi_add_handle($multi_handle, array_shift($handles));
874
+            $i++;
875
+        }
876
+
877
+        do
878
+        {
879
+            $active = false;
880
+
881
+            // Start executing and wait for a response.
882
+            while (($status = curl_multi_exec($multi_handle, $active)) === CURLM_CALL_MULTI_PERFORM)
883
+            {
884
+                // Start looking for possible responses immediately when we have to add more handles
885
+                if (count($handles) > 0) break;
886
+            }
887
+
888
+            // Figure out which requests finished.
889
+            $to_process = array();
890
+
891
+            while ($done = curl_multi_info_read($multi_handle))
892
+            {
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
+                if ($done['result'] > 0)
895
+                {
896
+                    throw new RequestCore_Exception('cURL resource: ' . (string) $done['handle'] . '; cURL error: ' . curl_error($done['handle']) . ' (' . $done['result'] . ')');
897
+                }
898
+
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']]))
901
+                {
902
+                    $to_process[(int) $done['handle']] = $done;
903
+                }
904
+            }
905
+
906
+            // Actually deal with the request
907
+            foreach ($to_process as $pkey => $done)
908
+            {
909
+                $response = $http->process_response($done['handle'], curl_multi_getcontent($done['handle']));
910
+                $key = array_search($done['handle'], $handle_list, true);
911
+                $handles_post[$key] = $response;
912
+
913
+                if (count($handles) > 0)
914
+                {
915
+                    curl_multi_add_handle($multi_handle, array_shift($handles));
916
+                }
917
+
918
+                curl_multi_remove_handle($multi_handle, $done['handle']);
919
+                curl_close($done['handle']);
920
+            }
921
+        }
922
+        while ($active || count($handles_post) < $added);
923
+
924
+        curl_multi_close($multi_handle);
925
+
926
+        ksort($handles_post, SORT_NUMERIC);
927
+        return $handles_post;
928
+    }
929
+
930
+
931
+    /*%******************************************************************************************%*/
932
+    // RESPONSE METHODS
933
+
934
+    /**
935
+     * Get the HTTP response headers from the request.
936
+     *
937
+     * @param string $header (Optional) A specific header value to return. Defaults to all headers.
938
+     * @return string|array All or selected header values.
939
+     */
940
+    public function get_response_header($header = null)
941
+    {
942
+        if ($header)
943
+        {
944
+            return $this->response_headers[strtolower($header)];
945
+        }
946
+        return $this->response_headers;
947
+    }
948
+
949
+    /**
950
+     * Get the HTTP response body from the request.
951
+     *
952
+     * @return string The response body.
953
+     */
954
+    public function get_response_body()
955
+    {
956
+        return $this->response_body;
957
+    }
958
+
959
+    /**
960
+     * Get the HTTP response code from the request.
961
+     *
962
+     * @return string The HTTP response code.
963
+     */
964
+    public function get_response_code()
965
+    {
966
+        return $this->response_code;
967
+    }
968 968
 }
969 969
 
970 970
 
@@ -973,53 +973,53 @@  discard block
 block discarded – undo
973 973
  */
974 974
 class ResponseCore
975 975
 {
976
-	/**
977
-	 * Stores the HTTP header information.
978
-	 */
979
-	public $header;
980
-
981
-	/**
982
-	 * Stores the SimpleXML response.
983
-	 */
984
-	public $body;
985
-
986
-	/**
987
-	 * Stores the HTTP response code.
988
-	 */
989
-	public $status;
990
-
991
-	/**
992
-	 * Constructs a new instance of this class.
993
-	 *
994
-	 * @param array $header (Required) Associative array of HTTP headers (typically returned by <RequestCore::get_response_header()>).
995
-	 * @param string $body (Required) XML-formatted response from AWS.
996
-	 * @param integer $status (Optional) HTTP response status code from the request.
997
-	 * @return object Contains an <php:array> `header` property (HTTP headers as an associative array), a <php:SimpleXMLElement> or <php:string> `body` property, and an <php:integer> `status` code.
998
-	 */
999
-	public function __construct($header, $body, $status = null)
1000
-	{
1001
-		$this->header = $header;
1002
-		$this->body = $body;
1003
-		$this->status = $status;
1004
-
1005
-		return $this;
1006
-	}
1007
-
1008
-	/**
1009
-	 * Did we receive the status code we expected?
1010
-	 *
1011
-	 * @param integer|array $codes (Optional) The status code(s) to expect. Pass an <php:integer> for a single acceptable value, or an <php:array> of integers for multiple acceptable values.
1012
-	 * @return boolean Whether we received the expected status code or not.
1013
-	 */
1014
-	public function isOK($codes = array(200, 201, 204, 206))
1015
-	{
1016
-		if (is_array($codes))
1017
-		{
1018
-			return in_array($this->status, $codes);
1019
-		}
1020
-
1021
-		return $this->status === $codes;
1022
-	}
976
+    /**
977
+     * Stores the HTTP header information.
978
+     */
979
+    public $header;
980
+
981
+    /**
982
+     * Stores the SimpleXML response.
983
+     */
984
+    public $body;
985
+
986
+    /**
987
+     * Stores the HTTP response code.
988
+     */
989
+    public $status;
990
+
991
+    /**
992
+     * Constructs a new instance of this class.
993
+     *
994
+     * @param array $header (Required) Associative array of HTTP headers (typically returned by <RequestCore::get_response_header()>).
995
+     * @param string $body (Required) XML-formatted response from AWS.
996
+     * @param integer $status (Optional) HTTP response status code from the request.
997
+     * @return object Contains an <php:array> `header` property (HTTP headers as an associative array), a <php:SimpleXMLElement> or <php:string> `body` property, and an <php:integer> `status` code.
998
+     */
999
+    public function __construct($header, $body, $status = null)
1000
+    {
1001
+        $this->header = $header;
1002
+        $this->body = $body;
1003
+        $this->status = $status;
1004
+
1005
+        return $this;
1006
+    }
1007
+
1008
+    /**
1009
+     * Did we receive the status code we expected?
1010
+     *
1011
+     * @param integer|array $codes (Optional) The status code(s) to expect. Pass an <php:integer> for a single acceptable value, or an <php:array> of integers for multiple acceptable values.
1012
+     * @return boolean Whether we received the expected status code or not.
1013
+     */
1014
+    public function isOK($codes = array(200, 201, 204, 206))
1015
+    {
1016
+        if (is_array($codes))
1017
+        {
1018
+            return in_array($this->status, $codes);
1019
+        }
1020
+
1021
+        return $this->status === $codes;
1022
+    }
1023 1023
 }
1024 1024
 
1025 1025
 /**
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -387,7 +387,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
Braces   +16 added lines, -12 removed lines patch added patch discarded remove patch
@@ -621,8 +621,7 @@  discard block
 block discarded – undo
621 621
 		{
622 622
 			curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, true);
623 623
 			curl_setopt($curl_handle, CURLOPT_SSL_VERIFYHOST, 2);
624
-		}
625
-		else
624
+		} else
626 625
 		{
627 626
 			curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, false);
628 627
 			curl_setopt($curl_handle, CURLOPT_SSL_VERIFYHOST, false);
@@ -632,8 +631,7 @@  discard block
 block discarded – undo
632 631
 		if ($this->cacert_location === true)
633 632
 		{
634 633
 			curl_setopt($curl_handle, CURLOPT_CAINFO, dirname(__FILE__) . '/cacert.pem');
635
-		}
636
-		elseif (is_string($this->cacert_location))
634
+		} elseif (is_string($this->cacert_location))
637 635
 		{
638 636
 			curl_setopt($curl_handle, CURLOPT_CAINFO, $this->cacert_location);
639 637
 		}
@@ -705,8 +703,7 @@  discard block
 block discarded – undo
705 703
 
706 704
 					curl_setopt($curl_handle, CURLOPT_INFILESIZE, $this->read_stream_size);
707 705
 					curl_setopt($curl_handle, CURLOPT_UPLOAD, true);
708
-				}
709
-				else
706
+				} else
710 707
 				{
711 708
 					curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $this->request_body);
712 709
 				}
@@ -728,8 +725,7 @@  discard block
 block discarded – undo
728 725
 				{
729 726
 					curl_setopt($curl_handle, CURLOPT_WRITEFUNCTION, array($this, 'streaming_write_callback'));
730 727
 					curl_setopt($curl_handle, CURLOPT_HEADER, false);
731
-				}
732
-				else
728
+				} else
733 729
 				{
734 730
 					curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $this->request_body);
735 731
 				}
@@ -849,9 +845,13 @@  discard block
 block discarded – undo
849 845
 		set_time_limit(0);
850 846
 
851 847
 		// Skip everything if there are no handles to process.
852
-		if (count($handles) === 0) return array();
848
+		if (count($handles) === 0) {
849
+		    return array();
850
+		}
853 851
 
854
-		if (!$opt) $opt = array();
852
+		if (!$opt) {
853
+		    $opt = array();
854
+		}
855 855
 
856 856
 		// Initialize any missing options
857 857
 		$limit = isset($opt['limit']) ? $opt['limit'] : -1;
@@ -869,7 +869,9 @@  discard block
 block discarded – undo
869 869
 		// Loop through the cURL handles and add as many as it set by the limit parameter.
870 870
 		while ($i < $added)
871 871
 		{
872
-			if ($limit > 0 && $i >= $limit) break;
872
+			if ($limit > 0 && $i >= $limit) {
873
+			    break;
874
+			}
873 875
 			curl_multi_add_handle($multi_handle, array_shift($handles));
874 876
 			$i++;
875 877
 		}
@@ -882,7 +884,9 @@  discard block
 block discarded – undo
882 884
 			while (($status = curl_multi_exec($multi_handle, $active)) === CURLM_CALL_MULTI_PERFORM)
883 885
 			{
884 886
 				// Start looking for possible responses immediately when we have to add more handles
885
-				if (count($handles) > 0) break;
887
+				if (count($handles) > 0) {
888
+				    break;
889
+				}
886 890
 			}
887 891
 
888 892
 			// Figure out which requests finished.
Please login to merge, or discard this patch.
src/service/ksyun/bin/Ks3EncryptionClient.class.php 3 patches
Indentation   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -19,111 +19,111 @@
 block discarded – undo
19 19
 
20 20
 
21 21
 if(function_exists('get_loaded_extensions')){
22
-	//检测mcrypt,openssl扩展
23
-	$extensions = get_loaded_extensions();
24
-	if($extensions){
25
-		if(!in_array('mcrypt', $extensions)){
26
-			throw new Ks3ClientException("please install mcrypt extension");
27
-		}
28
-		if(!in_array('openssl', $extensions)){
29
-			throw new Ks3ClientException("please install openssl extension");
30
-		}
31
-	}else{
32
-		throw new Ks3ClientException("please install extensions");
33
-	}
22
+    //检测mcrypt,openssl扩展
23
+    $extensions = get_loaded_extensions();
24
+    if($extensions){
25
+        if(!in_array('mcrypt', $extensions)){
26
+            throw new Ks3ClientException("please install mcrypt extension");
27
+        }
28
+        if(!in_array('openssl', $extensions)){
29
+            throw new Ks3ClientException("please install openssl extension");
30
+        }
31
+    }else{
32
+        throw new Ks3ClientException("please install extensions");
33
+    }
34 34
 }else{
35
-	throw new Ks3ClientException();
35
+    throw new Ks3ClientException();
36 36
 } 
37 37
 class Ks3EncryptionClient extends Ks3Client{
38
-	private $encryptionHandler = NULL;
39
-	//用户提供的主密钥,可以是对称秘钥或非对称秘钥(array,分别是公钥和私钥)
40
-	private $encryptionMaterials = NULL;
38
+    private $encryptionHandler = NULL;
39
+    //用户提供的主密钥,可以是对称秘钥或非对称秘钥(array,分别是公钥和私钥)
40
+    private $encryptionMaterials = NULL;
41 41
 
42
-	public function __construct($accessKey, $secretKey,$encryptionMaterials, $endpoint = NULL ){
43
-		parent::__construct($accessKey,$secretKey,$endpoint);
44
-		if(is_array($encryptionMaterials)){
45
-			if(count($encryptionMaterials)==2){
46
-				$pk = openssl_pkey_get_public($encryptionMaterials[0]);
47
-				$sk = openssl_pkey_get_private($encryptionMaterials[1]);
48
-				if(!$pk)
49
-					throw new Ks3ClientException("invalid RSA public key,you can generate key use openssl");
50
-				if(!$sk)
51
-					throw new Ks3ClientException("invalid RSA private key,you can generate key use openssl");
52
-				$encryptionMaterials = array($pk,$sk);
53
-			}else{
54
-				throw new Ks3ClientException("encryptionMaterials should be string or an array of size 2");
55
-			}
56
-		}
57
-		$ks3client = new Ks3Client($accessKey,$secretKey,$endpoint);
58
-		$this->encryptionMaterials = $encryptionMaterials;
59
-		if(ENCRYPTPTION_MODE == "EO"){
60
-			$this->encryptionHandler = new EncryptionEO($ks3client,$encryptionMaterials);
61
-		}elseif (ENCRYPTPTION_MODE == "AE") {
62
-			throw new Ks3ClientException("Authenticated encryption will be supported in the futher");
63
-		}
64
-		else{
65
-			throw new Ks3ClientException("unsupported encryption mode :".ENCRYPTPTION_MODE);
66
-		}
67
-		if(ENCRYPTPTION_STORAGE_MODE != "ObjectMetadata"&&ENCRYPTPTION_STORAGE_MODE!="InstructionFile"){
68
-			throw new Ks3ClientException("unsupported encryption storage mode :".ENCRYPTPTION_STORAGE_MODE);
69
-		}
70
-	}
42
+    public function __construct($accessKey, $secretKey,$encryptionMaterials, $endpoint = NULL ){
43
+        parent::__construct($accessKey,$secretKey,$endpoint);
44
+        if(is_array($encryptionMaterials)){
45
+            if(count($encryptionMaterials)==2){
46
+                $pk = openssl_pkey_get_public($encryptionMaterials[0]);
47
+                $sk = openssl_pkey_get_private($encryptionMaterials[1]);
48
+                if(!$pk)
49
+                    throw new Ks3ClientException("invalid RSA public key,you can generate key use openssl");
50
+                if(!$sk)
51
+                    throw new Ks3ClientException("invalid RSA private key,you can generate key use openssl");
52
+                $encryptionMaterials = array($pk,$sk);
53
+            }else{
54
+                throw new Ks3ClientException("encryptionMaterials should be string or an array of size 2");
55
+            }
56
+        }
57
+        $ks3client = new Ks3Client($accessKey,$secretKey,$endpoint);
58
+        $this->encryptionMaterials = $encryptionMaterials;
59
+        if(ENCRYPTPTION_MODE == "EO"){
60
+            $this->encryptionHandler = new EncryptionEO($ks3client,$encryptionMaterials);
61
+        }elseif (ENCRYPTPTION_MODE == "AE") {
62
+            throw new Ks3ClientException("Authenticated encryption will be supported in the futher");
63
+        }
64
+        else{
65
+            throw new Ks3ClientException("unsupported encryption mode :".ENCRYPTPTION_MODE);
66
+        }
67
+        if(ENCRYPTPTION_STORAGE_MODE != "ObjectMetadata"&&ENCRYPTPTION_STORAGE_MODE!="InstructionFile"){
68
+            throw new Ks3ClientException("unsupported encryption storage mode :".ENCRYPTPTION_STORAGE_MODE);
69
+        }
70
+    }
71 71
 
72
-	public function putObjectByContent($args=array()){
73
-		return $this->encryptionHandler->putObjectByContentSecurely($args);
74
-	}
75
-	public function putObjectByFile($args=array()){
76
-		return $this->encryptionHandler->putObjectByFileSecurely($args);
77
-	}
78
-	public function getObject($args=array()){
79
-		return $this->encryptionHandler->getObjectSecurely($args);
80
-	}
81
-	public function initMultipartUpload($args=array()){
82
-		return $this->encryptionHandler->initMultipartUploadSecurely($args);
83
-	}
84
-	public function uploadPart($args=array()){
85
-		return $this->encryptionHandler->uploadPartSecurely($args);
86
-	}
87
-	public function abortMultipartUpload($args=array()){
88
-		return $this->encryptionHandler->abortMultipartUploadSecurely($args);
89
-	}
90
-	public function completeMultipartUpload($args=array()){
91
-		return $this->encryptionHandler->completeMultipartUploadSecurely($args);
92
-	}
93
-	public function deleteObject($args=array()){
94
-		$result = parent::deleteObject($args);
95
-		$args["Key"] = $args["Key"].EncryptionUtil::$INSTRUCTION_SUFFIX;
96
-		try {
97
-			parent::deleteObject($args);
98
-		} catch (Exception $e) {
99
-			//do nothing
100
-		}
101
-		return $result;
102
-	}
103
-	public function copyObject($args=array()){
104
-		if(parent::objectExists(array(
105
-			"Bucket"=>$args["Bucket"],
106
-			"Key"=>$args["Key"]
107
-			))){
108
-			throw new Ks3ClientException("copy object faild,destination object exists");
109
-		}
110
-		if(parent::objectExists(array(
111
-			"Bucket"=>$args["CopySource"]["Bucket"],
112
-			"Key"=>$args["CopySource"]["Key"].EncryptionUtil::$INSTRUCTION_SUFFIX
113
-			))){
114
-			parent::copyObject(
115
-				array(
116
-					"Bucket"=>$args["Bucket"],
117
-					"Key"=>$args["Key"].EncryptionUtil::$INSTRUCTION_SUFFIX,
118
-					"CopySource"=>array(
119
-						"Bucket"=>$args["CopySource"]["Bucket"],
120
-						"Key"=>$args["CopySource"]["Key"].EncryptionUtil::$INSTRUCTION_SUFFIX
121
-						)
122
-					)
123
-				);
124
-		}
125
-		return parent::copyObject($args);
126
-	}
72
+    public function putObjectByContent($args=array()){
73
+        return $this->encryptionHandler->putObjectByContentSecurely($args);
74
+    }
75
+    public function putObjectByFile($args=array()){
76
+        return $this->encryptionHandler->putObjectByFileSecurely($args);
77
+    }
78
+    public function getObject($args=array()){
79
+        return $this->encryptionHandler->getObjectSecurely($args);
80
+    }
81
+    public function initMultipartUpload($args=array()){
82
+        return $this->encryptionHandler->initMultipartUploadSecurely($args);
83
+    }
84
+    public function uploadPart($args=array()){
85
+        return $this->encryptionHandler->uploadPartSecurely($args);
86
+    }
87
+    public function abortMultipartUpload($args=array()){
88
+        return $this->encryptionHandler->abortMultipartUploadSecurely($args);
89
+    }
90
+    public function completeMultipartUpload($args=array()){
91
+        return $this->encryptionHandler->completeMultipartUploadSecurely($args);
92
+    }
93
+    public function deleteObject($args=array()){
94
+        $result = parent::deleteObject($args);
95
+        $args["Key"] = $args["Key"].EncryptionUtil::$INSTRUCTION_SUFFIX;
96
+        try {
97
+            parent::deleteObject($args);
98
+        } catch (Exception $e) {
99
+            //do nothing
100
+        }
101
+        return $result;
102
+    }
103
+    public function copyObject($args=array()){
104
+        if(parent::objectExists(array(
105
+            "Bucket"=>$args["Bucket"],
106
+            "Key"=>$args["Key"]
107
+            ))){
108
+            throw new Ks3ClientException("copy object faild,destination object exists");
109
+        }
110
+        if(parent::objectExists(array(
111
+            "Bucket"=>$args["CopySource"]["Bucket"],
112
+            "Key"=>$args["CopySource"]["Key"].EncryptionUtil::$INSTRUCTION_SUFFIX
113
+            ))){
114
+            parent::copyObject(
115
+                array(
116
+                    "Bucket"=>$args["Bucket"],
117
+                    "Key"=>$args["Key"].EncryptionUtil::$INSTRUCTION_SUFFIX,
118
+                    "CopySource"=>array(
119
+                        "Bucket"=>$args["CopySource"]["Bucket"],
120
+                        "Key"=>$args["CopySource"]["Key"].EncryptionUtil::$INSTRUCTION_SUFFIX
121
+                        )
122
+                    )
123
+                );
124
+        }
125
+        return parent::copyObject($args);
126
+    }
127 127
 }
128 128
 
129 129
 ?>
130 130
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 //使用客户端加密的方式上传下载文件
3 3
 //检测API路径
4
-if(!defined('KS3_API_PATH'))
4
+if (!defined('KS3_API_PATH'))
5 5
 define('KS3_API_PATH', dirname(__FILE__));
6 6
 require_once KS3_API_PATH.DIRECTORY_SEPARATOR."Ks3Client.class.php";
7 7
 require_once KS3_API_PATH.DIRECTORY_SEPARATOR."encryption".DIRECTORY_SEPARATOR."EncryptionUtil.php";
@@ -9,88 +9,88 @@  discard block
 block discarded – undo
9 9
 
10 10
 //加密模式
11 11
 //暂时仅支持EO,使用AES/CBC/PKCS5Padding算法对数据进行加密
12
-if(!defined("ENCRYPTPTION_MODE"))
13
-define("ENCRYPTPTION_MODE","EO");
12
+if (!defined("ENCRYPTPTION_MODE"))
13
+define("ENCRYPTPTION_MODE", "EO");
14 14
 //加密信息存储模式,暂时支持 ObjectMetadata和InstructionFile
15 15
 //ObjectMetadata:存在用户元数据中
16 16
 //InstructionFile:存在一个.instruction文件中
17
-if(!defined("ENCRYPTPTION_STORAGE_MODE"))
18
-define("ENCRYPTPTION_STORAGE_MODE","ObjectMetadata");
17
+if (!defined("ENCRYPTPTION_STORAGE_MODE"))
18
+define("ENCRYPTPTION_STORAGE_MODE", "ObjectMetadata");
19 19
 
20 20
 
21
-if(function_exists('get_loaded_extensions')){
21
+if (function_exists('get_loaded_extensions')) {
22 22
 	//检测mcrypt,openssl扩展
23 23
 	$extensions = get_loaded_extensions();
24
-	if($extensions){
25
-		if(!in_array('mcrypt', $extensions)){
24
+	if ($extensions) {
25
+		if (!in_array('mcrypt', $extensions)) {
26 26
 			throw new Ks3ClientException("please install mcrypt extension");
27 27
 		}
28
-		if(!in_array('openssl', $extensions)){
28
+		if (!in_array('openssl', $extensions)) {
29 29
 			throw new Ks3ClientException("please install openssl extension");
30 30
 		}
31
-	}else{
31
+	}else {
32 32
 		throw new Ks3ClientException("please install extensions");
33 33
 	}
34
-}else{
34
+}else {
35 35
 	throw new Ks3ClientException();
36 36
 } 
37
-class Ks3EncryptionClient extends Ks3Client{
37
+class Ks3EncryptionClient extends Ks3Client {
38 38
 	private $encryptionHandler = NULL;
39 39
 	//用户提供的主密钥,可以是对称秘钥或非对称秘钥(array,分别是公钥和私钥)
40 40
 	private $encryptionMaterials = NULL;
41 41
 
42
-	public function __construct($accessKey, $secretKey,$encryptionMaterials, $endpoint = NULL ){
43
-		parent::__construct($accessKey,$secretKey,$endpoint);
44
-		if(is_array($encryptionMaterials)){
45
-			if(count($encryptionMaterials)==2){
42
+	public function __construct($accessKey, $secretKey, $encryptionMaterials, $endpoint = NULL) {
43
+		parent::__construct($accessKey, $secretKey, $endpoint);
44
+		if (is_array($encryptionMaterials)) {
45
+			if (count($encryptionMaterials) == 2) {
46 46
 				$pk = openssl_pkey_get_public($encryptionMaterials[0]);
47 47
 				$sk = openssl_pkey_get_private($encryptionMaterials[1]);
48
-				if(!$pk)
48
+				if (!$pk)
49 49
 					throw new Ks3ClientException("invalid RSA public key,you can generate key use openssl");
50
-				if(!$sk)
50
+				if (!$sk)
51 51
 					throw new Ks3ClientException("invalid RSA private key,you can generate key use openssl");
52
-				$encryptionMaterials = array($pk,$sk);
53
-			}else{
52
+				$encryptionMaterials = array($pk, $sk);
53
+			}else {
54 54
 				throw new Ks3ClientException("encryptionMaterials should be string or an array of size 2");
55 55
 			}
56 56
 		}
57
-		$ks3client = new Ks3Client($accessKey,$secretKey,$endpoint);
57
+		$ks3client = new Ks3Client($accessKey, $secretKey, $endpoint);
58 58
 		$this->encryptionMaterials = $encryptionMaterials;
59
-		if(ENCRYPTPTION_MODE == "EO"){
60
-			$this->encryptionHandler = new EncryptionEO($ks3client,$encryptionMaterials);
59
+		if (ENCRYPTPTION_MODE == "EO") {
60
+			$this->encryptionHandler = new EncryptionEO($ks3client, $encryptionMaterials);
61 61
 		}elseif (ENCRYPTPTION_MODE == "AE") {
62 62
 			throw new Ks3ClientException("Authenticated encryption will be supported in the futher");
63 63
 		}
64
-		else{
64
+		else {
65 65
 			throw new Ks3ClientException("unsupported encryption mode :".ENCRYPTPTION_MODE);
66 66
 		}
67
-		if(ENCRYPTPTION_STORAGE_MODE != "ObjectMetadata"&&ENCRYPTPTION_STORAGE_MODE!="InstructionFile"){
67
+		if (ENCRYPTPTION_STORAGE_MODE != "ObjectMetadata" && ENCRYPTPTION_STORAGE_MODE != "InstructionFile") {
68 68
 			throw new Ks3ClientException("unsupported encryption storage mode :".ENCRYPTPTION_STORAGE_MODE);
69 69
 		}
70 70
 	}
71 71
 
72
-	public function putObjectByContent($args=array()){
72
+	public function putObjectByContent($args = array()) {
73 73
 		return $this->encryptionHandler->putObjectByContentSecurely($args);
74 74
 	}
75
-	public function putObjectByFile($args=array()){
75
+	public function putObjectByFile($args = array()) {
76 76
 		return $this->encryptionHandler->putObjectByFileSecurely($args);
77 77
 	}
78
-	public function getObject($args=array()){
78
+	public function getObject($args = array()) {
79 79
 		return $this->encryptionHandler->getObjectSecurely($args);
80 80
 	}
81
-	public function initMultipartUpload($args=array()){
81
+	public function initMultipartUpload($args = array()) {
82 82
 		return $this->encryptionHandler->initMultipartUploadSecurely($args);
83 83
 	}
84
-	public function uploadPart($args=array()){
84
+	public function uploadPart($args = array()) {
85 85
 		return $this->encryptionHandler->uploadPartSecurely($args);
86 86
 	}
87
-	public function abortMultipartUpload($args=array()){
87
+	public function abortMultipartUpload($args = array()) {
88 88
 		return $this->encryptionHandler->abortMultipartUploadSecurely($args);
89 89
 	}
90
-	public function completeMultipartUpload($args=array()){
90
+	public function completeMultipartUpload($args = array()) {
91 91
 		return $this->encryptionHandler->completeMultipartUploadSecurely($args);
92 92
 	}
93
-	public function deleteObject($args=array()){
93
+	public function deleteObject($args = array()) {
94 94
 		$result = parent::deleteObject($args);
95 95
 		$args["Key"] = $args["Key"].EncryptionUtil::$INSTRUCTION_SUFFIX;
96 96
 		try {
@@ -100,17 +100,17 @@  discard block
 block discarded – undo
100 100
 		}
101 101
 		return $result;
102 102
 	}
103
-	public function copyObject($args=array()){
104
-		if(parent::objectExists(array(
103
+	public function copyObject($args = array()) {
104
+		if (parent::objectExists(array(
105 105
 			"Bucket"=>$args["Bucket"],
106 106
 			"Key"=>$args["Key"]
107
-			))){
107
+			))) {
108 108
 			throw new Ks3ClientException("copy object faild,destination object exists");
109 109
 		}
110
-		if(parent::objectExists(array(
110
+		if (parent::objectExists(array(
111 111
 			"Bucket"=>$args["CopySource"]["Bucket"],
112 112
 			"Key"=>$args["CopySource"]["Key"].EncryptionUtil::$INSTRUCTION_SUFFIX
113
-			))){
113
+			))) {
114 114
 			parent::copyObject(
115 115
 				array(
116 116
 					"Bucket"=>$args["Bucket"],
Please login to merge, or discard this patch.
Braces   +20 added lines, -16 removed lines patch added patch discarded remove patch
@@ -1,21 +1,24 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 //使用客户端加密的方式上传下载文件
3 3
 //检测API路径
4
-if(!defined('KS3_API_PATH'))
5
-define('KS3_API_PATH', dirname(__FILE__));
4
+if(!defined('KS3_API_PATH')) {
5
+    define('KS3_API_PATH', dirname(__FILE__));
6
+}
6 7
 require_once KS3_API_PATH.DIRECTORY_SEPARATOR."Ks3Client.class.php";
7 8
 require_once KS3_API_PATH.DIRECTORY_SEPARATOR."encryption".DIRECTORY_SEPARATOR."EncryptionUtil.php";
8 9
 require_once KS3_API_PATH.DIRECTORY_SEPARATOR."encryption".DIRECTORY_SEPARATOR."EncryptionHandlers.php";
9 10
 
10 11
 //加密模式
11 12
 //暂时仅支持EO,使用AES/CBC/PKCS5Padding算法对数据进行加密
12
-if(!defined("ENCRYPTPTION_MODE"))
13
-define("ENCRYPTPTION_MODE","EO");
13
+if(!defined("ENCRYPTPTION_MODE")) {
14
+    define("ENCRYPTPTION_MODE","EO");
15
+}
14 16
 //加密信息存储模式,暂时支持 ObjectMetadata和InstructionFile
15 17
 //ObjectMetadata:存在用户元数据中
16 18
 //InstructionFile:存在一个.instruction文件中
17
-if(!defined("ENCRYPTPTION_STORAGE_MODE"))
18
-define("ENCRYPTPTION_STORAGE_MODE","ObjectMetadata");
19
+if(!defined("ENCRYPTPTION_STORAGE_MODE")) {
20
+    define("ENCRYPTPTION_STORAGE_MODE","ObjectMetadata");
21
+}
19 22
 
20 23
 
21 24
 if(function_exists('get_loaded_extensions')){
@@ -28,10 +31,10 @@  discard block
 block discarded – undo
28 31
 		if(!in_array('openssl', $extensions)){
29 32
 			throw new Ks3ClientException("please install openssl extension");
30 33
 		}
31
-	}else{
34
+	} else{
32 35
 		throw new Ks3ClientException("please install extensions");
33 36
 	}
34
-}else{
37
+} else{
35 38
 	throw new Ks3ClientException();
36 39
 } 
37 40
 class Ks3EncryptionClient extends Ks3Client{
@@ -45,12 +48,14 @@  discard block
 block discarded – undo
45 48
 			if(count($encryptionMaterials)==2){
46 49
 				$pk = openssl_pkey_get_public($encryptionMaterials[0]);
47 50
 				$sk = openssl_pkey_get_private($encryptionMaterials[1]);
48
-				if(!$pk)
49
-					throw new Ks3ClientException("invalid RSA public key,you can generate key use openssl");
50
-				if(!$sk)
51
-					throw new Ks3ClientException("invalid RSA private key,you can generate key use openssl");
51
+				if(!$pk) {
52
+									throw new Ks3ClientException("invalid RSA public key,you can generate key use openssl");
53
+				}
54
+				if(!$sk) {
55
+									throw new Ks3ClientException("invalid RSA private key,you can generate key use openssl");
56
+				}
52 57
 				$encryptionMaterials = array($pk,$sk);
53
-			}else{
58
+			} else{
54 59
 				throw new Ks3ClientException("encryptionMaterials should be string or an array of size 2");
55 60
 			}
56 61
 		}
@@ -58,10 +63,9 @@  discard block
 block discarded – undo
58 63
 		$this->encryptionMaterials = $encryptionMaterials;
59 64
 		if(ENCRYPTPTION_MODE == "EO"){
60 65
 			$this->encryptionHandler = new EncryptionEO($ks3client,$encryptionMaterials);
61
-		}elseif (ENCRYPTPTION_MODE == "AE") {
66
+		} elseif (ENCRYPTPTION_MODE == "AE") {
62 67
 			throw new Ks3ClientException("Authenticated encryption will be supported in the futher");
63
-		}
64
-		else{
68
+		} else{
65 69
 			throw new Ks3ClientException("unsupported encryption mode :".ENCRYPTPTION_MODE);
66 70
 		}
67 71
 		if(ENCRYPTPTION_STORAGE_MODE != "ObjectMetadata"&&ENCRYPTPTION_STORAGE_MODE!="InstructionFile"){
Please login to merge, or discard this patch.