@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | public static function verify_certificate($host, $cert) { |
33 | 33 | // Calculate the valid wildcard match if the host is not an IP address |
34 | 34 | $parts = explode('.', $host); |
35 | - if (ip2long($host) === false) { |
|
35 | + if(ip2long($host) === false) { |
|
36 | 36 | $parts[0] = '*'; |
37 | 37 | } |
38 | 38 | $wildcard = implode('.', $parts); |
@@ -40,11 +40,11 @@ discard block |
||
40 | 40 | $has_dns_alt = false; |
41 | 41 | |
42 | 42 | // Check the subjectAltName |
43 | - if (!empty($cert['extensions']) && !empty($cert['extensions']['subjectAltName'])) { |
|
43 | + if(!empty($cert['extensions']) && !empty($cert['extensions']['subjectAltName'])) { |
|
44 | 44 | $altnames = explode(',', $cert['extensions']['subjectAltName']); |
45 | - foreach ($altnames as $altname) { |
|
45 | + foreach($altnames as $altname) { |
|
46 | 46 | $altname = trim($altname); |
47 | - if (strpos($altname, 'DNS:') !== 0) { |
|
47 | + if(strpos($altname, 'DNS:') !== 0) { |
|
48 | 48 | continue; |
49 | 49 | } |
50 | 50 | |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | $altname = trim(substr($altname, 4)); |
55 | 55 | |
56 | 56 | // Check for a match |
57 | - if (self::match_domain($host, $altname) === true) { |
|
57 | + if(self::match_domain($host, $altname) === true) { |
|
58 | 58 | return true; |
59 | 59 | } |
60 | 60 | } |
@@ -62,9 +62,9 @@ discard block |
||
62 | 62 | |
63 | 63 | // Fall back to checking the common name if we didn't get any dNSName |
64 | 64 | // alt names, as per RFC2818 |
65 | - if (!$has_dns_alt && !empty($cert['subject']['CN'])) { |
|
65 | + if(!$has_dns_alt && !empty($cert['subject']['CN'])) { |
|
66 | 66 | // Check for a match |
67 | - if (self::match_domain($host, $cert['subject']['CN']) === true) { |
|
67 | + if(self::match_domain($host, $cert['subject']['CN']) === true) { |
|
68 | 68 | return true; |
69 | 69 | } |
70 | 70 | } |
@@ -94,21 +94,21 @@ discard block |
||
94 | 94 | // Check the first part of the name |
95 | 95 | $first = array_shift($parts); |
96 | 96 | |
97 | - if (strpos($first, '*') !== false) { |
|
97 | + if(strpos($first, '*') !== false) { |
|
98 | 98 | // Check that the wildcard is the full part |
99 | - if ($first !== '*') { |
|
99 | + if($first !== '*') { |
|
100 | 100 | return false; |
101 | 101 | } |
102 | 102 | |
103 | 103 | // Check that we have at least 3 components (including first) |
104 | - if (count($parts) < 2) { |
|
104 | + if(count($parts) < 2) { |
|
105 | 105 | return false; |
106 | 106 | } |
107 | 107 | } |
108 | 108 | |
109 | 109 | // Check the remaining parts |
110 | - foreach ($parts as $part) { |
|
111 | - if (strpos($part, '*') !== false) { |
|
110 | + foreach($parts as $part) { |
|
111 | + if(strpos($part, '*') !== false) { |
|
112 | 112 | return false; |
113 | 113 | } |
114 | 114 | } |
@@ -126,23 +126,23 @@ discard block |
||
126 | 126 | */ |
127 | 127 | public static function match_domain($host, $reference) { |
128 | 128 | // Check if the reference is blacklisted first |
129 | - if (self::verify_reference_name($reference) !== true) { |
|
129 | + if(self::verify_reference_name($reference) !== true) { |
|
130 | 130 | return false; |
131 | 131 | } |
132 | 132 | |
133 | 133 | // Check for a direct match |
134 | - if ($host === $reference) { |
|
134 | + if($host === $reference) { |
|
135 | 135 | return true; |
136 | 136 | } |
137 | 137 | |
138 | 138 | // Calculate the valid wildcard match if the host is not an IP address |
139 | 139 | // Also validates that the host has 3 parts or more, as per Firefox's |
140 | 140 | // ruleset. |
141 | - if (ip2long($host) === false) { |
|
141 | + if(ip2long($host) === false) { |
|
142 | 142 | $parts = explode('.', $host); |
143 | 143 | $parts[0] = '*'; |
144 | 144 | $wildcard = implode('.', $parts); |
145 | - if ($wildcard === $reference) { |
|
145 | + if($wildcard === $reference) { |
|
146 | 146 | return true; |
147 | 147 | } |
148 | 148 | } |
@@ -14,7 +14,8 @@ discard block |
||
14 | 14 | * @package Requests |
15 | 15 | * @subpackage Utilities |
16 | 16 | */ |
17 | -class Requests_SSL { |
|
17 | +class Requests_SSL |
|
18 | +{ |
|
18 | 19 | /** |
19 | 20 | * Verify the certificate against common name and subject alternative names |
20 | 21 | * |
@@ -29,10 +30,12 @@ discard block |
||
29 | 30 | * @param array $cert Certificate data from openssl_x509_parse() |
30 | 31 | * @return bool |
31 | 32 | */ |
32 | - public static function verify_certificate($host, $cert) { |
|
33 | + public static function verify_certificate($host, $cert) |
|
34 | + { |
|
33 | 35 | // Calculate the valid wildcard match if the host is not an IP address |
34 | 36 | $parts = explode('.', $host); |
35 | - if (ip2long($host) === false) { |
|
37 | + if (ip2long($host) === false) |
|
38 | + { |
|
36 | 39 | $parts[0] = '*'; |
37 | 40 | } |
38 | 41 | $wildcard = implode('.', $parts); |
@@ -40,11 +43,14 @@ discard block |
||
40 | 43 | $has_dns_alt = false; |
41 | 44 | |
42 | 45 | // Check the subjectAltName |
43 | - if (!empty($cert['extensions']) && !empty($cert['extensions']['subjectAltName'])) { |
|
46 | + if (!empty($cert['extensions']) && !empty($cert['extensions']['subjectAltName'])) |
|
47 | + { |
|
44 | 48 | $altnames = explode(',', $cert['extensions']['subjectAltName']); |
45 | - foreach ($altnames as $altname) { |
|
49 | + foreach ($altnames as $altname) |
|
50 | + { |
|
46 | 51 | $altname = trim($altname); |
47 | - if (strpos($altname, 'DNS:') !== 0) { |
|
52 | + if (strpos($altname, 'DNS:') !== 0) |
|
53 | + { |
|
48 | 54 | continue; |
49 | 55 | } |
50 | 56 | |
@@ -54,7 +60,8 @@ discard block |
||
54 | 60 | $altname = trim(substr($altname, 4)); |
55 | 61 | |
56 | 62 | // Check for a match |
57 | - if (self::match_domain($host, $altname) === true) { |
|
63 | + if (self::match_domain($host, $altname) === true) |
|
64 | + { |
|
58 | 65 | return true; |
59 | 66 | } |
60 | 67 | } |
@@ -62,9 +69,11 @@ discard block |
||
62 | 69 | |
63 | 70 | // Fall back to checking the common name if we didn't get any dNSName |
64 | 71 | // alt names, as per RFC2818 |
65 | - if (!$has_dns_alt && !empty($cert['subject']['CN'])) { |
|
72 | + if (!$has_dns_alt && !empty($cert['subject']['CN'])) |
|
73 | + { |
|
66 | 74 | // Check for a match |
67 | - if (self::match_domain($host, $cert['subject']['CN']) === true) { |
|
75 | + if (self::match_domain($host, $cert['subject']['CN']) === true) |
|
76 | + { |
|
68 | 77 | return true; |
69 | 78 | } |
70 | 79 | } |
@@ -88,27 +97,33 @@ discard block |
||
88 | 97 | * @param string $reference Reference dNSName |
89 | 98 | * @return boolean Is the name valid? |
90 | 99 | */ |
91 | - public static function verify_reference_name($reference) { |
|
100 | + public static function verify_reference_name($reference) |
|
101 | + { |
|
92 | 102 | $parts = explode('.', $reference); |
93 | 103 | |
94 | 104 | // Check the first part of the name |
95 | 105 | $first = array_shift($parts); |
96 | 106 | |
97 | - if (strpos($first, '*') !== false) { |
|
107 | + if (strpos($first, '*') !== false) |
|
108 | + { |
|
98 | 109 | // Check that the wildcard is the full part |
99 | - if ($first !== '*') { |
|
110 | + if ($first !== '*') |
|
111 | + { |
|
100 | 112 | return false; |
101 | 113 | } |
102 | 114 | |
103 | 115 | // Check that we have at least 3 components (including first) |
104 | - if (count($parts) < 2) { |
|
116 | + if (count($parts) < 2) |
|
117 | + { |
|
105 | 118 | return false; |
106 | 119 | } |
107 | 120 | } |
108 | 121 | |
109 | 122 | // Check the remaining parts |
110 | - foreach ($parts as $part) { |
|
111 | - if (strpos($part, '*') !== false) { |
|
123 | + foreach ($parts as $part) |
|
124 | + { |
|
125 | + if (strpos($part, '*') !== false) |
|
126 | + { |
|
112 | 127 | return false; |
113 | 128 | } |
114 | 129 | } |
@@ -124,25 +139,30 @@ discard block |
||
124 | 139 | * @param string $reference dNSName to match against |
125 | 140 | * @return boolean Does the domain match? |
126 | 141 | */ |
127 | - public static function match_domain($host, $reference) { |
|
142 | + public static function match_domain($host, $reference) |
|
143 | + { |
|
128 | 144 | // Check if the reference is blacklisted first |
129 | - if (self::verify_reference_name($reference) !== true) { |
|
145 | + if (self::verify_reference_name($reference) !== true) |
|
146 | + { |
|
130 | 147 | return false; |
131 | 148 | } |
132 | 149 | |
133 | 150 | // Check for a direct match |
134 | - if ($host === $reference) { |
|
151 | + if ($host === $reference) |
|
152 | + { |
|
135 | 153 | return true; |
136 | 154 | } |
137 | 155 | |
138 | 156 | // Calculate the valid wildcard match if the host is not an IP address |
139 | 157 | // Also validates that the host has 3 parts or more, as per Firefox's |
140 | 158 | // ruleset. |
141 | - if (ip2long($host) === false) { |
|
159 | + if (ip2long($host) === false) |
|
160 | + { |
|
142 | 161 | $parts = explode('.', $host); |
143 | 162 | $parts[0] = '*'; |
144 | 163 | $wildcard = implode('.', $parts); |
145 | - if ($wildcard === $reference) { |
|
164 | + if ($wildcard === $reference) |
|
165 | + { |
|
146 | 166 | return true; |
147 | 167 | } |
148 | 168 | } |
@@ -32,12 +32,12 @@ discard block |
||
32 | 32 | public static function verify_certificate($host, $cert) { |
33 | 33 | // Calculate the valid wildcard match if the host is not an IP address |
34 | 34 | $parts = explode('.', $host); |
35 | - if (ip2long($host) === false) { |
|
35 | + if (ip2long($host) === FALSE) { |
|
36 | 36 | $parts[0] = '*'; |
37 | 37 | } |
38 | 38 | $wildcard = implode('.', $parts); |
39 | 39 | |
40 | - $has_dns_alt = false; |
|
40 | + $has_dns_alt = FALSE; |
|
41 | 41 | |
42 | 42 | // Check the subjectAltName |
43 | 43 | if (!empty($cert['extensions']) && !empty($cert['extensions']['subjectAltName'])) { |
@@ -48,14 +48,14 @@ discard block |
||
48 | 48 | continue; |
49 | 49 | } |
50 | 50 | |
51 | - $has_dns_alt = true; |
|
51 | + $has_dns_alt = TRUE; |
|
52 | 52 | |
53 | 53 | // Strip the 'DNS:' prefix and trim whitespace |
54 | 54 | $altname = trim(substr($altname, 4)); |
55 | 55 | |
56 | 56 | // Check for a match |
57 | - if (self::match_domain($host, $altname) === true) { |
|
58 | - return true; |
|
57 | + if (self::match_domain($host, $altname) === TRUE) { |
|
58 | + return TRUE; |
|
59 | 59 | } |
60 | 60 | } |
61 | 61 | } |
@@ -64,12 +64,12 @@ discard block |
||
64 | 64 | // alt names, as per RFC2818 |
65 | 65 | if (!$has_dns_alt && !empty($cert['subject']['CN'])) { |
66 | 66 | // Check for a match |
67 | - if (self::match_domain($host, $cert['subject']['CN']) === true) { |
|
68 | - return true; |
|
67 | + if (self::match_domain($host, $cert['subject']['CN']) === TRUE) { |
|
68 | + return TRUE; |
|
69 | 69 | } |
70 | 70 | } |
71 | 71 | |
72 | - return false; |
|
72 | + return FALSE; |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
@@ -94,27 +94,27 @@ discard block |
||
94 | 94 | // Check the first part of the name |
95 | 95 | $first = array_shift($parts); |
96 | 96 | |
97 | - if (strpos($first, '*') !== false) { |
|
97 | + if (strpos($first, '*') !== FALSE) { |
|
98 | 98 | // Check that the wildcard is the full part |
99 | 99 | if ($first !== '*') { |
100 | - return false; |
|
100 | + return FALSE; |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | // Check that we have at least 3 components (including first) |
104 | 104 | if (count($parts) < 2) { |
105 | - return false; |
|
105 | + return FALSE; |
|
106 | 106 | } |
107 | 107 | } |
108 | 108 | |
109 | 109 | // Check the remaining parts |
110 | 110 | foreach ($parts as $part) { |
111 | - if (strpos($part, '*') !== false) { |
|
112 | - return false; |
|
111 | + if (strpos($part, '*') !== FALSE) { |
|
112 | + return FALSE; |
|
113 | 113 | } |
114 | 114 | } |
115 | 115 | |
116 | 116 | // Nothing found, verified! |
117 | - return true; |
|
117 | + return TRUE; |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
@@ -126,27 +126,27 @@ discard block |
||
126 | 126 | */ |
127 | 127 | public static function match_domain($host, $reference) { |
128 | 128 | // Check if the reference is blacklisted first |
129 | - if (self::verify_reference_name($reference) !== true) { |
|
130 | - return false; |
|
129 | + if (self::verify_reference_name($reference) !== TRUE) { |
|
130 | + return FALSE; |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | // Check for a direct match |
134 | 134 | if ($host === $reference) { |
135 | - return true; |
|
135 | + return TRUE; |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | // Calculate the valid wildcard match if the host is not an IP address |
139 | 139 | // Also validates that the host has 3 parts or more, as per Firefox's |
140 | 140 | // ruleset. |
141 | - if (ip2long($host) === false) { |
|
141 | + if (ip2long($host) === FALSE) { |
|
142 | 142 | $parts = explode('.', $host); |
143 | 143 | $parts[0] = '*'; |
144 | 144 | $wildcard = implode('.', $parts); |
145 | 145 | if ($wildcard === $reference) { |
146 | - return true; |
|
146 | + return TRUE; |
|
147 | 147 | } |
148 | 148 | } |
149 | 149 | |
150 | - return false; |
|
150 | + return FALSE; |
|
151 | 151 | } |
152 | 152 | } |
153 | 153 | \ No newline at end of file |
@@ -35,28 +35,28 @@ discard block |
||
35 | 35 | * @return string The uncompressed IPv6 address |
36 | 36 | */ |
37 | 37 | public static function uncompress($ip) { |
38 | - if (substr_count($ip, '::') !== 1) { |
|
38 | + if(substr_count($ip, '::') !== 1) { |
|
39 | 39 | return $ip; |
40 | 40 | } |
41 | 41 | |
42 | 42 | list($ip1, $ip2) = explode('::', $ip); |
43 | - $c1 = ($ip1 === '') ? -1 : substr_count($ip1, ':'); |
|
44 | - $c2 = ($ip2 === '') ? -1 : substr_count($ip2, ':'); |
|
43 | + $c1 = ($ip1 === '')? -1 : substr_count($ip1, ':'); |
|
44 | + $c2 = ($ip2 === '')? -1 : substr_count($ip2, ':'); |
|
45 | 45 | |
46 | - if (strpos($ip2, '.') !== false) { |
|
46 | + if(strpos($ip2, '.') !== false) { |
|
47 | 47 | $c2++; |
48 | 48 | } |
49 | 49 | // :: |
50 | - if ($c1 === -1 && $c2 === -1) { |
|
50 | + if($c1 === -1 && $c2 === -1) { |
|
51 | 51 | $ip = '0:0:0:0:0:0:0:0'; |
52 | 52 | } |
53 | 53 | // ::xxx |
54 | - else if ($c1 === -1) { |
|
54 | + else if($c1 === -1) { |
|
55 | 55 | $fill = str_repeat('0:', 7 - $c2); |
56 | 56 | $ip = str_replace('::', $fill, $ip); |
57 | 57 | } |
58 | 58 | // xxx:: |
59 | - else if ($c2 === -1) { |
|
59 | + else if($c2 === -1) { |
|
60 | 60 | $fill = str_repeat(':0', 7 - $c1); |
61 | 61 | $ip = str_replace('::', $fill, $ip); |
62 | 62 | } |
@@ -91,11 +91,11 @@ discard block |
||
91 | 91 | $ip_parts[0] = preg_replace('/(^|:)0+([0-9])/', '\1\2', $ip_parts[0]); |
92 | 92 | |
93 | 93 | // Find bunches of zeros |
94 | - if (preg_match_all('/(?:^|:)(?:0(?::|$))+/', $ip_parts[0], $matches, PREG_OFFSET_CAPTURE)) { |
|
94 | + if(preg_match_all('/(?:^|:)(?:0(?::|$))+/', $ip_parts[0], $matches, PREG_OFFSET_CAPTURE)) { |
|
95 | 95 | $max = 0; |
96 | 96 | $pos = null; |
97 | - foreach ($matches[0] as $match) { |
|
98 | - if (strlen($match[0]) > $max) { |
|
97 | + foreach($matches[0] as $match) { |
|
98 | + if(strlen($match[0]) > $max) { |
|
99 | 99 | $max = strlen($match[0]); |
100 | 100 | $pos = $match[1]; |
101 | 101 | } |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | $ip_parts[0] = substr_replace($ip_parts[0], '::', $pos, $max); |
105 | 105 | } |
106 | 106 | |
107 | - if ($ip_parts[1] !== '') { |
|
107 | + if($ip_parts[1] !== '') { |
|
108 | 108 | return implode(':', $ip_parts); |
109 | 109 | } |
110 | 110 | else { |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | * @return string[] [0] contains the IPv6 represented part, and [1] the IPv4 represented part |
126 | 126 | */ |
127 | 127 | protected static function split_v6_v4($ip) { |
128 | - if (strpos($ip, '.') !== false) { |
|
128 | + if(strpos($ip, '.') !== false) { |
|
129 | 129 | $pos = strrpos($ip, ':'); |
130 | 130 | $ipv6_part = substr($ip, 0, $pos); |
131 | 131 | $ipv4_part = substr($ip, $pos + 1); |
@@ -149,34 +149,34 @@ discard block |
||
149 | 149 | list($ipv6, $ipv4) = self::split_v6_v4($ip); |
150 | 150 | $ipv6 = explode(':', $ipv6); |
151 | 151 | $ipv4 = explode('.', $ipv4); |
152 | - if (count($ipv6) === 8 && count($ipv4) === 1 || count($ipv6) === 6 && count($ipv4) === 4) { |
|
153 | - foreach ($ipv6 as $ipv6_part) { |
|
152 | + if(count($ipv6) === 8 && count($ipv4) === 1 || count($ipv6) === 6 && count($ipv4) === 4) { |
|
153 | + foreach($ipv6 as $ipv6_part) { |
|
154 | 154 | // The section can't be empty |
155 | - if ($ipv6_part === '') { |
|
155 | + if($ipv6_part === '') { |
|
156 | 156 | return false; |
157 | 157 | } |
158 | 158 | |
159 | 159 | // Nor can it be over four characters |
160 | - if (strlen($ipv6_part) > 4) { |
|
160 | + if(strlen($ipv6_part) > 4) { |
|
161 | 161 | return false; |
162 | 162 | } |
163 | 163 | |
164 | 164 | // Remove leading zeros (this is safe because of the above) |
165 | 165 | $ipv6_part = ltrim($ipv6_part, '0'); |
166 | - if ($ipv6_part === '') { |
|
166 | + if($ipv6_part === '') { |
|
167 | 167 | $ipv6_part = '0'; |
168 | 168 | } |
169 | 169 | |
170 | 170 | // Check the value is valid |
171 | 171 | $value = hexdec($ipv6_part); |
172 | - if (dechex($value) !== strtolower($ipv6_part) || $value < 0 || $value > 0xFFFF) { |
|
172 | + if(dechex($value) !== strtolower($ipv6_part) || $value < 0 || $value > 0xFFFF) { |
|
173 | 173 | return false; |
174 | 174 | } |
175 | 175 | } |
176 | - if (count($ipv4) === 4) { |
|
177 | - foreach ($ipv4 as $ipv4_part) { |
|
178 | - $value = (int) $ipv4_part; |
|
179 | - if ((string) $value !== $ipv4_part || $value < 0 || $value > 0xFF) { |
|
176 | + if(count($ipv4) === 4) { |
|
177 | + foreach($ipv4 as $ipv4_part) { |
|
178 | + $value = (int)$ipv4_part; |
|
179 | + if((string)$value !== $ipv4_part || $value < 0 || $value > 0xFF) { |
|
180 | 180 | return false; |
181 | 181 | } |
182 | 182 | } |
@@ -15,7 +15,8 @@ discard block |
||
15 | 15 | * @package Requests |
16 | 16 | * @subpackage Utilities |
17 | 17 | */ |
18 | -class Requests_IPv6 { |
|
18 | +class Requests_IPv6 |
|
19 | +{ |
|
19 | 20 | /** |
20 | 21 | * Uncompresses an IPv6 address |
21 | 22 | * |
@@ -34,8 +35,10 @@ discard block |
||
34 | 35 | * @param string $ip An IPv6 address |
35 | 36 | * @return string The uncompressed IPv6 address |
36 | 37 | */ |
37 | - public static function uncompress($ip) { |
|
38 | - if (substr_count($ip, '::') !== 1) { |
|
38 | + public static function uncompress($ip) |
|
39 | + { |
|
40 | + if (substr_count($ip, '::') !== 1) |
|
41 | + { |
|
39 | 42 | return $ip; |
40 | 43 | } |
41 | 44 | |
@@ -43,25 +46,30 @@ discard block |
||
43 | 46 | $c1 = ($ip1 === '') ? -1 : substr_count($ip1, ':'); |
44 | 47 | $c2 = ($ip2 === '') ? -1 : substr_count($ip2, ':'); |
45 | 48 | |
46 | - if (strpos($ip2, '.') !== false) { |
|
49 | + if (strpos($ip2, '.') !== false) |
|
50 | + { |
|
47 | 51 | $c2++; |
48 | 52 | } |
49 | 53 | // :: |
50 | - if ($c1 === -1 && $c2 === -1) { |
|
54 | + if ($c1 === -1 && $c2 === -1) |
|
55 | + { |
|
51 | 56 | $ip = '0:0:0:0:0:0:0:0'; |
52 | 57 | } |
53 | 58 | // ::xxx |
54 | - else if ($c1 === -1) { |
|
59 | + else if ($c1 === -1) |
|
60 | + { |
|
55 | 61 | $fill = str_repeat('0:', 7 - $c2); |
56 | 62 | $ip = str_replace('::', $fill, $ip); |
57 | 63 | } |
58 | 64 | // xxx:: |
59 | - else if ($c2 === -1) { |
|
65 | + else if ($c2 === -1) |
|
66 | + { |
|
60 | 67 | $fill = str_repeat(':0', 7 - $c1); |
61 | 68 | $ip = str_replace('::', $fill, $ip); |
62 | 69 | } |
63 | 70 | // xxx::xxx |
64 | - else { |
|
71 | + else |
|
72 | + { |
|
65 | 73 | $fill = ':' . str_repeat('0:', 6 - $c2 - $c1); |
66 | 74 | $ip = str_replace('::', $fill, $ip); |
67 | 75 | } |
@@ -82,7 +90,8 @@ discard block |
||
82 | 90 | * @param string $ip An IPv6 address |
83 | 91 | * @return string The compressed IPv6 address |
84 | 92 | */ |
85 | - public static function compress($ip) { |
|
93 | + public static function compress($ip) |
|
94 | + { |
|
86 | 95 | // Prepare the IP to be compressed |
87 | 96 | $ip = self::uncompress($ip); |
88 | 97 | $ip_parts = self::split_v6_v4($ip); |
@@ -91,11 +100,14 @@ discard block |
||
91 | 100 | $ip_parts[0] = preg_replace('/(^|:)0+([0-9])/', '\1\2', $ip_parts[0]); |
92 | 101 | |
93 | 102 | // Find bunches of zeros |
94 | - if (preg_match_all('/(?:^|:)(?:0(?::|$))+/', $ip_parts[0], $matches, PREG_OFFSET_CAPTURE)) { |
|
103 | + if (preg_match_all('/(?:^|:)(?:0(?::|$))+/', $ip_parts[0], $matches, PREG_OFFSET_CAPTURE)) |
|
104 | + { |
|
95 | 105 | $max = 0; |
96 | 106 | $pos = null; |
97 | - foreach ($matches[0] as $match) { |
|
98 | - if (strlen($match[0]) > $max) { |
|
107 | + foreach ($matches[0] as $match) |
|
108 | + { |
|
109 | + if (strlen($match[0]) > $max) |
|
110 | + { |
|
99 | 111 | $max = strlen($match[0]); |
100 | 112 | $pos = $match[1]; |
101 | 113 | } |
@@ -104,10 +116,12 @@ discard block |
||
104 | 116 | $ip_parts[0] = substr_replace($ip_parts[0], '::', $pos, $max); |
105 | 117 | } |
106 | 118 | |
107 | - if ($ip_parts[1] !== '') { |
|
119 | + if ($ip_parts[1] !== '') |
|
120 | + { |
|
108 | 121 | return implode(':', $ip_parts); |
109 | 122 | } |
110 | - else { |
|
123 | + else |
|
124 | + { |
|
111 | 125 | return $ip_parts[0]; |
112 | 126 | } |
113 | 127 | } |
@@ -124,14 +138,17 @@ discard block |
||
124 | 138 | * @param string $ip An IPv6 address |
125 | 139 | * @return string[] [0] contains the IPv6 represented part, and [1] the IPv4 represented part |
126 | 140 | */ |
127 | - protected static function split_v6_v4($ip) { |
|
128 | - if (strpos($ip, '.') !== false) { |
|
141 | + protected static function split_v6_v4($ip) |
|
142 | + { |
|
143 | + if (strpos($ip, '.') !== false) |
|
144 | + { |
|
129 | 145 | $pos = strrpos($ip, ':'); |
130 | 146 | $ipv6_part = substr($ip, 0, $pos); |
131 | 147 | $ipv4_part = substr($ip, $pos + 1); |
132 | 148 | return array($ipv6_part, $ipv4_part); |
133 | 149 | } |
134 | - else { |
|
150 | + else |
|
151 | + { |
|
135 | 152 | return array($ip, ''); |
136 | 153 | } |
137 | 154 | } |
@@ -144,46 +161,57 @@ discard block |
||
144 | 161 | * @param string $ip An IPv6 address |
145 | 162 | * @return bool true if $ip is a valid IPv6 address |
146 | 163 | */ |
147 | - public static function check_ipv6($ip) { |
|
164 | + public static function check_ipv6($ip) |
|
165 | + { |
|
148 | 166 | $ip = self::uncompress($ip); |
149 | 167 | list($ipv6, $ipv4) = self::split_v6_v4($ip); |
150 | 168 | $ipv6 = explode(':', $ipv6); |
151 | 169 | $ipv4 = explode('.', $ipv4); |
152 | - if (count($ipv6) === 8 && count($ipv4) === 1 || count($ipv6) === 6 && count($ipv4) === 4) { |
|
153 | - foreach ($ipv6 as $ipv6_part) { |
|
170 | + if (count($ipv6) === 8 && count($ipv4) === 1 || count($ipv6) === 6 && count($ipv4) === 4) |
|
171 | + { |
|
172 | + foreach ($ipv6 as $ipv6_part) |
|
173 | + { |
|
154 | 174 | // The section can't be empty |
155 | - if ($ipv6_part === '') { |
|
175 | + if ($ipv6_part === '') |
|
176 | + { |
|
156 | 177 | return false; |
157 | 178 | } |
158 | 179 | |
159 | 180 | // Nor can it be over four characters |
160 | - if (strlen($ipv6_part) > 4) { |
|
181 | + if (strlen($ipv6_part) > 4) |
|
182 | + { |
|
161 | 183 | return false; |
162 | 184 | } |
163 | 185 | |
164 | 186 | // Remove leading zeros (this is safe because of the above) |
165 | 187 | $ipv6_part = ltrim($ipv6_part, '0'); |
166 | - if ($ipv6_part === '') { |
|
188 | + if ($ipv6_part === '') |
|
189 | + { |
|
167 | 190 | $ipv6_part = '0'; |
168 | 191 | } |
169 | 192 | |
170 | 193 | // Check the value is valid |
171 | 194 | $value = hexdec($ipv6_part); |
172 | - if (dechex($value) !== strtolower($ipv6_part) || $value < 0 || $value > 0xFFFF) { |
|
195 | + if (dechex($value) !== strtolower($ipv6_part) || $value < 0 || $value > 0xFFFF) |
|
196 | + { |
|
173 | 197 | return false; |
174 | 198 | } |
175 | 199 | } |
176 | - if (count($ipv4) === 4) { |
|
177 | - foreach ($ipv4 as $ipv4_part) { |
|
200 | + if (count($ipv4) === 4) |
|
201 | + { |
|
202 | + foreach ($ipv4 as $ipv4_part) |
|
203 | + { |
|
178 | 204 | $value = (int) $ipv4_part; |
179 | - if ((string) $value !== $ipv4_part || $value < 0 || $value > 0xFF) { |
|
205 | + if ((string) $value !== $ipv4_part || $value < 0 || $value > 0xFF) |
|
206 | + { |
|
180 | 207 | return false; |
181 | 208 | } |
182 | 209 | } |
183 | 210 | } |
184 | 211 | return true; |
185 | 212 | } |
186 | - else { |
|
213 | + else |
|
214 | + { |
|
187 | 215 | return false; |
188 | 216 | } |
189 | 217 | } |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | $c1 = ($ip1 === '') ? -1 : substr_count($ip1, ':'); |
44 | 44 | $c2 = ($ip2 === '') ? -1 : substr_count($ip2, ':'); |
45 | 45 | |
46 | - if (strpos($ip2, '.') !== false) { |
|
46 | + if (strpos($ip2, '.') !== FALSE) { |
|
47 | 47 | $c2++; |
48 | 48 | } |
49 | 49 | // :: |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | // Find bunches of zeros |
94 | 94 | if (preg_match_all('/(?:^|:)(?:0(?::|$))+/', $ip_parts[0], $matches, PREG_OFFSET_CAPTURE)) { |
95 | 95 | $max = 0; |
96 | - $pos = null; |
|
96 | + $pos = NULL; |
|
97 | 97 | foreach ($matches[0] as $match) { |
98 | 98 | if (strlen($match[0]) > $max) { |
99 | 99 | $max = strlen($match[0]); |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | * @return string[] [0] contains the IPv6 represented part, and [1] the IPv4 represented part |
126 | 126 | */ |
127 | 127 | protected static function split_v6_v4($ip) { |
128 | - if (strpos($ip, '.') !== false) { |
|
128 | + if (strpos($ip, '.') !== FALSE) { |
|
129 | 129 | $pos = strrpos($ip, ':'); |
130 | 130 | $ipv6_part = substr($ip, 0, $pos); |
131 | 131 | $ipv4_part = substr($ip, $pos + 1); |
@@ -153,12 +153,12 @@ discard block |
||
153 | 153 | foreach ($ipv6 as $ipv6_part) { |
154 | 154 | // The section can't be empty |
155 | 155 | if ($ipv6_part === '') { |
156 | - return false; |
|
156 | + return FALSE; |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | // Nor can it be over four characters |
160 | 160 | if (strlen($ipv6_part) > 4) { |
161 | - return false; |
|
161 | + return FALSE; |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | // Remove leading zeros (this is safe because of the above) |
@@ -170,21 +170,21 @@ discard block |
||
170 | 170 | // Check the value is valid |
171 | 171 | $value = hexdec($ipv6_part); |
172 | 172 | if (dechex($value) !== strtolower($ipv6_part) || $value < 0 || $value > 0xFFFF) { |
173 | - return false; |
|
173 | + return FALSE; |
|
174 | 174 | } |
175 | 175 | } |
176 | 176 | if (count($ipv4) === 4) { |
177 | 177 | foreach ($ipv4 as $ipv4_part) { |
178 | 178 | $value = (int) $ipv4_part; |
179 | 179 | if ((string) $value !== $ipv4_part || $value < 0 || $value > 0xFF) { |
180 | - return false; |
|
180 | + return FALSE; |
|
181 | 181 | } |
182 | 182 | } |
183 | 183 | } |
184 | - return true; |
|
184 | + return TRUE; |
|
185 | 185 | } |
186 | 186 | else { |
187 | - return false; |
|
187 | + return FALSE; |
|
188 | 188 | } |
189 | 189 | } |
190 | 190 | } |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | */ |
26 | 26 | public function offsetGet($key) { |
27 | 27 | $key = strtolower($key); |
28 | - if (!isset($this->data[$key])) { |
|
28 | + if(!isset($this->data[$key])) { |
|
29 | 29 | return null; |
30 | 30 | } |
31 | 31 | |
@@ -41,13 +41,13 @@ discard block |
||
41 | 41 | * @param string $value Item value |
42 | 42 | */ |
43 | 43 | public function offsetSet($key, $value) { |
44 | - if ($key === null) { |
|
44 | + if($key === null) { |
|
45 | 45 | throw new Requests_Exception('Object is a dictionary, not a list', 'invalidset'); |
46 | 46 | } |
47 | 47 | |
48 | 48 | $key = strtolower($key); |
49 | 49 | |
50 | - if (!isset($this->data[$key])) { |
|
50 | + if(!isset($this->data[$key])) { |
|
51 | 51 | $this->data[$key] = array(); |
52 | 52 | } |
53 | 53 | |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | */ |
63 | 63 | public function getValues($key) { |
64 | 64 | $key = strtolower($key); |
65 | - if (!isset($this->data[$key])) { |
|
65 | + if(!isset($this->data[$key])) { |
|
66 | 66 | return null; |
67 | 67 | } |
68 | 68 | |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | * @return string Flattened value |
80 | 80 | */ |
81 | 81 | public function flatten($value) { |
82 | - if (is_array($value)) { |
|
82 | + if(is_array($value)) { |
|
83 | 83 | $value = implode(',', $value); |
84 | 84 | } |
85 | 85 |
@@ -10,7 +10,8 @@ discard block |
||
10 | 10 | * |
11 | 11 | * @package Requests |
12 | 12 | */ |
13 | -class Requests_Response_Headers extends Requests_Utility_CaseInsensitiveDictionary { |
|
13 | +class Requests_Response_Headers extends Requests_Utility_CaseInsensitiveDictionary |
|
14 | +{ |
|
14 | 15 | /** |
15 | 16 | * Get the given header |
16 | 17 | * |
@@ -23,9 +24,11 @@ discard block |
||
23 | 24 | * @param string $key |
24 | 25 | * @return string Header value |
25 | 26 | */ |
26 | - public function offsetGet($key) { |
|
27 | + public function offsetGet($key) |
|
28 | + { |
|
27 | 29 | $key = strtolower($key); |
28 | - if (!isset($this->data[$key])) { |
|
30 | + if (!isset($this->data[$key])) |
|
31 | + { |
|
29 | 32 | return null; |
30 | 33 | } |
31 | 34 | |
@@ -40,14 +43,17 @@ discard block |
||
40 | 43 | * @param string $key Item name |
41 | 44 | * @param string $value Item value |
42 | 45 | */ |
43 | - public function offsetSet($key, $value) { |
|
44 | - if ($key === null) { |
|
46 | + public function offsetSet($key, $value) |
|
47 | + { |
|
48 | + if ($key === null) |
|
49 | + { |
|
45 | 50 | throw new Requests_Exception('Object is a dictionary, not a list', 'invalidset'); |
46 | 51 | } |
47 | 52 | |
48 | 53 | $key = strtolower($key); |
49 | 54 | |
50 | - if (!isset($this->data[$key])) { |
|
55 | + if (!isset($this->data[$key])) |
|
56 | + { |
|
51 | 57 | $this->data[$key] = array(); |
52 | 58 | } |
53 | 59 | |
@@ -60,9 +66,11 @@ discard block |
||
60 | 66 | * @param string $key |
61 | 67 | * @return array Header values |
62 | 68 | */ |
63 | - public function getValues($key) { |
|
69 | + public function getValues($key) |
|
70 | + { |
|
64 | 71 | $key = strtolower($key); |
65 | - if (!isset($this->data[$key])) { |
|
72 | + if (!isset($this->data[$key])) |
|
73 | + { |
|
66 | 74 | return null; |
67 | 75 | } |
68 | 76 | |
@@ -78,8 +86,10 @@ discard block |
||
78 | 86 | * @param string|array $value Value to flatten |
79 | 87 | * @return string Flattened value |
80 | 88 | */ |
81 | - public function flatten($value) { |
|
82 | - if (is_array($value)) { |
|
89 | + public function flatten($value) |
|
90 | + { |
|
91 | + if (is_array($value)) |
|
92 | + { |
|
83 | 93 | $value = implode(',', $value); |
84 | 94 | } |
85 | 95 | |
@@ -92,7 +102,8 @@ discard block |
||
92 | 102 | * Converts the internal |
93 | 103 | * @return ArrayIterator |
94 | 104 | */ |
95 | - public function getIterator() { |
|
105 | + public function getIterator() |
|
106 | + { |
|
96 | 107 | return new Requests_Utility_FilteredIterator($this->data, array($this, 'flatten')); |
97 | 108 | } |
98 | 109 | } |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | public function offsetGet($key) { |
27 | 27 | $key = strtolower($key); |
28 | 28 | if (!isset($this->data[$key])) { |
29 | - return null; |
|
29 | + return NULL; |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | return $this->flatten($this->data[$key]); |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | * @param string $value Item value |
42 | 42 | */ |
43 | 43 | public function offsetSet($key, $value) { |
44 | - if ($key === null) { |
|
44 | + if ($key === NULL) { |
|
45 | 45 | throw new Requests_Exception('Object is a dictionary, not a list', 'invalidset'); |
46 | 46 | } |
47 | 47 | |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | public function getValues($key) { |
64 | 64 | $key = strtolower($key); |
65 | 65 | if (!isset($this->data[$key])) { |
66 | - return null; |
|
66 | + return NULL; |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | return $this->data[$key]; |
@@ -108,12 +108,12 @@ |
||
108 | 108 | * @param boolean $allow_redirects Set to false to throw on a 3xx as well |
109 | 109 | */ |
110 | 110 | public function throw_for_status($allow_redirects = true) { |
111 | - if ($this->is_redirect()) { |
|
112 | - if (!$allow_redirects) { |
|
111 | + if($this->is_redirect()) { |
|
112 | + if(!$allow_redirects) { |
|
113 | 113 | throw new Requests_Exception('Redirection not allowed', 'response.no_redirects', $this); |
114 | 114 | } |
115 | 115 | } |
116 | - elseif (!$this->success) { |
|
116 | + elseif(!$this->success) { |
|
117 | 117 | $exception = Requests_Exception_HTTP::get_class($this->status_code); |
118 | 118 | throw new $exception(null, $this); |
119 | 119 | } |
@@ -12,11 +12,13 @@ discard block |
||
12 | 12 | * Contains a response from Requests::request() |
13 | 13 | * @package Requests |
14 | 14 | */ |
15 | -class Requests_Response { |
|
15 | +class Requests_Response |
|
16 | +{ |
|
16 | 17 | /** |
17 | 18 | * Constructor |
18 | 19 | */ |
19 | - public function __construct() { |
|
20 | + public function __construct() |
|
21 | + { |
|
20 | 22 | $this->headers = new Requests_Response_Headers(); |
21 | 23 | $this->cookies = new Requests_Cookie_Jar(); |
22 | 24 | } |
@@ -95,7 +97,8 @@ discard block |
||
95 | 97 | * |
96 | 98 | * @return boolean True if redirect (3xx status), false if not. |
97 | 99 | */ |
98 | - public function is_redirect() { |
|
100 | + public function is_redirect() |
|
101 | + { |
|
99 | 102 | $code = $this->status_code; |
100 | 103 | return in_array($code, array(300, 301, 302, 303, 307)) || $code > 307 && $code < 400; |
101 | 104 | } |
@@ -107,13 +110,17 @@ discard block |
||
107 | 110 | * @throws Requests_Exception_HTTP On non-successful status code. Exception class corresponds to code (e.g. {@see Requests_Exception_HTTP_404}) |
108 | 111 | * @param boolean $allow_redirects Set to false to throw on a 3xx as well |
109 | 112 | */ |
110 | - public function throw_for_status($allow_redirects = true) { |
|
111 | - if ($this->is_redirect()) { |
|
112 | - if (!$allow_redirects) { |
|
113 | + public function throw_for_status($allow_redirects = true) |
|
114 | + { |
|
115 | + if ($this->is_redirect()) |
|
116 | + { |
|
117 | + if (!$allow_redirects) |
|
118 | + { |
|
113 | 119 | throw new Requests_Exception('Redirection not allowed', 'response.no_redirects', $this); |
114 | 120 | } |
115 | 121 | } |
116 | - elseif (!$this->success) { |
|
122 | + elseif (!$this->success) |
|
123 | + { |
|
117 | 124 | $exception = Requests_Exception_HTTP::get_class($this->status_code); |
118 | 125 | throw new $exception(null, $this); |
119 | 126 | } |
@@ -47,20 +47,20 @@ discard block |
||
47 | 47 | * |
48 | 48 | * @var integer|boolean |
49 | 49 | */ |
50 | - public $status_code = false; |
|
50 | + public $status_code = FALSE; |
|
51 | 51 | |
52 | 52 | /** |
53 | 53 | * Protocol version, false if non-blocking |
54 | 54 | * @var float|boolean |
55 | 55 | */ |
56 | - public $protocol_version = false; |
|
56 | + public $protocol_version = FALSE; |
|
57 | 57 | |
58 | 58 | /** |
59 | 59 | * Whether the request succeeded or not |
60 | 60 | * |
61 | 61 | * @var boolean |
62 | 62 | */ |
63 | - public $success = false; |
|
63 | + public $success = FALSE; |
|
64 | 64 | |
65 | 65 | /** |
66 | 66 | * Number of redirects the request used |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | * @throws Requests_Exception_HTTP On non-successful status code. Exception class corresponds to code (e.g. {@see Requests_Exception_HTTP_404}) |
108 | 108 | * @param boolean $allow_redirects Set to false to throw on a 3xx as well |
109 | 109 | */ |
110 | - public function throw_for_status($allow_redirects = true) { |
|
110 | + public function throw_for_status($allow_redirects = TRUE) { |
|
111 | 111 | if ($this->is_redirect()) { |
112 | 112 | if (!$allow_redirects) { |
113 | 113 | throw new Requests_Exception('Redirection not allowed', 'response.no_redirects', $this); |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | } |
116 | 116 | elseif (!$this->success) { |
117 | 117 | $exception = Requests_Exception_HTTP::get_class($this->status_code); |
118 | - throw new $exception(null, $this); |
|
118 | + throw new $exception(NULL, $this); |
|
119 | 119 | } |
120 | 120 | } |
121 | 121 | } |
@@ -10,7 +10,8 @@ discard block |
||
10 | 10 | * |
11 | 11 | * @package Requests |
12 | 12 | */ |
13 | -class Requests_Exception extends Exception { |
|
13 | +class Requests_Exception extends Exception |
|
14 | +{ |
|
14 | 15 | /** |
15 | 16 | * Type of exception |
16 | 17 | * |
@@ -33,7 +34,8 @@ discard block |
||
33 | 34 | * @param mixed $data Associated data |
34 | 35 | * @param integer $code Exception numerical code, if applicable |
35 | 36 | */ |
36 | - public function __construct($message, $type, $data = null, $code = 0) { |
|
37 | + public function __construct($message, $type, $data = null, $code = 0) |
|
38 | + { |
|
37 | 39 | parent::__construct($message, $code); |
38 | 40 | |
39 | 41 | $this->type = $type; |
@@ -46,7 +48,8 @@ discard block |
||
46 | 48 | * @codeCoverageIgnore |
47 | 49 | * @return string |
48 | 50 | */ |
49 | - public function getType() { |
|
51 | + public function getType() |
|
52 | + { |
|
50 | 53 | return $this->type; |
51 | 54 | } |
52 | 55 | |
@@ -56,7 +59,8 @@ discard block |
||
56 | 59 | * @codeCoverageIgnore |
57 | 60 | * @return mixed |
58 | 61 | */ |
59 | - public function getData() { |
|
62 | + public function getData() |
|
63 | + { |
|
60 | 64 | return $this->data; |
61 | 65 | } |
62 | 66 | } |
63 | 67 | \ No newline at end of file |
@@ -33,7 +33,7 @@ |
||
33 | 33 | * @param mixed $data Associated data |
34 | 34 | * @param integer $code Exception numerical code, if applicable |
35 | 35 | */ |
36 | - public function __construct($message, $type, $data = null, $code = 0) { |
|
36 | + public function __construct($message, $type, $data = NULL, $code = 0) { |
|
37 | 37 | parent::__construct($message, $code); |
38 | 38 | |
39 | 39 | $this->type = $type; |
@@ -37,8 +37,8 @@ discard block |
||
37 | 37 | * @param array|null $args Array of user and password. Must have exactly two elements |
38 | 38 | */ |
39 | 39 | public function __construct($args = null) { |
40 | - if (is_array($args)) { |
|
41 | - if (count($args) !== 2) { |
|
40 | + if(is_array($args)) { |
|
41 | + if(count($args) !== 2) { |
|
42 | 42 | throw new Requests_Exception('Invalid number of arguments', 'authbasicbadargs'); |
43 | 43 | } |
44 | 44 | |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | * @see fsockopen_header |
54 | 54 | * @param Requests_Hooks $hooks Hook system |
55 | 55 | */ |
56 | - public function register(Requests_Hooks &$hooks) { |
|
56 | + public function register(Requests_Hooks&$hooks) { |
|
57 | 57 | $hooks->register('curl.before_send', array(&$this, 'curl_before_send')); |
58 | 58 | $hooks->register('fsockopen.after_headers', array(&$this, 'fsockopen_header')); |
59 | 59 | } |
@@ -15,7 +15,8 @@ discard block |
||
15 | 15 | * @package Requests |
16 | 16 | * @subpackage Authentication |
17 | 17 | */ |
18 | -class Requests_Auth_Basic implements Requests_Auth { |
|
18 | +class Requests_Auth_Basic implements Requests_Auth |
|
19 | +{ |
|
19 | 20 | /** |
20 | 21 | * Username |
21 | 22 | * |
@@ -36,9 +37,12 @@ discard block |
||
36 | 37 | * @throws Requests_Exception On incorrect number of arguments (`authbasicbadargs`) |
37 | 38 | * @param array|null $args Array of user and password. Must have exactly two elements |
38 | 39 | */ |
39 | - public function __construct($args = null) { |
|
40 | - if (is_array($args)) { |
|
41 | - if (count($args) !== 2) { |
|
40 | + public function __construct($args = null) |
|
41 | + { |
|
42 | + if (is_array($args)) |
|
43 | + { |
|
44 | + if (count($args) !== 2) |
|
45 | + { |
|
42 | 46 | throw new Requests_Exception('Invalid number of arguments', 'authbasicbadargs'); |
43 | 47 | } |
44 | 48 | |
@@ -53,7 +57,8 @@ discard block |
||
53 | 57 | * @see fsockopen_header |
54 | 58 | * @param Requests_Hooks $hooks Hook system |
55 | 59 | */ |
56 | - public function register(Requests_Hooks &$hooks) { |
|
60 | + public function register(Requests_Hooks &$hooks) |
|
61 | + { |
|
57 | 62 | $hooks->register('curl.before_send', array(&$this, 'curl_before_send')); |
58 | 63 | $hooks->register('fsockopen.after_headers', array(&$this, 'fsockopen_header')); |
59 | 64 | } |
@@ -63,7 +68,8 @@ discard block |
||
63 | 68 | * |
64 | 69 | * @param resource $handle cURL resource |
65 | 70 | */ |
66 | - public function curl_before_send(&$handle) { |
|
71 | + public function curl_before_send(&$handle) |
|
72 | + { |
|
67 | 73 | curl_setopt($handle, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); |
68 | 74 | curl_setopt($handle, CURLOPT_USERPWD, $this->getAuthString()); |
69 | 75 | } |
@@ -73,7 +79,8 @@ discard block |
||
73 | 79 | * |
74 | 80 | * @param string $out HTTP header string |
75 | 81 | */ |
76 | - public function fsockopen_header(&$out) { |
|
82 | + public function fsockopen_header(&$out) |
|
83 | + { |
|
77 | 84 | $out .= sprintf("Authorization: Basic %s\r\n", base64_encode($this->getAuthString())); |
78 | 85 | } |
79 | 86 | |
@@ -82,7 +89,8 @@ discard block |
||
82 | 89 | * |
83 | 90 | * @return string |
84 | 91 | */ |
85 | - public function getAuthString() { |
|
92 | + public function getAuthString() |
|
93 | + { |
|
86 | 94 | return $this->user . ':' . $this->pass; |
87 | 95 | } |
88 | 96 | } |
89 | 97 | \ No newline at end of file |
@@ -36,7 +36,7 @@ |
||
36 | 36 | * @throws Requests_Exception On incorrect number of arguments (`authbasicbadargs`) |
37 | 37 | * @param array|null $args Array of user and password. Must have exactly two elements |
38 | 38 | */ |
39 | - public function __construct($args = null) { |
|
39 | + public function __construct($args = NULL) { |
|
40 | 40 | if (is_array($args)) { |
41 | 41 | if (count($args) !== 2) { |
42 | 42 | throw new Requests_Exception('Invalid number of arguments', 'authbasicbadargs'); |
@@ -137,12 +137,12 @@ discard block |
||
137 | 137 | */ |
138 | 138 | public static function autoloader($class) { |
139 | 139 | // Check that the class starts with "Requests" |
140 | - if (strpos($class, 'Requests') !== 0) { |
|
140 | + if(strpos($class, 'Requests') !== 0) { |
|
141 | 141 | return; |
142 | 142 | } |
143 | 143 | |
144 | 144 | $file = str_replace('_', '/', $class); |
145 | - if (file_exists(dirname(__FILE__) . '/' . $file . '.php')) { |
|
145 | + if(file_exists(dirname(__FILE__) . '/' . $file . '.php')) { |
|
146 | 146 | require_once(dirname(__FILE__) . '/' . $file . '.php'); |
147 | 147 | } |
148 | 148 | } |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | * @param string $transport Transport class to add, must support the Requests_Transport interface |
163 | 163 | */ |
164 | 164 | public static function add_transport($transport) { |
165 | - if (empty(self::$transports)) { |
|
165 | + if(empty(self::$transports)) { |
|
166 | 166 | self::$transports = array( |
167 | 167 | 'Requests_Transport_cURL', |
168 | 168 | 'Requests_Transport_fsockopen', |
@@ -186,12 +186,12 @@ discard block |
||
186 | 186 | $cap_string = serialize($capabilities); |
187 | 187 | |
188 | 188 | // Don't search for a transport if it's already been done for these $capabilities |
189 | - if (isset(self::$transport[$cap_string]) && self::$transport[$cap_string] !== null) { |
|
189 | + if(isset(self::$transport[$cap_string]) && self::$transport[$cap_string] !== null) { |
|
190 | 190 | return new self::$transport[$cap_string](); |
191 | 191 | } |
192 | 192 | // @codeCoverageIgnoreEnd |
193 | 193 | |
194 | - if (empty(self::$transports)) { |
|
194 | + if(empty(self::$transports)) { |
|
195 | 195 | self::$transports = array( |
196 | 196 | 'Requests_Transport_cURL', |
197 | 197 | 'Requests_Transport_fsockopen', |
@@ -199,18 +199,18 @@ discard block |
||
199 | 199 | } |
200 | 200 | |
201 | 201 | // Find us a working transport |
202 | - foreach (self::$transports as $class) { |
|
203 | - if (!class_exists($class)) { |
|
202 | + foreach(self::$transports as $class) { |
|
203 | + if(!class_exists($class)) { |
|
204 | 204 | continue; |
205 | 205 | } |
206 | 206 | |
207 | 207 | $result = call_user_func(array($class, 'test'), $capabilities); |
208 | - if ($result) { |
|
208 | + if($result) { |
|
209 | 209 | self::$transport[$cap_string] = $class; |
210 | 210 | break; |
211 | 211 | } |
212 | 212 | } |
213 | - if (self::$transport[$cap_string] === null) { |
|
213 | + if(self::$transport[$cap_string] === null) { |
|
214 | 214 | throw new Requests_Exception('No working transports found', 'notransport', self::$transports); |
215 | 215 | } |
216 | 216 | |
@@ -355,7 +355,7 @@ discard block |
||
355 | 355 | * @return Requests_Response |
356 | 356 | */ |
357 | 357 | public static function request($url, $headers = array(), $data = array(), $type = self::GET, $options = array()) { |
358 | - if (empty($options['type'])) { |
|
358 | + if(empty($options['type'])) { |
|
359 | 359 | $options['type'] = $type; |
360 | 360 | } |
361 | 361 | $options = array_merge(self::get_default_options(), $options); |
@@ -364,10 +364,10 @@ discard block |
||
364 | 364 | |
365 | 365 | $options['hooks']->dispatch('requests.before_request', array(&$url, &$headers, &$data, &$type, &$options)); |
366 | 366 | |
367 | - if (!empty($options['transport'])) { |
|
367 | + if(!empty($options['transport'])) { |
|
368 | 368 | $transport = $options['transport']; |
369 | 369 | |
370 | - if (is_string($options['transport'])) { |
|
370 | + if(is_string($options['transport'])) { |
|
371 | 371 | $transport = new $transport(); |
372 | 372 | } |
373 | 373 | } |
@@ -427,29 +427,29 @@ discard block |
||
427 | 427 | public static function request_multiple($requests, $options = array()) { |
428 | 428 | $options = array_merge(self::get_default_options(true), $options); |
429 | 429 | |
430 | - if (!empty($options['hooks'])) { |
|
430 | + if(!empty($options['hooks'])) { |
|
431 | 431 | $options['hooks']->register('transport.internal.parse_response', array('Requests', 'parse_multiple')); |
432 | - if (!empty($options['complete'])) { |
|
432 | + if(!empty($options['complete'])) { |
|
433 | 433 | $options['hooks']->register('multiple.request.complete', $options['complete']); |
434 | 434 | } |
435 | 435 | } |
436 | 436 | |
437 | - foreach ($requests as $id => &$request) { |
|
438 | - if (!isset($request['headers'])) { |
|
437 | + foreach($requests as $id => &$request) { |
|
438 | + if(!isset($request['headers'])) { |
|
439 | 439 | $request['headers'] = array(); |
440 | 440 | } |
441 | - if (!isset($request['data'])) { |
|
441 | + if(!isset($request['data'])) { |
|
442 | 442 | $request['data'] = array(); |
443 | 443 | } |
444 | - if (!isset($request['type'])) { |
|
444 | + if(!isset($request['type'])) { |
|
445 | 445 | $request['type'] = self::GET; |
446 | 446 | } |
447 | - if (!isset($request['options'])) { |
|
447 | + if(!isset($request['options'])) { |
|
448 | 448 | $request['options'] = $options; |
449 | 449 | $request['options']['type'] = $request['type']; |
450 | 450 | } |
451 | 451 | else { |
452 | - if (empty($request['options']['type'])) { |
|
452 | + if(empty($request['options']['type'])) { |
|
453 | 453 | $request['options']['type'] = $request['type']; |
454 | 454 | } |
455 | 455 | $request['options'] = array_merge($options, $request['options']); |
@@ -458,19 +458,19 @@ discard block |
||
458 | 458 | self::set_defaults($request['url'], $request['headers'], $request['data'], $request['type'], $request['options']); |
459 | 459 | |
460 | 460 | // Ensure we only hook in once |
461 | - if ($request['options']['hooks'] !== $options['hooks']) { |
|
461 | + if($request['options']['hooks'] !== $options['hooks']) { |
|
462 | 462 | $request['options']['hooks']->register('transport.internal.parse_response', array('Requests', 'parse_multiple')); |
463 | - if (!empty($request['options']['complete'])) { |
|
463 | + if(!empty($request['options']['complete'])) { |
|
464 | 464 | $request['options']['hooks']->register('multiple.request.complete', $request['options']['complete']); |
465 | 465 | } |
466 | 466 | } |
467 | 467 | } |
468 | 468 | unset($request); |
469 | 469 | |
470 | - if (!empty($options['transport'])) { |
|
470 | + if(!empty($options['transport'])) { |
|
471 | 471 | $transport = $options['transport']; |
472 | 472 | |
473 | - if (is_string($options['transport'])) { |
|
473 | + if(is_string($options['transport'])) { |
|
474 | 474 | $transport = new $transport(); |
475 | 475 | } |
476 | 476 | } |
@@ -479,10 +479,10 @@ discard block |
||
479 | 479 | } |
480 | 480 | $responses = $transport->request_multiple($requests, $options); |
481 | 481 | |
482 | - foreach ($responses as $id => &$response) { |
|
482 | + foreach($responses as $id => &$response) { |
|
483 | 483 | // If our hook got messed with somehow, ensure we end up with the |
484 | 484 | // correct response |
485 | - if (is_string($response)) { |
|
485 | + if(is_string($response)) { |
|
486 | 486 | $request = $requests[$id]; |
487 | 487 | self::parse_multiple($response, $request); |
488 | 488 | $request['options']['hooks']->dispatch('multiple.request.complete', array(&$response, $id)); |
@@ -521,7 +521,7 @@ discard block |
||
521 | 521 | 'verify' => Requests::get_certificate_path(), |
522 | 522 | 'verifyname' => true, |
523 | 523 | ); |
524 | - if ($multirequest !== false) { |
|
524 | + if($multirequest !== false) { |
|
525 | 525 | $defaults['complete'] = null; |
526 | 526 | } |
527 | 527 | return $defaults; |
@@ -533,7 +533,7 @@ discard block |
||
533 | 533 | * @return string Default certificate path. |
534 | 534 | */ |
535 | 535 | public static function get_certificate_path() { |
536 | - if ( ! empty( Requests::$certificate_path ) ) { |
|
536 | + if(!empty(Requests::$certificate_path)) { |
|
537 | 537 | return Requests::$certificate_path; |
538 | 538 | } |
539 | 539 | |
@@ -545,7 +545,7 @@ discard block |
||
545 | 545 | * |
546 | 546 | * @param string $path Certificate path, pointing to a PEM file. |
547 | 547 | */ |
548 | - public static function set_certificate_path( $path ) { |
|
548 | + public static function set_certificate_path($path) { |
|
549 | 549 | Requests::$certificate_path = $path; |
550 | 550 | } |
551 | 551 | |
@@ -560,39 +560,39 @@ discard block |
||
560 | 560 | * @return array $options |
561 | 561 | */ |
562 | 562 | protected static function set_defaults(&$url, &$headers, &$data, &$type, &$options) { |
563 | - if (!preg_match('/^http(s)?:\/\//i', $url, $matches)) { |
|
563 | + if(!preg_match('/^http(s)?:\/\//i', $url, $matches)) { |
|
564 | 564 | throw new Requests_Exception('Only HTTP(S) requests are handled.', 'nonhttp', $url); |
565 | 565 | } |
566 | 566 | |
567 | - if (empty($options['hooks'])) { |
|
567 | + if(empty($options['hooks'])) { |
|
568 | 568 | $options['hooks'] = new Requests_Hooks(); |
569 | 569 | } |
570 | 570 | |
571 | - if (is_array($options['auth'])) { |
|
571 | + if(is_array($options['auth'])) { |
|
572 | 572 | $options['auth'] = new Requests_Auth_Basic($options['auth']); |
573 | 573 | } |
574 | - if ($options['auth'] !== false) { |
|
574 | + if($options['auth'] !== false) { |
|
575 | 575 | $options['auth']->register($options['hooks']); |
576 | 576 | } |
577 | 577 | |
578 | - if (is_string($options['proxy']) || is_array($options['proxy'])) { |
|
578 | + if(is_string($options['proxy']) || is_array($options['proxy'])) { |
|
579 | 579 | $options['proxy'] = new Requests_Proxy_HTTP($options['proxy']); |
580 | 580 | } |
581 | - if ($options['proxy'] !== false) { |
|
581 | + if($options['proxy'] !== false) { |
|
582 | 582 | $options['proxy']->register($options['hooks']); |
583 | 583 | } |
584 | 584 | |
585 | - if (is_array($options['cookies'])) { |
|
585 | + if(is_array($options['cookies'])) { |
|
586 | 586 | $options['cookies'] = new Requests_Cookie_Jar($options['cookies']); |
587 | 587 | } |
588 | - elseif (empty($options['cookies'])) { |
|
588 | + elseif(empty($options['cookies'])) { |
|
589 | 589 | $options['cookies'] = new Requests_Cookie_Jar(); |
590 | 590 | } |
591 | - if ($options['cookies'] !== false) { |
|
591 | + if($options['cookies'] !== false) { |
|
592 | 592 | $options['cookies']->register($options['hooks']); |
593 | 593 | } |
594 | 594 | |
595 | - if ($options['idn'] !== false) { |
|
595 | + if($options['idn'] !== false) { |
|
596 | 596 | $iri = new Requests_IRI($url); |
597 | 597 | $iri->host = Requests_IDNAEncoder::encode($iri->ihost); |
598 | 598 | $url = $iri->uri; |
@@ -601,8 +601,8 @@ discard block |
||
601 | 601 | // Massage the type to ensure we support it. |
602 | 602 | $type = strtoupper($type); |
603 | 603 | |
604 | - if (!isset($options['data_format'])) { |
|
605 | - if (in_array($type, array(self::HEAD, self::GET, self::DELETE))) { |
|
604 | + if(!isset($options['data_format'])) { |
|
605 | + if(in_array($type, array(self::HEAD, self::GET, self::DELETE))) { |
|
606 | 606 | $options['data_format'] = 'query'; |
607 | 607 | } |
608 | 608 | else { |
@@ -627,15 +627,15 @@ discard block |
||
627 | 627 | */ |
628 | 628 | protected static function parse_response($headers, $url, $req_headers, $req_data, $options) { |
629 | 629 | $return = new Requests_Response(); |
630 | - if (!$options['blocking']) { |
|
630 | + if(!$options['blocking']) { |
|
631 | 631 | return $return; |
632 | 632 | } |
633 | 633 | |
634 | 634 | $return->raw = $headers; |
635 | 635 | $return->url = $url; |
636 | 636 | |
637 | - if (!$options['filename']) { |
|
638 | - if (($pos = strpos($headers, "\r\n\r\n")) === false) { |
|
637 | + if(!$options['filename']) { |
|
638 | + if(($pos = strpos($headers, "\r\n\r\n")) === false) { |
|
639 | 639 | // Crap! |
640 | 640 | throw new Requests_Exception('Missing header/body separator', 'requests.no_crlf_separator'); |
641 | 641 | } |
@@ -652,44 +652,44 @@ discard block |
||
652 | 652 | $headers = preg_replace('/\n[ \t]/', ' ', $headers); |
653 | 653 | $headers = explode("\n", $headers); |
654 | 654 | preg_match('#^HTTP/(1\.\d)[ \t]+(\d+)#i', array_shift($headers), $matches); |
655 | - if (empty($matches)) { |
|
655 | + if(empty($matches)) { |
|
656 | 656 | throw new Requests_Exception('Response could not be parsed', 'noversion', $headers); |
657 | 657 | } |
658 | - $return->protocol_version = (float) $matches[1]; |
|
659 | - $return->status_code = (int) $matches[2]; |
|
660 | - if ($return->status_code >= 200 && $return->status_code < 300) { |
|
658 | + $return->protocol_version = (float)$matches[1]; |
|
659 | + $return->status_code = (int)$matches[2]; |
|
660 | + if($return->status_code >= 200 && $return->status_code < 300) { |
|
661 | 661 | $return->success = true; |
662 | 662 | } |
663 | 663 | |
664 | - foreach ($headers as $header) { |
|
664 | + foreach($headers as $header) { |
|
665 | 665 | list($key, $value) = explode(':', $header, 2); |
666 | 666 | $value = trim($value); |
667 | 667 | preg_replace('#(\s+)#i', ' ', $value); |
668 | 668 | $return->headers[$key] = $value; |
669 | 669 | } |
670 | - if (isset($return->headers['transfer-encoding'])) { |
|
670 | + if(isset($return->headers['transfer-encoding'])) { |
|
671 | 671 | $return->body = self::decode_chunked($return->body); |
672 | 672 | unset($return->headers['transfer-encoding']); |
673 | 673 | } |
674 | - if (isset($return->headers['content-encoding'])) { |
|
674 | + if(isset($return->headers['content-encoding'])) { |
|
675 | 675 | $return->body = self::decompress($return->body); |
676 | 676 | } |
677 | 677 | |
678 | 678 | //fsockopen and cURL compatibility |
679 | - if (isset($return->headers['connection'])) { |
|
679 | + if(isset($return->headers['connection'])) { |
|
680 | 680 | unset($return->headers['connection']); |
681 | 681 | } |
682 | 682 | |
683 | 683 | $options['hooks']->dispatch('requests.before_redirect_check', array(&$return, $req_headers, $req_data, $options)); |
684 | 684 | |
685 | - if ($return->is_redirect() && $options['follow_redirects'] === true) { |
|
686 | - if (isset($return->headers['location']) && $options['redirected'] < $options['redirects']) { |
|
687 | - if ($return->status_code === 303) { |
|
685 | + if($return->is_redirect() && $options['follow_redirects'] === true) { |
|
686 | + if(isset($return->headers['location']) && $options['redirected'] < $options['redirects']) { |
|
687 | + if($return->status_code === 303) { |
|
688 | 688 | $options['type'] = self::GET; |
689 | 689 | } |
690 | 690 | $options['redirected']++; |
691 | 691 | $location = $return->headers['location']; |
692 | - if (strpos($location, 'http://') !== 0 && strpos($location, 'https://') !== 0) { |
|
692 | + if(strpos($location, 'http://') !== 0 && strpos($location, 'https://') !== 0) { |
|
693 | 693 | // relative redirect, for compatibility make it absolute |
694 | 694 | $location = Requests_IRI::absolutize($url, $location); |
695 | 695 | $location = $location->uri; |
@@ -707,7 +707,7 @@ discard block |
||
707 | 707 | $redirected->history[] = $return; |
708 | 708 | return $redirected; |
709 | 709 | } |
710 | - elseif ($options['redirected'] >= $options['redirects']) { |
|
710 | + elseif($options['redirected'] >= $options['redirects']) { |
|
711 | 711 | throw new Requests_Exception('Too many redirects', 'toomanyredirects', $return); |
712 | 712 | } |
713 | 713 | } |
@@ -736,7 +736,7 @@ discard block |
||
736 | 736 | $options = $request['options']; |
737 | 737 | $response = self::parse_response($response, $url, $headers, $data, $options); |
738 | 738 | } |
739 | - catch (Requests_Exception $e) { |
|
739 | + catch(Requests_Exception $e) { |
|
740 | 740 | $response = $e; |
741 | 741 | } |
742 | 742 | } |
@@ -749,7 +749,7 @@ discard block |
||
749 | 749 | * @return string Decoded body |
750 | 750 | */ |
751 | 751 | protected static function decode_chunked($data) { |
752 | - if (!preg_match('/^([0-9a-f]+)(?:;(?:[\w-]*)(?:=(?:(?:[\w-]*)*|"(?:[^\r\n])*"))?)*\r\n/i', trim($data))) { |
|
752 | + if(!preg_match('/^([0-9a-f]+)(?:;(?:[\w-]*)(?:=(?:(?:[\w-]*)*|"(?:[^\r\n])*"))?)*\r\n/i', trim($data))) { |
|
753 | 753 | return $data; |
754 | 754 | } |
755 | 755 | |
@@ -758,15 +758,15 @@ discard block |
||
758 | 758 | $decoded = ''; |
759 | 759 | $encoded = $data; |
760 | 760 | |
761 | - while (true) { |
|
762 | - $is_chunked = (bool) preg_match('/^([0-9a-f]+)(?:;(?:[\w-]*)(?:=(?:(?:[\w-]*)*|"(?:[^\r\n])*"))?)*\r\n/i', $encoded, $matches); |
|
763 | - if (!$is_chunked) { |
|
761 | + while(true) { |
|
762 | + $is_chunked = (bool)preg_match('/^([0-9a-f]+)(?:;(?:[\w-]*)(?:=(?:(?:[\w-]*)*|"(?:[^\r\n])*"))?)*\r\n/i', $encoded, $matches); |
|
763 | + if(!$is_chunked) { |
|
764 | 764 | // Looks like it's not chunked after all |
765 | 765 | return $data; |
766 | 766 | } |
767 | 767 | |
768 | 768 | $length = hexdec(trim($matches[1])); |
769 | - if ($length === 0) { |
|
769 | + if($length === 0) { |
|
770 | 770 | // Ignore trailer headers |
771 | 771 | return $decoded; |
772 | 772 | } |
@@ -775,7 +775,7 @@ discard block |
||
775 | 775 | $decoded .= substr($encoded, $chunk_length, $length); |
776 | 776 | $encoded = substr($encoded, $chunk_length + $length + 2); |
777 | 777 | |
778 | - if (trim($encoded) === '0' || empty($encoded)) { |
|
778 | + if(trim($encoded) === '0' || empty($encoded)) { |
|
779 | 779 | return $decoded; |
780 | 780 | } |
781 | 781 | } |
@@ -793,7 +793,7 @@ discard block |
||
793 | 793 | */ |
794 | 794 | public static function flatten($array) { |
795 | 795 | $return = array(); |
796 | - foreach ($array as $key => $value) { |
|
796 | + foreach($array as $key => $value) { |
|
797 | 797 | $return[] = sprintf('%s: %s', $key, $value); |
798 | 798 | } |
799 | 799 | return $return; |
@@ -821,21 +821,21 @@ discard block |
||
821 | 821 | * @return string Decompressed string |
822 | 822 | */ |
823 | 823 | public static function decompress($data) { |
824 | - if (substr($data, 0, 2) !== "\x1f\x8b" && substr($data, 0, 2) !== "\x78\x9c") { |
|
824 | + if(substr($data, 0, 2) !== "\x1f\x8b" && substr($data, 0, 2) !== "\x78\x9c") { |
|
825 | 825 | // Not actually compressed. Probably cURL ruining this for us. |
826 | 826 | return $data; |
827 | 827 | } |
828 | 828 | |
829 | - if (function_exists('gzdecode') && ($decoded = @gzdecode($data)) !== false) { |
|
829 | + if(function_exists('gzdecode') && ($decoded = @gzdecode($data)) !== false) { |
|
830 | 830 | return $decoded; |
831 | 831 | } |
832 | - elseif (function_exists('gzinflate') && ($decoded = @gzinflate($data)) !== false) { |
|
832 | + elseif(function_exists('gzinflate') && ($decoded = @gzinflate($data)) !== false) { |
|
833 | 833 | return $decoded; |
834 | 834 | } |
835 | - elseif (($decoded = self::compatible_gzinflate($data)) !== false) { |
|
835 | + elseif(($decoded = self::compatible_gzinflate($data)) !== false) { |
|
836 | 836 | return $decoded; |
837 | 837 | } |
838 | - elseif (function_exists('gzuncompress') && ($decoded = @gzuncompress($data)) !== false) { |
|
838 | + elseif(function_exists('gzuncompress') && ($decoded = @gzuncompress($data)) !== false) { |
|
839 | 839 | return $decoded; |
840 | 840 | } |
841 | 841 | |
@@ -865,26 +865,26 @@ discard block |
||
865 | 865 | public static function compatible_gzinflate($gzData) { |
866 | 866 | // Compressed data might contain a full zlib header, if so strip it for |
867 | 867 | // gzinflate() |
868 | - if (substr($gzData, 0, 3) == "\x1f\x8b\x08") { |
|
868 | + if(substr($gzData, 0, 3) == "\x1f\x8b\x08") { |
|
869 | 869 | $i = 10; |
870 | 870 | $flg = ord(substr($gzData, 3, 1)); |
871 | - if ($flg > 0) { |
|
872 | - if ($flg & 4) { |
|
871 | + if($flg > 0) { |
|
872 | + if($flg&4) { |
|
873 | 873 | list($xlen) = unpack('v', substr($gzData, $i, 2)); |
874 | 874 | $i = $i + 2 + $xlen; |
875 | 875 | } |
876 | - if ($flg & 8) { |
|
876 | + if($flg&8) { |
|
877 | 877 | $i = strpos($gzData, "\0", $i) + 1; |
878 | 878 | } |
879 | - if ($flg & 16) { |
|
879 | + if($flg&16) { |
|
880 | 880 | $i = strpos($gzData, "\0", $i) + 1; |
881 | 881 | } |
882 | - if ($flg & 2) { |
|
882 | + if($flg&2) { |
|
883 | 883 | $i = $i + 2; |
884 | 884 | } |
885 | 885 | } |
886 | 886 | $decompressed = self::compatible_gzinflate(substr($gzData, $i)); |
887 | - if (false !== $decompressed) { |
|
887 | + if(false !== $decompressed) { |
|
888 | 888 | return $decompressed; |
889 | 889 | } |
890 | 890 | } |
@@ -905,17 +905,17 @@ discard block |
||
905 | 905 | // First 2 bytes should be divisible by 0x1F |
906 | 906 | list(, $first_two_bytes) = unpack('n', $gzData); |
907 | 907 | |
908 | - if (0x08 == $first_nibble && 0 == ($first_two_bytes % 0x1F)) { |
|
908 | + if(0x08 == $first_nibble && 0 == ($first_two_bytes % 0x1F)) { |
|
909 | 909 | $huffman_encoded = true; |
910 | 910 | } |
911 | 911 | |
912 | - if ($huffman_encoded) { |
|
913 | - if (false !== ($decompressed = @gzinflate(substr($gzData, 2)))) { |
|
912 | + if($huffman_encoded) { |
|
913 | + if(false !== ($decompressed = @gzinflate(substr($gzData, 2)))) { |
|
914 | 914 | return $decompressed; |
915 | 915 | } |
916 | 916 | } |
917 | 917 | |
918 | - if ("\x50\x4b\x03\x04" == substr($gzData, 0, 4)) { |
|
918 | + if("\x50\x4b\x03\x04" == substr($gzData, 0, 4)) { |
|
919 | 919 | // ZIP file format header |
920 | 920 | // Offset 6: 2 bytes, General-purpose field |
921 | 921 | // Offset 26: 2 bytes, filename length |
@@ -927,9 +927,9 @@ discard block |
||
927 | 927 | // If the file has been compressed on the fly, 0x08 bit is set of |
928 | 928 | // the general purpose field. We can use this to differentiate |
929 | 929 | // between a compressed document, and a ZIP file |
930 | - $zip_compressed_on_the_fly = (0x08 == (0x08 & $general_purpose_flag)); |
|
930 | + $zip_compressed_on_the_fly = (0x08 == (0x08&$general_purpose_flag)); |
|
931 | 931 | |
932 | - if (!$zip_compressed_on_the_fly) { |
|
932 | + if(!$zip_compressed_on_the_fly) { |
|
933 | 933 | // Don't attempt to decode a compressed zip file |
934 | 934 | return $gzData; |
935 | 935 | } |
@@ -937,20 +937,20 @@ discard block |
||
937 | 937 | // Determine the first byte of data, based on the above ZIP header |
938 | 938 | // offsets: |
939 | 939 | $first_file_start = array_sum(unpack('v2', substr($gzData, 26, 4))); |
940 | - if (false !== ($decompressed = @gzinflate(substr($gzData, 30 + $first_file_start)))) { |
|
940 | + if(false !== ($decompressed = @gzinflate(substr($gzData, 30 + $first_file_start)))) { |
|
941 | 941 | return $decompressed; |
942 | 942 | } |
943 | 943 | return false; |
944 | 944 | } |
945 | 945 | |
946 | 946 | // Finally fall back to straight gzinflate |
947 | - if (false !== ($decompressed = @gzinflate($gzData))) { |
|
947 | + if(false !== ($decompressed = @gzinflate($gzData))) { |
|
948 | 948 | return $decompressed; |
949 | 949 | } |
950 | 950 | |
951 | 951 | // Fallback for all above failing, not expected, but included for |
952 | 952 | // debugging and preventing regressions and to track stats |
953 | - if (false !== ($decompressed = @gzinflate(substr($gzData, 2)))) { |
|
953 | + if(false !== ($decompressed = @gzinflate(substr($gzData, 2)))) { |
|
954 | 954 | return $decompressed; |
955 | 955 | } |
956 | 956 | |
@@ -959,7 +959,7 @@ discard block |
||
959 | 959 | |
960 | 960 | public static function match_domain($host, $reference) { |
961 | 961 | // Check for a direct match |
962 | - if ($host === $reference) { |
|
962 | + if($host === $reference) { |
|
963 | 963 | return true; |
964 | 964 | } |
965 | 965 | |
@@ -967,10 +967,10 @@ discard block |
||
967 | 967 | // Also validates that the host has 3 parts or more, as per Firefox's |
968 | 968 | // ruleset. |
969 | 969 | $parts = explode('.', $host); |
970 | - if (ip2long($host) === false && count($parts) >= 3) { |
|
970 | + if(ip2long($host) === false && count($parts) >= 3) { |
|
971 | 971 | $parts[0] = '*'; |
972 | 972 | $wildcard = implode('.', $parts); |
973 | - if ($wildcard === $reference) { |
|
973 | + if($wildcard === $reference) { |
|
974 | 974 | return true; |
975 | 975 | } |
976 | 976 | } |
@@ -18,7 +18,8 @@ discard block |
||
18 | 18 | * |
19 | 19 | * @package Requests |
20 | 20 | */ |
21 | -class Requests { |
|
21 | +class Requests |
|
22 | +{ |
|
22 | 23 | /** |
23 | 24 | * POST method |
24 | 25 | * |
@@ -121,7 +122,9 @@ discard block |
||
121 | 122 | * |
122 | 123 | * @codeCoverageIgnore |
123 | 124 | */ |
124 | - private function __construct() {} |
|
125 | + private function __construct() |
|
126 | + { |
|
127 | +} |
|
125 | 128 | |
126 | 129 | /** |
127 | 130 | * Autoloader for Requests |
@@ -135,14 +138,17 @@ discard block |
||
135 | 138 | * |
136 | 139 | * @param string $class Class name to load |
137 | 140 | */ |
138 | - public static function autoloader($class) { |
|
141 | + public static function autoloader($class) |
|
142 | + { |
|
139 | 143 | // Check that the class starts with "Requests" |
140 | - if (strpos($class, 'Requests') !== 0) { |
|
144 | + if (strpos($class, 'Requests') !== 0) |
|
145 | + { |
|
141 | 146 | return; |
142 | 147 | } |
143 | 148 | |
144 | 149 | $file = str_replace('_', '/', $class); |
145 | - if (file_exists(dirname(__FILE__) . '/' . $file . '.php')) { |
|
150 | + if (file_exists(dirname(__FILE__) . '/' . $file . '.php')) |
|
151 | + { |
|
146 | 152 | require_once(dirname(__FILE__) . '/' . $file . '.php'); |
147 | 153 | } |
148 | 154 | } |
@@ -152,7 +158,8 @@ discard block |
||
152 | 158 | * |
153 | 159 | * @codeCoverageIgnore |
154 | 160 | */ |
155 | - public static function register_autoloader() { |
|
161 | + public static function register_autoloader() |
|
162 | + { |
|
156 | 163 | spl_autoload_register(array('Requests', 'autoloader')); |
157 | 164 | } |
158 | 165 | |
@@ -161,8 +168,10 @@ discard block |
||
161 | 168 | * |
162 | 169 | * @param string $transport Transport class to add, must support the Requests_Transport interface |
163 | 170 | */ |
164 | - public static function add_transport($transport) { |
|
165 | - if (empty(self::$transports)) { |
|
171 | + public static function add_transport($transport) |
|
172 | + { |
|
173 | + if (empty(self::$transports)) |
|
174 | + { |
|
166 | 175 | self::$transports = array( |
167 | 176 | 'Requests_Transport_cURL', |
168 | 177 | 'Requests_Transport_fsockopen', |
@@ -178,7 +187,8 @@ discard block |
||
178 | 187 | * @throws Requests_Exception If no valid transport is found (`notransport`) |
179 | 188 | * @return Requests_Transport |
180 | 189 | */ |
181 | - protected static function get_transport($capabilities = array()) { |
|
190 | + protected static function get_transport($capabilities = array()) |
|
191 | + { |
|
182 | 192 | // Caching code, don't bother testing coverage |
183 | 193 | // @codeCoverageIgnoreStart |
184 | 194 | // array of capabilities as a string to be used as an array key |
@@ -186,12 +196,14 @@ discard block |
||
186 | 196 | $cap_string = serialize($capabilities); |
187 | 197 | |
188 | 198 | // Don't search for a transport if it's already been done for these $capabilities |
189 | - if (isset(self::$transport[$cap_string]) && self::$transport[$cap_string] !== null) { |
|
199 | + if (isset(self::$transport[$cap_string]) && self::$transport[$cap_string] !== null) |
|
200 | + { |
|
190 | 201 | return new self::$transport[$cap_string](); |
191 | 202 | } |
192 | 203 | // @codeCoverageIgnoreEnd |
193 | 204 | |
194 | - if (empty(self::$transports)) { |
|
205 | + if (empty(self::$transports)) |
|
206 | + { |
|
195 | 207 | self::$transports = array( |
196 | 208 | 'Requests_Transport_cURL', |
197 | 209 | 'Requests_Transport_fsockopen', |
@@ -199,18 +211,22 @@ discard block |
||
199 | 211 | } |
200 | 212 | |
201 | 213 | // Find us a working transport |
202 | - foreach (self::$transports as $class) { |
|
203 | - if (!class_exists($class)) { |
|
214 | + foreach (self::$transports as $class) |
|
215 | + { |
|
216 | + if (!class_exists($class)) |
|
217 | + { |
|
204 | 218 | continue; |
205 | 219 | } |
206 | 220 | |
207 | 221 | $result = call_user_func(array($class, 'test'), $capabilities); |
208 | - if ($result) { |
|
222 | + if ($result) |
|
223 | + { |
|
209 | 224 | self::$transport[$cap_string] = $class; |
210 | 225 | break; |
211 | 226 | } |
212 | 227 | } |
213 | - if (self::$transport[$cap_string] === null) { |
|
228 | + if (self::$transport[$cap_string] === null) |
|
229 | + { |
|
214 | 230 | throw new Requests_Exception('No working transports found', 'notransport', self::$transports); |
215 | 231 | } |
216 | 232 | |
@@ -227,28 +243,32 @@ discard block |
||
227 | 243 | /** |
228 | 244 | * Send a GET request |
229 | 245 | */ |
230 | - public static function get($url, $headers = array(), $options = array()) { |
|
246 | + public static function get($url, $headers = array(), $options = array()) |
|
247 | + { |
|
231 | 248 | return self::request($url, $headers, null, self::GET, $options); |
232 | 249 | } |
233 | 250 | |
234 | 251 | /** |
235 | 252 | * Send a HEAD request |
236 | 253 | */ |
237 | - public static function head($url, $headers = array(), $options = array()) { |
|
254 | + public static function head($url, $headers = array(), $options = array()) |
|
255 | + { |
|
238 | 256 | return self::request($url, $headers, null, self::HEAD, $options); |
239 | 257 | } |
240 | 258 | |
241 | 259 | /** |
242 | 260 | * Send a DELETE request |
243 | 261 | */ |
244 | - public static function delete($url, $headers = array(), $options = array()) { |
|
262 | + public static function delete($url, $headers = array(), $options = array()) |
|
263 | + { |
|
245 | 264 | return self::request($url, $headers, null, self::DELETE, $options); |
246 | 265 | } |
247 | 266 | |
248 | 267 | /** |
249 | 268 | * Send a TRACE request |
250 | 269 | */ |
251 | - public static function trace($url, $headers = array(), $options = array()) { |
|
270 | + public static function trace($url, $headers = array(), $options = array()) |
|
271 | + { |
|
252 | 272 | return self::request($url, $headers, null, self::TRACE, $options); |
253 | 273 | } |
254 | 274 | /**#@-*/ |
@@ -264,20 +284,23 @@ discard block |
||
264 | 284 | /** |
265 | 285 | * Send a POST request |
266 | 286 | */ |
267 | - public static function post($url, $headers = array(), $data = array(), $options = array()) { |
|
287 | + public static function post($url, $headers = array(), $data = array(), $options = array()) |
|
288 | + { |
|
268 | 289 | return self::request($url, $headers, $data, self::POST, $options); |
269 | 290 | } |
270 | 291 | /** |
271 | 292 | * Send a PUT request |
272 | 293 | */ |
273 | - public static function put($url, $headers = array(), $data = array(), $options = array()) { |
|
294 | + public static function put($url, $headers = array(), $data = array(), $options = array()) |
|
295 | + { |
|
274 | 296 | return self::request($url, $headers, $data, self::PUT, $options); |
275 | 297 | } |
276 | 298 | |
277 | 299 | /** |
278 | 300 | * Send an OPTIONS request |
279 | 301 | */ |
280 | - public static function options($url, $headers = array(), $data = array(), $options = array()) { |
|
302 | + public static function options($url, $headers = array(), $data = array(), $options = array()) |
|
303 | + { |
|
281 | 304 | return self::request($url, $headers, $data, self::OPTIONS, $options); |
282 | 305 | } |
283 | 306 | |
@@ -289,7 +312,8 @@ discard block |
||
289 | 312 | * |
290 | 313 | * @link https://tools.ietf.org/html/rfc5789 |
291 | 314 | */ |
292 | - public static function patch($url, $headers, $data = array(), $options = array()) { |
|
315 | + public static function patch($url, $headers, $data = array(), $options = array()) |
|
316 | + { |
|
293 | 317 | return self::request($url, $headers, $data, self::PATCH, $options); |
294 | 318 | } |
295 | 319 | /**#@-*/ |
@@ -354,8 +378,10 @@ discard block |
||
354 | 378 | * @param array $options Options for the request (see description for more information) |
355 | 379 | * @return Requests_Response |
356 | 380 | */ |
357 | - public static function request($url, $headers = array(), $data = array(), $type = self::GET, $options = array()) { |
|
358 | - if (empty($options['type'])) { |
|
381 | + public static function request($url, $headers = array(), $data = array(), $type = self::GET, $options = array()) |
|
382 | + { |
|
383 | + if (empty($options['type'])) |
|
384 | + { |
|
359 | 385 | $options['type'] = $type; |
360 | 386 | } |
361 | 387 | $options = array_merge(self::get_default_options(), $options); |
@@ -364,14 +390,17 @@ discard block |
||
364 | 390 | |
365 | 391 | $options['hooks']->dispatch('requests.before_request', array(&$url, &$headers, &$data, &$type, &$options)); |
366 | 392 | |
367 | - if (!empty($options['transport'])) { |
|
393 | + if (!empty($options['transport'])) |
|
394 | + { |
|
368 | 395 | $transport = $options['transport']; |
369 | 396 | |
370 | - if (is_string($options['transport'])) { |
|
397 | + if (is_string($options['transport'])) |
|
398 | + { |
|
371 | 399 | $transport = new $transport(); |
372 | 400 | } |
373 | 401 | } |
374 | - else { |
|
402 | + else |
|
403 | + { |
|
375 | 404 | $need_ssl = (0 === stripos($url, 'https://')); |
376 | 405 | $capabilities = array('ssl' => $need_ssl); |
377 | 406 | $transport = self::get_transport($capabilities); |
@@ -424,32 +453,42 @@ discard block |
||
424 | 453 | * @param array $options Global and default options (see {@see Requests::request}) |
425 | 454 | * @return array Responses (either Requests_Response or a Requests_Exception object) |
426 | 455 | */ |
427 | - public static function request_multiple($requests, $options = array()) { |
|
456 | + public static function request_multiple($requests, $options = array()) |
|
457 | + { |
|
428 | 458 | $options = array_merge(self::get_default_options(true), $options); |
429 | 459 | |
430 | - if (!empty($options['hooks'])) { |
|
460 | + if (!empty($options['hooks'])) |
|
461 | + { |
|
431 | 462 | $options['hooks']->register('transport.internal.parse_response', array('Requests', 'parse_multiple')); |
432 | - if (!empty($options['complete'])) { |
|
463 | + if (!empty($options['complete'])) |
|
464 | + { |
|
433 | 465 | $options['hooks']->register('multiple.request.complete', $options['complete']); |
434 | 466 | } |
435 | 467 | } |
436 | 468 | |
437 | - foreach ($requests as $id => &$request) { |
|
438 | - if (!isset($request['headers'])) { |
|
469 | + foreach ($requests as $id => &$request) |
|
470 | + { |
|
471 | + if (!isset($request['headers'])) |
|
472 | + { |
|
439 | 473 | $request['headers'] = array(); |
440 | 474 | } |
441 | - if (!isset($request['data'])) { |
|
475 | + if (!isset($request['data'])) |
|
476 | + { |
|
442 | 477 | $request['data'] = array(); |
443 | 478 | } |
444 | - if (!isset($request['type'])) { |
|
479 | + if (!isset($request['type'])) |
|
480 | + { |
|
445 | 481 | $request['type'] = self::GET; |
446 | 482 | } |
447 | - if (!isset($request['options'])) { |
|
483 | + if (!isset($request['options'])) |
|
484 | + { |
|
448 | 485 | $request['options'] = $options; |
449 | 486 | $request['options']['type'] = $request['type']; |
450 | 487 | } |
451 | - else { |
|
452 | - if (empty($request['options']['type'])) { |
|
488 | + else |
|
489 | + { |
|
490 | + if (empty($request['options']['type'])) |
|
491 | + { |
|
453 | 492 | $request['options']['type'] = $request['type']; |
454 | 493 | } |
455 | 494 | $request['options'] = array_merge($options, $request['options']); |
@@ -458,31 +497,38 @@ discard block |
||
458 | 497 | self::set_defaults($request['url'], $request['headers'], $request['data'], $request['type'], $request['options']); |
459 | 498 | |
460 | 499 | // Ensure we only hook in once |
461 | - if ($request['options']['hooks'] !== $options['hooks']) { |
|
500 | + if ($request['options']['hooks'] !== $options['hooks']) |
|
501 | + { |
|
462 | 502 | $request['options']['hooks']->register('transport.internal.parse_response', array('Requests', 'parse_multiple')); |
463 | - if (!empty($request['options']['complete'])) { |
|
503 | + if (!empty($request['options']['complete'])) |
|
504 | + { |
|
464 | 505 | $request['options']['hooks']->register('multiple.request.complete', $request['options']['complete']); |
465 | 506 | } |
466 | 507 | } |
467 | 508 | } |
468 | 509 | unset($request); |
469 | 510 | |
470 | - if (!empty($options['transport'])) { |
|
511 | + if (!empty($options['transport'])) |
|
512 | + { |
|
471 | 513 | $transport = $options['transport']; |
472 | 514 | |
473 | - if (is_string($options['transport'])) { |
|
515 | + if (is_string($options['transport'])) |
|
516 | + { |
|
474 | 517 | $transport = new $transport(); |
475 | 518 | } |
476 | 519 | } |
477 | - else { |
|
520 | + else |
|
521 | + { |
|
478 | 522 | $transport = self::get_transport(); |
479 | 523 | } |
480 | 524 | $responses = $transport->request_multiple($requests, $options); |
481 | 525 | |
482 | - foreach ($responses as $id => &$response) { |
|
526 | + foreach ($responses as $id => &$response) |
|
527 | + { |
|
483 | 528 | // If our hook got messed with somehow, ensure we end up with the |
484 | 529 | // correct response |
485 | - if (is_string($response)) { |
|
530 | + if (is_string($response)) |
|
531 | + { |
|
486 | 532 | $request = $requests[$id]; |
487 | 533 | self::parse_multiple($response, $request); |
488 | 534 | $request['options']['hooks']->dispatch('multiple.request.complete', array(&$response, $id)); |
@@ -499,7 +545,8 @@ discard block |
||
499 | 545 | * @param boolean $multirequest Is this a multirequest? |
500 | 546 | * @return array Default option values |
501 | 547 | */ |
502 | - protected static function get_default_options($multirequest = false) { |
|
548 | + protected static function get_default_options($multirequest = false) |
|
549 | + { |
|
503 | 550 | $defaults = array( |
504 | 551 | 'timeout' => 10, |
505 | 552 | 'connect_timeout' => 10, |
@@ -521,7 +568,8 @@ discard block |
||
521 | 568 | 'verify' => Requests::get_certificate_path(), |
522 | 569 | 'verifyname' => true, |
523 | 570 | ); |
524 | - if ($multirequest !== false) { |
|
571 | + if ($multirequest !== false) |
|
572 | + { |
|
525 | 573 | $defaults['complete'] = null; |
526 | 574 | } |
527 | 575 | return $defaults; |
@@ -532,8 +580,10 @@ discard block |
||
532 | 580 | * |
533 | 581 | * @return string Default certificate path. |
534 | 582 | */ |
535 | - public static function get_certificate_path() { |
|
536 | - if ( ! empty( Requests::$certificate_path ) ) { |
|
583 | + public static function get_certificate_path() |
|
584 | + { |
|
585 | + if ( ! empty( Requests::$certificate_path ) ) |
|
586 | + { |
|
537 | 587 | return Requests::$certificate_path; |
538 | 588 | } |
539 | 589 | |
@@ -545,7 +595,8 @@ discard block |
||
545 | 595 | * |
546 | 596 | * @param string $path Certificate path, pointing to a PEM file. |
547 | 597 | */ |
548 | - public static function set_certificate_path( $path ) { |
|
598 | + public static function set_certificate_path( $path ) |
|
599 | + { |
|
549 | 600 | Requests::$certificate_path = $path; |
550 | 601 | } |
551 | 602 | |
@@ -559,40 +610,51 @@ discard block |
||
559 | 610 | * @param array $options Options for the request |
560 | 611 | * @return array $options |
561 | 612 | */ |
562 | - protected static function set_defaults(&$url, &$headers, &$data, &$type, &$options) { |
|
563 | - if (!preg_match('/^http(s)?:\/\//i', $url, $matches)) { |
|
613 | + protected static function set_defaults(&$url, &$headers, &$data, &$type, &$options) |
|
614 | + { |
|
615 | + if (!preg_match('/^http(s)?:\/\//i', $url, $matches)) |
|
616 | + { |
|
564 | 617 | throw new Requests_Exception('Only HTTP(S) requests are handled.', 'nonhttp', $url); |
565 | 618 | } |
566 | 619 | |
567 | - if (empty($options['hooks'])) { |
|
620 | + if (empty($options['hooks'])) |
|
621 | + { |
|
568 | 622 | $options['hooks'] = new Requests_Hooks(); |
569 | 623 | } |
570 | 624 | |
571 | - if (is_array($options['auth'])) { |
|
625 | + if (is_array($options['auth'])) |
|
626 | + { |
|
572 | 627 | $options['auth'] = new Requests_Auth_Basic($options['auth']); |
573 | 628 | } |
574 | - if ($options['auth'] !== false) { |
|
629 | + if ($options['auth'] !== false) |
|
630 | + { |
|
575 | 631 | $options['auth']->register($options['hooks']); |
576 | 632 | } |
577 | 633 | |
578 | - if (is_string($options['proxy']) || is_array($options['proxy'])) { |
|
634 | + if (is_string($options['proxy']) || is_array($options['proxy'])) |
|
635 | + { |
|
579 | 636 | $options['proxy'] = new Requests_Proxy_HTTP($options['proxy']); |
580 | 637 | } |
581 | - if ($options['proxy'] !== false) { |
|
638 | + if ($options['proxy'] !== false) |
|
639 | + { |
|
582 | 640 | $options['proxy']->register($options['hooks']); |
583 | 641 | } |
584 | 642 | |
585 | - if (is_array($options['cookies'])) { |
|
643 | + if (is_array($options['cookies'])) |
|
644 | + { |
|
586 | 645 | $options['cookies'] = new Requests_Cookie_Jar($options['cookies']); |
587 | 646 | } |
588 | - elseif (empty($options['cookies'])) { |
|
647 | + elseif (empty($options['cookies'])) |
|
648 | + { |
|
589 | 649 | $options['cookies'] = new Requests_Cookie_Jar(); |
590 | 650 | } |
591 | - if ($options['cookies'] !== false) { |
|
651 | + if ($options['cookies'] !== false) |
|
652 | + { |
|
592 | 653 | $options['cookies']->register($options['hooks']); |
593 | 654 | } |
594 | 655 | |
595 | - if ($options['idn'] !== false) { |
|
656 | + if ($options['idn'] !== false) |
|
657 | + { |
|
596 | 658 | $iri = new Requests_IRI($url); |
597 | 659 | $iri->host = Requests_IDNAEncoder::encode($iri->ihost); |
598 | 660 | $url = $iri->uri; |
@@ -601,11 +663,14 @@ discard block |
||
601 | 663 | // Massage the type to ensure we support it. |
602 | 664 | $type = strtoupper($type); |
603 | 665 | |
604 | - if (!isset($options['data_format'])) { |
|
605 | - if (in_array($type, array(self::HEAD, self::GET, self::DELETE))) { |
|
666 | + if (!isset($options['data_format'])) |
|
667 | + { |
|
668 | + if (in_array($type, array(self::HEAD, self::GET, self::DELETE))) |
|
669 | + { |
|
606 | 670 | $options['data_format'] = 'query'; |
607 | 671 | } |
608 | - else { |
|
672 | + else |
|
673 | + { |
|
609 | 674 | $options['data_format'] = 'body'; |
610 | 675 | } |
611 | 676 | } |
@@ -625,17 +690,21 @@ discard block |
||
625 | 690 | * @param array $options Original $options array passed to {@link request()}, in case we need to follow redirects |
626 | 691 | * @return Requests_Response |
627 | 692 | */ |
628 | - protected static function parse_response($headers, $url, $req_headers, $req_data, $options) { |
|
693 | + protected static function parse_response($headers, $url, $req_headers, $req_data, $options) |
|
694 | + { |
|
629 | 695 | $return = new Requests_Response(); |
630 | - if (!$options['blocking']) { |
|
696 | + if (!$options['blocking']) |
|
697 | + { |
|
631 | 698 | return $return; |
632 | 699 | } |
633 | 700 | |
634 | 701 | $return->raw = $headers; |
635 | 702 | $return->url = $url; |
636 | 703 | |
637 | - if (!$options['filename']) { |
|
638 | - if (($pos = strpos($headers, "\r\n\r\n")) === false) { |
|
704 | + if (!$options['filename']) |
|
705 | + { |
|
706 | + if (($pos = strpos($headers, "\r\n\r\n")) === false) |
|
707 | + { |
|
639 | 708 | // Crap! |
640 | 709 | throw new Requests_Exception('Missing header/body separator', 'requests.no_crlf_separator'); |
641 | 710 | } |
@@ -643,7 +712,8 @@ discard block |
||
643 | 712 | $headers = substr($return->raw, 0, $pos); |
644 | 713 | $return->body = substr($return->raw, $pos + strlen("\n\r\n\r")); |
645 | 714 | } |
646 | - else { |
|
715 | + else |
|
716 | + { |
|
647 | 717 | $return->body = ''; |
648 | 718 | } |
649 | 719 | // Pretend CRLF = LF for compatibility (RFC 2616, section 19.3) |
@@ -652,44 +722,54 @@ discard block |
||
652 | 722 | $headers = preg_replace('/\n[ \t]/', ' ', $headers); |
653 | 723 | $headers = explode("\n", $headers); |
654 | 724 | preg_match('#^HTTP/(1\.\d)[ \t]+(\d+)#i', array_shift($headers), $matches); |
655 | - if (empty($matches)) { |
|
725 | + if (empty($matches)) |
|
726 | + { |
|
656 | 727 | throw new Requests_Exception('Response could not be parsed', 'noversion', $headers); |
657 | 728 | } |
658 | 729 | $return->protocol_version = (float) $matches[1]; |
659 | 730 | $return->status_code = (int) $matches[2]; |
660 | - if ($return->status_code >= 200 && $return->status_code < 300) { |
|
731 | + if ($return->status_code >= 200 && $return->status_code < 300) |
|
732 | + { |
|
661 | 733 | $return->success = true; |
662 | 734 | } |
663 | 735 | |
664 | - foreach ($headers as $header) { |
|
736 | + foreach ($headers as $header) |
|
737 | + { |
|
665 | 738 | list($key, $value) = explode(':', $header, 2); |
666 | 739 | $value = trim($value); |
667 | 740 | preg_replace('#(\s+)#i', ' ', $value); |
668 | 741 | $return->headers[$key] = $value; |
669 | 742 | } |
670 | - if (isset($return->headers['transfer-encoding'])) { |
|
743 | + if (isset($return->headers['transfer-encoding'])) |
|
744 | + { |
|
671 | 745 | $return->body = self::decode_chunked($return->body); |
672 | 746 | unset($return->headers['transfer-encoding']); |
673 | 747 | } |
674 | - if (isset($return->headers['content-encoding'])) { |
|
748 | + if (isset($return->headers['content-encoding'])) |
|
749 | + { |
|
675 | 750 | $return->body = self::decompress($return->body); |
676 | 751 | } |
677 | 752 | |
678 | 753 | //fsockopen and cURL compatibility |
679 | - if (isset($return->headers['connection'])) { |
|
754 | + if (isset($return->headers['connection'])) |
|
755 | + { |
|
680 | 756 | unset($return->headers['connection']); |
681 | 757 | } |
682 | 758 | |
683 | 759 | $options['hooks']->dispatch('requests.before_redirect_check', array(&$return, $req_headers, $req_data, $options)); |
684 | 760 | |
685 | - if ($return->is_redirect() && $options['follow_redirects'] === true) { |
|
686 | - if (isset($return->headers['location']) && $options['redirected'] < $options['redirects']) { |
|
687 | - if ($return->status_code === 303) { |
|
761 | + if ($return->is_redirect() && $options['follow_redirects'] === true) |
|
762 | + { |
|
763 | + if (isset($return->headers['location']) && $options['redirected'] < $options['redirects']) |
|
764 | + { |
|
765 | + if ($return->status_code === 303) |
|
766 | + { |
|
688 | 767 | $options['type'] = self::GET; |
689 | 768 | } |
690 | 769 | $options['redirected']++; |
691 | 770 | $location = $return->headers['location']; |
692 | - if (strpos($location, 'http://') !== 0 && strpos($location, 'https://') !== 0) { |
|
771 | + if (strpos($location, 'http://') !== 0 && strpos($location, 'https://') !== 0) |
|
772 | + { |
|
693 | 773 | // relative redirect, for compatibility make it absolute |
694 | 774 | $location = Requests_IRI::absolutize($url, $location); |
695 | 775 | $location = $location->uri; |
@@ -707,7 +787,8 @@ discard block |
||
707 | 787 | $redirected->history[] = $return; |
708 | 788 | return $redirected; |
709 | 789 | } |
710 | - elseif ($options['redirected'] >= $options['redirects']) { |
|
790 | + elseif ($options['redirected'] >= $options['redirects']) |
|
791 | + { |
|
711 | 792 | throw new Requests_Exception('Too many redirects', 'toomanyredirects', $return); |
712 | 793 | } |
713 | 794 | } |
@@ -728,15 +809,18 @@ discard block |
||
728 | 809 | * @param array $request Request data as passed into {@see Requests::request_multiple()} |
729 | 810 | * @return null `$response` is either set to a Requests_Response instance, or a Requests_Exception object |
730 | 811 | */ |
731 | - public static function parse_multiple(&$response, $request) { |
|
732 | - try { |
|
812 | + public static function parse_multiple(&$response, $request) |
|
813 | + { |
|
814 | + try |
|
815 | + { |
|
733 | 816 | $url = $request['url']; |
734 | 817 | $headers = $request['headers']; |
735 | 818 | $data = $request['data']; |
736 | 819 | $options = $request['options']; |
737 | 820 | $response = self::parse_response($response, $url, $headers, $data, $options); |
738 | 821 | } |
739 | - catch (Requests_Exception $e) { |
|
822 | + catch (Requests_Exception $e) |
|
823 | + { |
|
740 | 824 | $response = $e; |
741 | 825 | } |
742 | 826 | } |
@@ -748,8 +832,10 @@ discard block |
||
748 | 832 | * @param string $data Chunked body |
749 | 833 | * @return string Decoded body |
750 | 834 | */ |
751 | - protected static function decode_chunked($data) { |
|
752 | - if (!preg_match('/^([0-9a-f]+)(?:;(?:[\w-]*)(?:=(?:(?:[\w-]*)*|"(?:[^\r\n])*"))?)*\r\n/i', trim($data))) { |
|
835 | + protected static function decode_chunked($data) |
|
836 | + { |
|
837 | + if (!preg_match('/^([0-9a-f]+)(?:;(?:[\w-]*)(?:=(?:(?:[\w-]*)*|"(?:[^\r\n])*"))?)*\r\n/i', trim($data))) |
|
838 | + { |
|
753 | 839 | return $data; |
754 | 840 | } |
755 | 841 | |
@@ -758,15 +844,18 @@ discard block |
||
758 | 844 | $decoded = ''; |
759 | 845 | $encoded = $data; |
760 | 846 | |
761 | - while (true) { |
|
847 | + while (true) |
|
848 | + { |
|
762 | 849 | $is_chunked = (bool) preg_match('/^([0-9a-f]+)(?:;(?:[\w-]*)(?:=(?:(?:[\w-]*)*|"(?:[^\r\n])*"))?)*\r\n/i', $encoded, $matches); |
763 | - if (!$is_chunked) { |
|
850 | + if (!$is_chunked) |
|
851 | + { |
|
764 | 852 | // Looks like it's not chunked after all |
765 | 853 | return $data; |
766 | 854 | } |
767 | 855 | |
768 | 856 | $length = hexdec(trim($matches[1])); |
769 | - if ($length === 0) { |
|
857 | + if ($length === 0) |
|
858 | + { |
|
770 | 859 | // Ignore trailer headers |
771 | 860 | return $decoded; |
772 | 861 | } |
@@ -775,7 +864,8 @@ discard block |
||
775 | 864 | $decoded .= substr($encoded, $chunk_length, $length); |
776 | 865 | $encoded = substr($encoded, $chunk_length + $length + 2); |
777 | 866 | |
778 | - if (trim($encoded) === '0' || empty($encoded)) { |
|
867 | + if (trim($encoded) === '0' || empty($encoded)) |
|
868 | + { |
|
779 | 869 | return $decoded; |
780 | 870 | } |
781 | 871 | } |
@@ -791,9 +881,11 @@ discard block |
||
791 | 881 | * @param array $array Dictionary of header values |
792 | 882 | * @return array List of headers |
793 | 883 | */ |
794 | - public static function flatten($array) { |
|
884 | + public static function flatten($array) |
|
885 | + { |
|
795 | 886 | $return = array(); |
796 | - foreach ($array as $key => $value) { |
|
887 | + foreach ($array as $key => $value) |
|
888 | + { |
|
797 | 889 | $return[] = sprintf('%s: %s', $key, $value); |
798 | 890 | } |
799 | 891 | return $return; |
@@ -807,7 +899,8 @@ discard block |
||
807 | 899 | * @param array $array Dictionary of header values |
808 | 900 | * @return array List of headers |
809 | 901 | */ |
810 | - public static function flattern($array) { |
|
902 | + public static function flattern($array) |
|
903 | + { |
|
811 | 904 | return self::flatten($array); |
812 | 905 | } |
813 | 906 | |
@@ -820,22 +913,28 @@ discard block |
||
820 | 913 | * @param string $data Compressed data in one of the above formats |
821 | 914 | * @return string Decompressed string |
822 | 915 | */ |
823 | - public static function decompress($data) { |
|
824 | - if (substr($data, 0, 2) !== "\x1f\x8b" && substr($data, 0, 2) !== "\x78\x9c") { |
|
916 | + public static function decompress($data) |
|
917 | + { |
|
918 | + if (substr($data, 0, 2) !== "\x1f\x8b" && substr($data, 0, 2) !== "\x78\x9c") |
|
919 | + { |
|
825 | 920 | // Not actually compressed. Probably cURL ruining this for us. |
826 | 921 | return $data; |
827 | 922 | } |
828 | 923 | |
829 | - if (function_exists('gzdecode') && ($decoded = @gzdecode($data)) !== false) { |
|
924 | + if (function_exists('gzdecode') && ($decoded = @gzdecode($data)) !== false) |
|
925 | + { |
|
830 | 926 | return $decoded; |
831 | 927 | } |
832 | - elseif (function_exists('gzinflate') && ($decoded = @gzinflate($data)) !== false) { |
|
928 | + elseif (function_exists('gzinflate') && ($decoded = @gzinflate($data)) !== false) |
|
929 | + { |
|
833 | 930 | return $decoded; |
834 | 931 | } |
835 | - elseif (($decoded = self::compatible_gzinflate($data)) !== false) { |
|
932 | + elseif (($decoded = self::compatible_gzinflate($data)) !== false) |
|
933 | + { |
|
836 | 934 | return $decoded; |
837 | 935 | } |
838 | - elseif (function_exists('gzuncompress') && ($decoded = @gzuncompress($data)) !== false) { |
|
936 | + elseif (function_exists('gzuncompress') && ($decoded = @gzuncompress($data)) !== false) |
|
937 | + { |
|
839 | 938 | return $decoded; |
840 | 939 | } |
841 | 940 | |
@@ -862,29 +961,37 @@ discard block |
||
862 | 961 | * @param string $gzData String to decompress. |
863 | 962 | * @return string|bool False on failure. |
864 | 963 | */ |
865 | - public static function compatible_gzinflate($gzData) { |
|
964 | + public static function compatible_gzinflate($gzData) |
|
965 | + { |
|
866 | 966 | // Compressed data might contain a full zlib header, if so strip it for |
867 | 967 | // gzinflate() |
868 | - if (substr($gzData, 0, 3) == "\x1f\x8b\x08") { |
|
968 | + if (substr($gzData, 0, 3) == "\x1f\x8b\x08") |
|
969 | + { |
|
869 | 970 | $i = 10; |
870 | 971 | $flg = ord(substr($gzData, 3, 1)); |
871 | - if ($flg > 0) { |
|
872 | - if ($flg & 4) { |
|
972 | + if ($flg > 0) |
|
973 | + { |
|
974 | + if ($flg & 4) |
|
975 | + { |
|
873 | 976 | list($xlen) = unpack('v', substr($gzData, $i, 2)); |
874 | 977 | $i = $i + 2 + $xlen; |
875 | 978 | } |
876 | - if ($flg & 8) { |
|
979 | + if ($flg & 8) |
|
980 | + { |
|
877 | 981 | $i = strpos($gzData, "\0", $i) + 1; |
878 | 982 | } |
879 | - if ($flg & 16) { |
|
983 | + if ($flg & 16) |
|
984 | + { |
|
880 | 985 | $i = strpos($gzData, "\0", $i) + 1; |
881 | 986 | } |
882 | - if ($flg & 2) { |
|
987 | + if ($flg & 2) |
|
988 | + { |
|
883 | 989 | $i = $i + 2; |
884 | 990 | } |
885 | 991 | } |
886 | 992 | $decompressed = self::compatible_gzinflate(substr($gzData, $i)); |
887 | - if (false !== $decompressed) { |
|
993 | + if (false !== $decompressed) |
|
994 | + { |
|
888 | 995 | return $decompressed; |
889 | 996 | } |
890 | 997 | } |
@@ -905,17 +1012,21 @@ discard block |
||
905 | 1012 | // First 2 bytes should be divisible by 0x1F |
906 | 1013 | list(, $first_two_bytes) = unpack('n', $gzData); |
907 | 1014 | |
908 | - if (0x08 == $first_nibble && 0 == ($first_two_bytes % 0x1F)) { |
|
1015 | + if (0x08 == $first_nibble && 0 == ($first_two_bytes % 0x1F)) |
|
1016 | + { |
|
909 | 1017 | $huffman_encoded = true; |
910 | 1018 | } |
911 | 1019 | |
912 | - if ($huffman_encoded) { |
|
913 | - if (false !== ($decompressed = @gzinflate(substr($gzData, 2)))) { |
|
1020 | + if ($huffman_encoded) |
|
1021 | + { |
|
1022 | + if (false !== ($decompressed = @gzinflate(substr($gzData, 2)))) |
|
1023 | + { |
|
914 | 1024 | return $decompressed; |
915 | 1025 | } |
916 | 1026 | } |
917 | 1027 | |
918 | - if ("\x50\x4b\x03\x04" == substr($gzData, 0, 4)) { |
|
1028 | + if ("\x50\x4b\x03\x04" == substr($gzData, 0, 4)) |
|
1029 | + { |
|
919 | 1030 | // ZIP file format header |
920 | 1031 | // Offset 6: 2 bytes, General-purpose field |
921 | 1032 | // Offset 26: 2 bytes, filename length |
@@ -929,7 +1040,8 @@ discard block |
||
929 | 1040 | // between a compressed document, and a ZIP file |
930 | 1041 | $zip_compressed_on_the_fly = (0x08 == (0x08 & $general_purpose_flag)); |
931 | 1042 | |
932 | - if (!$zip_compressed_on_the_fly) { |
|
1043 | + if (!$zip_compressed_on_the_fly) |
|
1044 | + { |
|
933 | 1045 | // Don't attempt to decode a compressed zip file |
934 | 1046 | return $gzData; |
935 | 1047 | } |
@@ -937,29 +1049,34 @@ discard block |
||
937 | 1049 | // Determine the first byte of data, based on the above ZIP header |
938 | 1050 | // offsets: |
939 | 1051 | $first_file_start = array_sum(unpack('v2', substr($gzData, 26, 4))); |
940 | - if (false !== ($decompressed = @gzinflate(substr($gzData, 30 + $first_file_start)))) { |
|
1052 | + if (false !== ($decompressed = @gzinflate(substr($gzData, 30 + $first_file_start)))) |
|
1053 | + { |
|
941 | 1054 | return $decompressed; |
942 | 1055 | } |
943 | 1056 | return false; |
944 | 1057 | } |
945 | 1058 | |
946 | 1059 | // Finally fall back to straight gzinflate |
947 | - if (false !== ($decompressed = @gzinflate($gzData))) { |
|
1060 | + if (false !== ($decompressed = @gzinflate($gzData))) |
|
1061 | + { |
|
948 | 1062 | return $decompressed; |
949 | 1063 | } |
950 | 1064 | |
951 | 1065 | // Fallback for all above failing, not expected, but included for |
952 | 1066 | // debugging and preventing regressions and to track stats |
953 | - if (false !== ($decompressed = @gzinflate(substr($gzData, 2)))) { |
|
1067 | + if (false !== ($decompressed = @gzinflate(substr($gzData, 2)))) |
|
1068 | + { |
|
954 | 1069 | return $decompressed; |
955 | 1070 | } |
956 | 1071 | |
957 | 1072 | return false; |
958 | 1073 | } |
959 | 1074 | |
960 | - public static function match_domain($host, $reference) { |
|
1075 | + public static function match_domain($host, $reference) |
|
1076 | + { |
|
961 | 1077 | // Check for a direct match |
962 | - if ($host === $reference) { |
|
1078 | + if ($host === $reference) |
|
1079 | + { |
|
963 | 1080 | return true; |
964 | 1081 | } |
965 | 1082 | |
@@ -967,10 +1084,12 @@ discard block |
||
967 | 1084 | // Also validates that the host has 3 parts or more, as per Firefox's |
968 | 1085 | // ruleset. |
969 | 1086 | $parts = explode('.', $host); |
970 | - if (ip2long($host) === false && count($parts) >= 3) { |
|
1087 | + if (ip2long($host) === false && count($parts) >= 3) |
|
1088 | + { |
|
971 | 1089 | $parts[0] = '*'; |
972 | 1090 | $wildcard = implode('.', $parts); |
973 | - if ($wildcard === $reference) { |
|
1091 | + if ($wildcard === $reference) |
|
1092 | + { |
|
974 | 1093 | return true; |
975 | 1094 | } |
976 | 1095 | } |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | $cap_string = serialize($capabilities); |
187 | 187 | |
188 | 188 | // Don't search for a transport if it's already been done for these $capabilities |
189 | - if (isset(self::$transport[$cap_string]) && self::$transport[$cap_string] !== null) { |
|
189 | + if (isset(self::$transport[$cap_string]) && self::$transport[$cap_string] !== NULL) { |
|
190 | 190 | return new self::$transport[$cap_string](); |
191 | 191 | } |
192 | 192 | // @codeCoverageIgnoreEnd |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | break; |
211 | 211 | } |
212 | 212 | } |
213 | - if (self::$transport[$cap_string] === null) { |
|
213 | + if (self::$transport[$cap_string] === NULL) { |
|
214 | 214 | throw new Requests_Exception('No working transports found', 'notransport', self::$transports); |
215 | 215 | } |
216 | 216 | |
@@ -228,28 +228,28 @@ discard block |
||
228 | 228 | * Send a GET request |
229 | 229 | */ |
230 | 230 | public static function get($url, $headers = array(), $options = array()) { |
231 | - return self::request($url, $headers, null, self::GET, $options); |
|
231 | + return self::request($url, $headers, NULL, self::GET, $options); |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | /** |
235 | 235 | * Send a HEAD request |
236 | 236 | */ |
237 | 237 | public static function head($url, $headers = array(), $options = array()) { |
238 | - return self::request($url, $headers, null, self::HEAD, $options); |
|
238 | + return self::request($url, $headers, NULL, self::HEAD, $options); |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | /** |
242 | 242 | * Send a DELETE request |
243 | 243 | */ |
244 | 244 | public static function delete($url, $headers = array(), $options = array()) { |
245 | - return self::request($url, $headers, null, self::DELETE, $options); |
|
245 | + return self::request($url, $headers, NULL, self::DELETE, $options); |
|
246 | 246 | } |
247 | 247 | |
248 | 248 | /** |
249 | 249 | * Send a TRACE request |
250 | 250 | */ |
251 | 251 | public static function trace($url, $headers = array(), $options = array()) { |
252 | - return self::request($url, $headers, null, self::TRACE, $options); |
|
252 | + return self::request($url, $headers, NULL, self::TRACE, $options); |
|
253 | 253 | } |
254 | 254 | /**#@-*/ |
255 | 255 | |
@@ -425,7 +425,7 @@ discard block |
||
425 | 425 | * @return array Responses (either Requests_Response or a Requests_Exception object) |
426 | 426 | */ |
427 | 427 | public static function request_multiple($requests, $options = array()) { |
428 | - $options = array_merge(self::get_default_options(true), $options); |
|
428 | + $options = array_merge(self::get_default_options(TRUE), $options); |
|
429 | 429 | |
430 | 430 | if (!empty($options['hooks'])) { |
431 | 431 | $options['hooks']->register('transport.internal.parse_response', array('Requests', 'parse_multiple')); |
@@ -499,7 +499,7 @@ discard block |
||
499 | 499 | * @param boolean $multirequest Is this a multirequest? |
500 | 500 | * @return array Default option values |
501 | 501 | */ |
502 | - protected static function get_default_options($multirequest = false) { |
|
502 | + protected static function get_default_options($multirequest = FALSE) { |
|
503 | 503 | $defaults = array( |
504 | 504 | 'timeout' => 10, |
505 | 505 | 'connect_timeout' => 10, |
@@ -507,22 +507,22 @@ discard block |
||
507 | 507 | 'protocol_version' => 1.1, |
508 | 508 | 'redirected' => 0, |
509 | 509 | 'redirects' => 10, |
510 | - 'follow_redirects' => true, |
|
511 | - 'blocking' => true, |
|
510 | + 'follow_redirects' => TRUE, |
|
511 | + 'blocking' => TRUE, |
|
512 | 512 | 'type' => self::GET, |
513 | - 'filename' => false, |
|
514 | - 'auth' => false, |
|
515 | - 'proxy' => false, |
|
516 | - 'cookies' => false, |
|
517 | - 'max_bytes' => false, |
|
518 | - 'idn' => true, |
|
519 | - 'hooks' => null, |
|
520 | - 'transport' => null, |
|
513 | + 'filename' => FALSE, |
|
514 | + 'auth' => FALSE, |
|
515 | + 'proxy' => FALSE, |
|
516 | + 'cookies' => FALSE, |
|
517 | + 'max_bytes' => FALSE, |
|
518 | + 'idn' => TRUE, |
|
519 | + 'hooks' => NULL, |
|
520 | + 'transport' => NULL, |
|
521 | 521 | 'verify' => Requests::get_certificate_path(), |
522 | - 'verifyname' => true, |
|
522 | + 'verifyname' => TRUE, |
|
523 | 523 | ); |
524 | - if ($multirequest !== false) { |
|
525 | - $defaults['complete'] = null; |
|
524 | + if ($multirequest !== FALSE) { |
|
525 | + $defaults['complete'] = NULL; |
|
526 | 526 | } |
527 | 527 | return $defaults; |
528 | 528 | } |
@@ -571,14 +571,14 @@ discard block |
||
571 | 571 | if (is_array($options['auth'])) { |
572 | 572 | $options['auth'] = new Requests_Auth_Basic($options['auth']); |
573 | 573 | } |
574 | - if ($options['auth'] !== false) { |
|
574 | + if ($options['auth'] !== FALSE) { |
|
575 | 575 | $options['auth']->register($options['hooks']); |
576 | 576 | } |
577 | 577 | |
578 | 578 | if (is_string($options['proxy']) || is_array($options['proxy'])) { |
579 | 579 | $options['proxy'] = new Requests_Proxy_HTTP($options['proxy']); |
580 | 580 | } |
581 | - if ($options['proxy'] !== false) { |
|
581 | + if ($options['proxy'] !== FALSE) { |
|
582 | 582 | $options['proxy']->register($options['hooks']); |
583 | 583 | } |
584 | 584 | |
@@ -588,11 +588,11 @@ discard block |
||
588 | 588 | elseif (empty($options['cookies'])) { |
589 | 589 | $options['cookies'] = new Requests_Cookie_Jar(); |
590 | 590 | } |
591 | - if ($options['cookies'] !== false) { |
|
591 | + if ($options['cookies'] !== FALSE) { |
|
592 | 592 | $options['cookies']->register($options['hooks']); |
593 | 593 | } |
594 | 594 | |
595 | - if ($options['idn'] !== false) { |
|
595 | + if ($options['idn'] !== FALSE) { |
|
596 | 596 | $iri = new Requests_IRI($url); |
597 | 597 | $iri->host = Requests_IDNAEncoder::encode($iri->ihost); |
598 | 598 | $url = $iri->uri; |
@@ -635,7 +635,7 @@ discard block |
||
635 | 635 | $return->url = $url; |
636 | 636 | |
637 | 637 | if (!$options['filename']) { |
638 | - if (($pos = strpos($headers, "\r\n\r\n")) === false) { |
|
638 | + if (($pos = strpos($headers, "\r\n\r\n")) === FALSE) { |
|
639 | 639 | // Crap! |
640 | 640 | throw new Requests_Exception('Missing header/body separator', 'requests.no_crlf_separator'); |
641 | 641 | } |
@@ -658,7 +658,7 @@ discard block |
||
658 | 658 | $return->protocol_version = (float) $matches[1]; |
659 | 659 | $return->status_code = (int) $matches[2]; |
660 | 660 | if ($return->status_code >= 200 && $return->status_code < 300) { |
661 | - $return->success = true; |
|
661 | + $return->success = TRUE; |
|
662 | 662 | } |
663 | 663 | |
664 | 664 | foreach ($headers as $header) { |
@@ -682,7 +682,7 @@ discard block |
||
682 | 682 | |
683 | 683 | $options['hooks']->dispatch('requests.before_redirect_check', array(&$return, $req_headers, $req_data, $options)); |
684 | 684 | |
685 | - if ($return->is_redirect() && $options['follow_redirects'] === true) { |
|
685 | + if ($return->is_redirect() && $options['follow_redirects'] === TRUE) { |
|
686 | 686 | if (isset($return->headers['location']) && $options['redirected'] < $options['redirects']) { |
687 | 687 | if ($return->status_code === 303) { |
688 | 688 | $options['type'] = self::GET; |
@@ -758,7 +758,7 @@ discard block |
||
758 | 758 | $decoded = ''; |
759 | 759 | $encoded = $data; |
760 | 760 | |
761 | - while (true) { |
|
761 | + while (TRUE) { |
|
762 | 762 | $is_chunked = (bool) preg_match('/^([0-9a-f]+)(?:;(?:[\w-]*)(?:=(?:(?:[\w-]*)*|"(?:[^\r\n])*"))?)*\r\n/i', $encoded, $matches); |
763 | 763 | if (!$is_chunked) { |
764 | 764 | // Looks like it's not chunked after all |
@@ -826,16 +826,16 @@ discard block |
||
826 | 826 | return $data; |
827 | 827 | } |
828 | 828 | |
829 | - if (function_exists('gzdecode') && ($decoded = @gzdecode($data)) !== false) { |
|
829 | + if (function_exists('gzdecode') && ($decoded = @gzdecode($data)) !== FALSE) { |
|
830 | 830 | return $decoded; |
831 | 831 | } |
832 | - elseif (function_exists('gzinflate') && ($decoded = @gzinflate($data)) !== false) { |
|
832 | + elseif (function_exists('gzinflate') && ($decoded = @gzinflate($data)) !== FALSE) { |
|
833 | 833 | return $decoded; |
834 | 834 | } |
835 | - elseif (($decoded = self::compatible_gzinflate($data)) !== false) { |
|
835 | + elseif (($decoded = self::compatible_gzinflate($data)) !== FALSE) { |
|
836 | 836 | return $decoded; |
837 | 837 | } |
838 | - elseif (function_exists('gzuncompress') && ($decoded = @gzuncompress($data)) !== false) { |
|
838 | + elseif (function_exists('gzuncompress') && ($decoded = @gzuncompress($data)) !== FALSE) { |
|
839 | 839 | return $decoded; |
840 | 840 | } |
841 | 841 | |
@@ -884,7 +884,7 @@ discard block |
||
884 | 884 | } |
885 | 885 | } |
886 | 886 | $decompressed = self::compatible_gzinflate(substr($gzData, $i)); |
887 | - if (false !== $decompressed) { |
|
887 | + if (FALSE !== $decompressed) { |
|
888 | 888 | return $decompressed; |
889 | 889 | } |
890 | 890 | } |
@@ -897,7 +897,7 @@ discard block |
||
897 | 897 | // |
898 | 898 | // See https://decompres.blogspot.com/ for a quick explanation of this |
899 | 899 | // data type |
900 | - $huffman_encoded = false; |
|
900 | + $huffman_encoded = FALSE; |
|
901 | 901 | |
902 | 902 | // low nibble of first byte should be 0x08 |
903 | 903 | list(, $first_nibble) = unpack('h', $gzData); |
@@ -906,11 +906,11 @@ discard block |
||
906 | 906 | list(, $first_two_bytes) = unpack('n', $gzData); |
907 | 907 | |
908 | 908 | if (0x08 == $first_nibble && 0 == ($first_two_bytes % 0x1F)) { |
909 | - $huffman_encoded = true; |
|
909 | + $huffman_encoded = TRUE; |
|
910 | 910 | } |
911 | 911 | |
912 | 912 | if ($huffman_encoded) { |
913 | - if (false !== ($decompressed = @gzinflate(substr($gzData, 2)))) { |
|
913 | + if (FALSE !== ($decompressed = @gzinflate(substr($gzData, 2)))) { |
|
914 | 914 | return $decompressed; |
915 | 915 | } |
916 | 916 | } |
@@ -937,44 +937,44 @@ discard block |
||
937 | 937 | // Determine the first byte of data, based on the above ZIP header |
938 | 938 | // offsets: |
939 | 939 | $first_file_start = array_sum(unpack('v2', substr($gzData, 26, 4))); |
940 | - if (false !== ($decompressed = @gzinflate(substr($gzData, 30 + $first_file_start)))) { |
|
940 | + if (FALSE !== ($decompressed = @gzinflate(substr($gzData, 30 + $first_file_start)))) { |
|
941 | 941 | return $decompressed; |
942 | 942 | } |
943 | - return false; |
|
943 | + return FALSE; |
|
944 | 944 | } |
945 | 945 | |
946 | 946 | // Finally fall back to straight gzinflate |
947 | - if (false !== ($decompressed = @gzinflate($gzData))) { |
|
947 | + if (FALSE !== ($decompressed = @gzinflate($gzData))) { |
|
948 | 948 | return $decompressed; |
949 | 949 | } |
950 | 950 | |
951 | 951 | // Fallback for all above failing, not expected, but included for |
952 | 952 | // debugging and preventing regressions and to track stats |
953 | - if (false !== ($decompressed = @gzinflate(substr($gzData, 2)))) { |
|
953 | + if (FALSE !== ($decompressed = @gzinflate(substr($gzData, 2)))) { |
|
954 | 954 | return $decompressed; |
955 | 955 | } |
956 | 956 | |
957 | - return false; |
|
957 | + return FALSE; |
|
958 | 958 | } |
959 | 959 | |
960 | 960 | public static function match_domain($host, $reference) { |
961 | 961 | // Check for a direct match |
962 | 962 | if ($host === $reference) { |
963 | - return true; |
|
963 | + return TRUE; |
|
964 | 964 | } |
965 | 965 | |
966 | 966 | // Calculate the valid wildcard match if the host is not an IP address |
967 | 967 | // Also validates that the host has 3 parts or more, as per Firefox's |
968 | 968 | // ruleset. |
969 | 969 | $parts = explode('.', $host); |
970 | - if (ip2long($host) === false && count($parts) >= 3) { |
|
970 | + if (ip2long($host) === FALSE && count($parts) >= 3) { |
|
971 | 971 | $parts[0] = '*'; |
972 | 972 | $wildcard = implode('.', $parts); |
973 | 973 | if ($wildcard === $reference) { |
974 | - return true; |
|
974 | + return TRUE; |
|
975 | 975 | } |
976 | 976 | } |
977 | 977 | |
978 | - return false; |
|
978 | + return FALSE; |
|
979 | 979 | } |
980 | 980 | } |
@@ -1,6 +1,7 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -class SendJodel extends AbstractRequest { |
|
3 | +class SendJodel extends AbstractRequest |
|
4 | +{ |
|
4 | 5 | /** |
5 | 6 | * @var Location |
6 | 7 | */ |
@@ -1,26 +1,26 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | class SendJodel extends AbstractRequest { |
4 | - public $location; |
|
5 | - public $ancestor = ""; |
|
6 | - public $color = ""; |
|
4 | + public $location; |
|
5 | + public $ancestor = ""; |
|
6 | + public $color = ""; |
|
7 | 7 | |
8 | - function getApiEndPoint() |
|
9 | - { |
|
10 | - return '/v3/posts/'; |
|
11 | - } |
|
8 | + function getApiEndPoint() |
|
9 | + { |
|
10 | + return '/v3/posts/'; |
|
11 | + } |
|
12 | 12 | |
13 | - function getPayload() |
|
14 | - { |
|
15 | - return array( |
|
13 | + function getPayload() |
|
14 | + { |
|
15 | + return array( |
|
16 | 16 | "ancestor" => $this->ancestor, |
17 | 17 | "color" => $this->color, |
18 | - "location" => $this->location->toArray(), |
|
19 | - "message" => $_POST['message'], |
|
20 | - ); |
|
21 | - } |
|
22 | - function getMethod() |
|
23 | - { |
|
24 | - return 'POST'; |
|
25 | - } |
|
18 | + "location" => $this->location->toArray(), |
|
19 | + "message" => $_POST['message'], |
|
20 | + ); |
|
21 | + } |
|
22 | + function getMethod() |
|
23 | + { |
|
24 | + return 'POST'; |
|
25 | + } |
|
26 | 26 | } |
@@ -1,7 +1,8 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | |
4 | -class UpdateLocation extends AbstractRequest { |
|
4 | +class UpdateLocation extends AbstractRequest |
|
5 | +{ |
|
5 | 6 | /** |
6 | 7 | * @var Location |
7 | 8 | */ |
@@ -3,37 +3,37 @@ |
||
3 | 3 | |
4 | 4 | class UpdateLocation extends AbstractRequest { |
5 | 5 | /** |
6 | - * @var Location |
|
7 | - */ |
|
8 | - public $location; |
|
9 | - /** |
|
10 | - * @return Location |
|
11 | - */ |
|
12 | - public function getLocation() |
|
13 | - { |
|
14 | - return $this->location; |
|
15 | - } |
|
16 | - /** |
|
17 | - * @param Location $location |
|
18 | - */ |
|
19 | - public function setLocation($location) |
|
20 | - { |
|
21 | - $this->location = $location; |
|
22 | - } |
|
6 | + * @var Location |
|
7 | + */ |
|
8 | + public $location; |
|
9 | + /** |
|
10 | + * @return Location |
|
11 | + */ |
|
12 | + public function getLocation() |
|
13 | + { |
|
14 | + return $this->location; |
|
15 | + } |
|
16 | + /** |
|
17 | + * @param Location $location |
|
18 | + */ |
|
19 | + public function setLocation($location) |
|
20 | + { |
|
21 | + $this->location = $location; |
|
22 | + } |
|
23 | 23 | |
24 | - function getApiEndPoint() |
|
25 | - { |
|
26 | - return '/v2/users/location'; |
|
27 | - } |
|
28 | - function getPayload() |
|
29 | - { |
|
30 | - return array( |
|
24 | + function getApiEndPoint() |
|
25 | + { |
|
26 | + return '/v2/users/location'; |
|
27 | + } |
|
28 | + function getPayload() |
|
29 | + { |
|
30 | + return array( |
|
31 | 31 | "location" => $this->getLocation()->toArray(), |
32 | - ); |
|
33 | - } |
|
34 | - function getMethod() |
|
35 | - { |
|
36 | - return 'PUT'; |
|
37 | - } |
|
32 | + ); |
|
33 | + } |
|
34 | + function getMethod() |
|
35 | + { |
|
36 | + return 'PUT'; |
|
37 | + } |
|
38 | 38 | } |
39 | 39 |