@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | $options['hooks']->dispatch('fsockopen.before_request'); |
60 | 60 | |
61 | 61 | $url_parts = parse_url($url); |
62 | - if (empty($url_parts)) { |
|
62 | + if(empty($url_parts)) { |
|
63 | 63 | throw new Requests_Exception('Invalid URL.', 'invalidurl', $url); |
64 | 64 | } |
65 | 65 | $host = $url_parts['host']; |
@@ -68,9 +68,9 @@ discard block |
||
68 | 68 | $case_insensitive_headers = new Requests_Utility_CaseInsensitiveDictionary($headers); |
69 | 69 | |
70 | 70 | // HTTPS support |
71 | - if (isset($url_parts['scheme']) && strtolower($url_parts['scheme']) === 'https') { |
|
71 | + if(isset($url_parts['scheme']) && strtolower($url_parts['scheme']) === 'https') { |
|
72 | 72 | $remote_socket = 'ssl://' . $host; |
73 | - if (!isset($url_parts['port'])) { |
|
73 | + if(!isset($url_parts['port'])) { |
|
74 | 74 | $url_parts['port'] = 443; |
75 | 75 | } |
76 | 76 | |
@@ -82,23 +82,23 @@ discard block |
||
82 | 82 | $verifyname = true; |
83 | 83 | |
84 | 84 | // SNI, if enabled (OpenSSL >=0.9.8j) |
85 | - if (defined('OPENSSL_TLSEXT_SERVER_NAME') && OPENSSL_TLSEXT_SERVER_NAME) { |
|
85 | + if(defined('OPENSSL_TLSEXT_SERVER_NAME') && OPENSSL_TLSEXT_SERVER_NAME) { |
|
86 | 86 | $context_options['SNI_enabled'] = true; |
87 | - if (isset($options['verifyname']) && $options['verifyname'] === false) { |
|
87 | + if(isset($options['verifyname']) && $options['verifyname'] === false) { |
|
88 | 88 | $context_options['SNI_enabled'] = false; |
89 | 89 | } |
90 | 90 | } |
91 | 91 | |
92 | - if (isset($options['verify'])) { |
|
93 | - if ($options['verify'] === false) { |
|
92 | + if(isset($options['verify'])) { |
|
93 | + if($options['verify'] === false) { |
|
94 | 94 | $context_options['verify_peer'] = false; |
95 | 95 | } |
96 | - elseif (is_string($options['verify'])) { |
|
96 | + elseif(is_string($options['verify'])) { |
|
97 | 97 | $context_options['cafile'] = $options['verify']; |
98 | 98 | } |
99 | 99 | } |
100 | 100 | |
101 | - if (isset($options['verifyname']) && $options['verifyname'] === false) { |
|
101 | + if(isset($options['verifyname']) && $options['verifyname'] === false) { |
|
102 | 102 | $context_options['verify_peer_name'] = false; |
103 | 103 | $verifyname = false; |
104 | 104 | } |
@@ -111,12 +111,12 @@ discard block |
||
111 | 111 | |
112 | 112 | $this->max_bytes = $options['max_bytes']; |
113 | 113 | |
114 | - if (!isset($url_parts['port'])) { |
|
114 | + if(!isset($url_parts['port'])) { |
|
115 | 115 | $url_parts['port'] = 80; |
116 | 116 | } |
117 | 117 | $remote_socket .= ':' . $url_parts['port']; |
118 | 118 | |
119 | - set_error_handler(array($this, 'connect_error_handler'), E_WARNING | E_NOTICE); |
|
119 | + set_error_handler(array($this, 'connect_error_handler'), E_WARNING|E_NOTICE); |
|
120 | 120 | |
121 | 121 | $options['hooks']->dispatch('fsockopen.remote_socket', array(&$remote_socket)); |
122 | 122 | |
@@ -124,12 +124,12 @@ discard block |
||
124 | 124 | |
125 | 125 | restore_error_handler(); |
126 | 126 | |
127 | - if ($verifyname && !$this->verify_certificate_from_context($host, $context)) { |
|
127 | + if($verifyname && !$this->verify_certificate_from_context($host, $context)) { |
|
128 | 128 | throw new Requests_Exception('SSL certificate did not match the requested domain name', 'ssl.no_match'); |
129 | 129 | } |
130 | 130 | |
131 | - if (!$socket) { |
|
132 | - if ($errno === 0) { |
|
131 | + if(!$socket) { |
|
132 | + if($errno === 0) { |
|
133 | 133 | // Connection issue |
134 | 134 | throw new Requests_Exception(rtrim($this->connect_error), 'fsockopen.connect_error'); |
135 | 135 | } |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | |
140 | 140 | $data_format = $options['data_format']; |
141 | 141 | |
142 | - if ($data_format === 'query') { |
|
142 | + if($data_format === 'query') { |
|
143 | 143 | $path = self::format_get($url_parts, $data); |
144 | 144 | $data = ''; |
145 | 145 | } |
@@ -152,56 +152,56 @@ discard block |
||
152 | 152 | $request_body = ''; |
153 | 153 | $out = sprintf("%s %s HTTP/%.1f\r\n", $options['type'], $path, $options['protocol_version']); |
154 | 154 | |
155 | - if ($options['type'] !== Requests::TRACE) { |
|
156 | - if (is_array($data)) { |
|
155 | + if($options['type'] !== Requests::TRACE) { |
|
156 | + if(is_array($data)) { |
|
157 | 157 | $request_body = http_build_query($data, null, '&'); |
158 | 158 | } |
159 | 159 | else { |
160 | 160 | $request_body = $data; |
161 | 161 | } |
162 | 162 | |
163 | - if (!empty($data)) { |
|
164 | - if (!isset($case_insensitive_headers['Content-Length'])) { |
|
163 | + if(!empty($data)) { |
|
164 | + if(!isset($case_insensitive_headers['Content-Length'])) { |
|
165 | 165 | $headers['Content-Length'] = strlen($request_body); |
166 | 166 | } |
167 | 167 | |
168 | - if (!isset($case_insensitive_headers['Content-Type'])) { |
|
168 | + if(!isset($case_insensitive_headers['Content-Type'])) { |
|
169 | 169 | $headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8'; |
170 | 170 | } |
171 | 171 | } |
172 | 172 | } |
173 | 173 | |
174 | - if (!isset($case_insensitive_headers['Host'])) { |
|
174 | + if(!isset($case_insensitive_headers['Host'])) { |
|
175 | 175 | $out .= sprintf('Host: %s', $url_parts['host']); |
176 | 176 | |
177 | - if (( 'http' === strtolower($url_parts['scheme']) && $url_parts['port'] !== 80 ) || ( 'https' === strtolower($url_parts['scheme']) && $url_parts['port'] !== 443 )) { |
|
177 | + if(('http' === strtolower($url_parts['scheme']) && $url_parts['port'] !== 80) || ('https' === strtolower($url_parts['scheme']) && $url_parts['port'] !== 443)) { |
|
178 | 178 | $out .= ':' . $url_parts['port']; |
179 | 179 | } |
180 | 180 | $out .= "\r\n"; |
181 | 181 | } |
182 | 182 | |
183 | - if (!isset($case_insensitive_headers['User-Agent'])) { |
|
183 | + if(!isset($case_insensitive_headers['User-Agent'])) { |
|
184 | 184 | $out .= sprintf("User-Agent: %s\r\n", $options['useragent']); |
185 | 185 | } |
186 | 186 | |
187 | 187 | $accept_encoding = $this->accept_encoding(); |
188 | - if (!isset($case_insensitive_headers['Accept-Encoding']) && !empty($accept_encoding)) { |
|
188 | + if(!isset($case_insensitive_headers['Accept-Encoding']) && !empty($accept_encoding)) { |
|
189 | 189 | $out .= sprintf("Accept-Encoding: %s\r\n", $accept_encoding); |
190 | 190 | } |
191 | 191 | |
192 | 192 | $headers = Requests::flatten($headers); |
193 | 193 | |
194 | - if (!empty($headers)) { |
|
194 | + if(!empty($headers)) { |
|
195 | 195 | $out .= implode($headers, "\r\n") . "\r\n"; |
196 | 196 | } |
197 | 197 | |
198 | 198 | $options['hooks']->dispatch('fsockopen.after_headers', array(&$out)); |
199 | 199 | |
200 | - if (substr($out, -2) !== "\r\n") { |
|
200 | + if(substr($out, -2) !== "\r\n") { |
|
201 | 201 | $out .= "\r\n"; |
202 | 202 | } |
203 | 203 | |
204 | - if (!isset($case_insensitive_headers['Connection'])) { |
|
204 | + if(!isset($case_insensitive_headers['Connection'])) { |
|
205 | 205 | $out .= "Connection: Close\r\n"; |
206 | 206 | } |
207 | 207 | |
@@ -212,15 +212,15 @@ discard block |
||
212 | 212 | fwrite($socket, $out); |
213 | 213 | $options['hooks']->dispatch('fsockopen.after_send', array($out)); |
214 | 214 | |
215 | - if (!$options['blocking']) { |
|
215 | + if(!$options['blocking']) { |
|
216 | 216 | fclose($socket); |
217 | 217 | $fake_headers = ''; |
218 | 218 | $options['hooks']->dispatch('fsockopen.after_request', array(&$fake_headers)); |
219 | 219 | return ''; |
220 | 220 | } |
221 | 221 | |
222 | - $timeout_sec = (int) floor($options['timeout']); |
|
223 | - if ($timeout_sec == $options['timeout']) { |
|
222 | + $timeout_sec = (int)floor($options['timeout']); |
|
223 | + if($timeout_sec == $options['timeout']) { |
|
224 | 224 | $timeout_msec = 0; |
225 | 225 | } |
226 | 226 | else { |
@@ -233,35 +233,35 @@ discard block |
||
233 | 233 | $size = 0; |
234 | 234 | $doingbody = false; |
235 | 235 | $download = false; |
236 | - if ($options['filename']) { |
|
236 | + if($options['filename']) { |
|
237 | 237 | $download = fopen($options['filename'], 'wb'); |
238 | 238 | } |
239 | 239 | |
240 | - while (!feof($socket)) { |
|
240 | + while(!feof($socket)) { |
|
241 | 241 | $this->info = stream_get_meta_data($socket); |
242 | - if ($this->info['timed_out']) { |
|
242 | + if($this->info['timed_out']) { |
|
243 | 243 | throw new Requests_Exception('fsocket timed out', 'timeout'); |
244 | 244 | } |
245 | 245 | |
246 | 246 | $block = fread($socket, Requests::BUFFER_SIZE); |
247 | - if (!$doingbody) { |
|
247 | + if(!$doingbody) { |
|
248 | 248 | $response .= $block; |
249 | - if (strpos($response, "\r\n\r\n")) { |
|
249 | + if(strpos($response, "\r\n\r\n")) { |
|
250 | 250 | list($headers, $block) = explode("\r\n\r\n", $response, 2); |
251 | 251 | $doingbody = true; |
252 | 252 | } |
253 | 253 | } |
254 | 254 | |
255 | 255 | // Are we in body mode now? |
256 | - if ($doingbody) { |
|
256 | + if($doingbody) { |
|
257 | 257 | $options['hooks']->dispatch('request.progress', array($block, $size, $this->max_bytes)); |
258 | 258 | $data_length = strlen($block); |
259 | - if ($this->max_bytes) { |
|
259 | + if($this->max_bytes) { |
|
260 | 260 | // Have we already hit a limit? |
261 | - if ($size === $this->max_bytes) { |
|
261 | + if($size === $this->max_bytes) { |
|
262 | 262 | continue; |
263 | 263 | } |
264 | - if (($size + $data_length) > $this->max_bytes) { |
|
264 | + if(($size + $data_length) > $this->max_bytes) { |
|
265 | 265 | // Limit the length |
266 | 266 | $limited_length = ($this->max_bytes - $size); |
267 | 267 | $block = substr($block, 0, $limited_length); |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | } |
270 | 270 | |
271 | 271 | $size += strlen($block); |
272 | - if ($download) { |
|
272 | + if($download) { |
|
273 | 273 | fwrite($download, $block); |
274 | 274 | } |
275 | 275 | else { |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | } |
280 | 280 | $this->headers = $headers; |
281 | 281 | |
282 | - if ($download) { |
|
282 | + if($download) { |
|
283 | 283 | fclose($download); |
284 | 284 | } |
285 | 285 | else { |
@@ -301,18 +301,18 @@ discard block |
||
301 | 301 | public function request_multiple($requests, $options) { |
302 | 302 | $responses = array(); |
303 | 303 | $class = get_class($this); |
304 | - foreach ($requests as $id => $request) { |
|
304 | + foreach($requests as $id => $request) { |
|
305 | 305 | try { |
306 | 306 | $handler = new $class(); |
307 | 307 | $responses[$id] = $handler->request($request['url'], $request['headers'], $request['data'], $request['options']); |
308 | 308 | |
309 | 309 | $request['options']['hooks']->dispatch('transport.internal.parse_response', array(&$responses[$id], $request)); |
310 | 310 | } |
311 | - catch (Requests_Exception $e) { |
|
311 | + catch(Requests_Exception $e) { |
|
312 | 312 | $responses[$id] = $e; |
313 | 313 | } |
314 | 314 | |
315 | - if (!is_string($responses[$id])) { |
|
315 | + if(!is_string($responses[$id])) { |
|
316 | 316 | $request['options']['hooks']->dispatch('multiple.request.complete', array(&$responses[$id], $id)); |
317 | 317 | } |
318 | 318 | } |
@@ -327,11 +327,11 @@ discard block |
||
327 | 327 | */ |
328 | 328 | protected static function accept_encoding() { |
329 | 329 | $type = array(); |
330 | - if (function_exists('gzinflate')) { |
|
330 | + if(function_exists('gzinflate')) { |
|
331 | 331 | $type[] = 'deflate;q=1.0'; |
332 | 332 | } |
333 | 333 | |
334 | - if (function_exists('gzuncompress')) { |
|
334 | + if(function_exists('gzuncompress')) { |
|
335 | 335 | $type[] = 'compress;q=0.5'; |
336 | 336 | } |
337 | 337 | |
@@ -348,16 +348,16 @@ discard block |
||
348 | 348 | * @return string URL with data |
349 | 349 | */ |
350 | 350 | protected static function format_get($url_parts, $data) { |
351 | - if (!empty($data)) { |
|
352 | - if (empty($url_parts['query'])) { |
|
351 | + if(!empty($data)) { |
|
352 | + if(empty($url_parts['query'])) { |
|
353 | 353 | $url_parts['query'] = ''; |
354 | 354 | } |
355 | 355 | |
356 | 356 | $url_parts['query'] .= '&' . http_build_query($data, null, '&'); |
357 | 357 | $url_parts['query'] = trim($url_parts['query'], '&'); |
358 | 358 | } |
359 | - if (isset($url_parts['path'])) { |
|
360 | - if (isset($url_parts['query'])) { |
|
359 | + if(isset($url_parts['path'])) { |
|
360 | + if(isset($url_parts['query'])) { |
|
361 | 361 | $get = $url_parts['path'] . '?' . $url_parts['query']; |
362 | 362 | } |
363 | 363 | else { |
@@ -378,7 +378,7 @@ discard block |
||
378 | 378 | */ |
379 | 379 | public function connect_error_handler($errno, $errstr) { |
380 | 380 | // Double-check we can handle it |
381 | - if (($errno & E_WARNING) === 0 && ($errno & E_NOTICE) === 0) { |
|
381 | + if(($errno&E_WARNING) === 0 && ($errno&E_NOTICE) === 0) { |
|
382 | 382 | // Return false to indicate the default error handler should engage |
383 | 383 | return false; |
384 | 384 | } |
@@ -407,7 +407,7 @@ discard block |
||
407 | 407 | |
408 | 408 | // If we don't have SSL options, then we couldn't make the connection at |
409 | 409 | // all |
410 | - if (empty($meta) || empty($meta['ssl']) || empty($meta['ssl']['peer_certificate'])) { |
|
410 | + if(empty($meta) || empty($meta['ssl']) || empty($meta['ssl']['peer_certificate'])) { |
|
411 | 411 | throw new Requests_Exception(rtrim($this->connect_error), 'ssl.connect_error'); |
412 | 412 | } |
413 | 413 | |
@@ -423,18 +423,18 @@ discard block |
||
423 | 423 | * @return boolean True if the transport is valid, false otherwise. |
424 | 424 | */ |
425 | 425 | public static function test($capabilities = array()) { |
426 | - if (!function_exists('fsockopen')) { |
|
426 | + if(!function_exists('fsockopen')) { |
|
427 | 427 | return false; |
428 | 428 | } |
429 | 429 | |
430 | 430 | // If needed, check that streams support SSL |
431 | - if (isset($capabilities['ssl']) && $capabilities['ssl']) { |
|
432 | - if (!extension_loaded('openssl') || !function_exists('openssl_x509_parse')) { |
|
431 | + if(isset($capabilities['ssl']) && $capabilities['ssl']) { |
|
432 | + if(!extension_loaded('openssl') || !function_exists('openssl_x509_parse')) { |
|
433 | 433 | return false; |
434 | 434 | } |
435 | 435 | |
436 | 436 | // Currently broken, thanks to https://github.com/facebook/hhvm/issues/2156 |
437 | - if (defined('HHVM_VERSION')) { |
|
437 | + if(defined('HHVM_VERSION')) { |
|
438 | 438 | return false; |
439 | 439 | } |
440 | 440 | } |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | $this->data = $data; |
70 | 70 | $this->options = $options; |
71 | 71 | |
72 | - if (empty($this->options['cookies'])) { |
|
72 | + if(empty($this->options['cookies'])) { |
|
73 | 73 | $this->options['cookies'] = new Requests_Cookie_Jar(); |
74 | 74 | } |
75 | 75 | } |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | * @return mixed|null Property value, null if none found |
82 | 82 | */ |
83 | 83 | public function __get($key) { |
84 | - if (isset($this->options[$key])) { |
|
84 | + if(isset($this->options[$key])) { |
|
85 | 85 | return $this->options[$key]; |
86 | 86 | } |
87 | 87 | |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | * @param string $key Property key |
114 | 114 | */ |
115 | 115 | public function __unset($key) { |
116 | - if (isset($this->options[$key])) { |
|
116 | + if(isset($this->options[$key])) { |
|
117 | 117 | unset($this->options[$key]); |
118 | 118 | } |
119 | 119 | } |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | * @return array Responses (either Requests_Response or a Requests_Exception object) |
216 | 216 | */ |
217 | 217 | public function request_multiple($requests, $options = array()) { |
218 | - foreach ($requests as $key => $request) { |
|
218 | + foreach($requests as $key => $request) { |
|
219 | 219 | $requests[$key] = $this->merge_request($request, false); |
220 | 220 | } |
221 | 221 | |
@@ -235,26 +235,26 @@ discard block |
||
235 | 235 | * @return array Request data |
236 | 236 | */ |
237 | 237 | protected function merge_request($request, $merge_options = true) { |
238 | - if ($this->url !== null) { |
|
238 | + if($this->url !== null) { |
|
239 | 239 | $request['url'] = Requests_IRI::absolutize($this->url, $request['url']); |
240 | 240 | $request['url'] = $request['url']->uri; |
241 | 241 | } |
242 | 242 | |
243 | - if (empty($request['headers'])) { |
|
243 | + if(empty($request['headers'])) { |
|
244 | 244 | $request['headers'] = array(); |
245 | 245 | } |
246 | 246 | $request['headers'] = array_merge($this->headers, $request['headers']); |
247 | 247 | |
248 | - if (empty($request['data'])) { |
|
249 | - if (is_array($this->data)) { |
|
248 | + if(empty($request['data'])) { |
|
249 | + if(is_array($this->data)) { |
|
250 | 250 | $request['data'] = $this->data; |
251 | 251 | } |
252 | 252 | } |
253 | - elseif (is_array($request['data']) && is_array($this->data)) { |
|
253 | + elseif(is_array($request['data']) && is_array($this->data)) { |
|
254 | 254 | $request['data'] = array_merge($this->data, $request['data']); |
255 | 255 | } |
256 | 256 | |
257 | - if ($merge_options !== false) { |
|
257 | + if($merge_options !== false) { |
|
258 | 258 | $request['options'] = array_merge($this->options, $request['options']); |
259 | 259 | |
260 | 260 | // Disallow forcing the type, as that's a per request setting |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * @param array $data Dictionary/map to convert to case-insensitive |
27 | 27 | */ |
28 | 28 | public function __construct(array $data = array()) { |
29 | - foreach ($data as $key => $value) { |
|
29 | + foreach($data as $key => $value) { |
|
30 | 30 | $this->offsetSet($key, $value); |
31 | 31 | } |
32 | 32 | } |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | */ |
51 | 51 | public function offsetGet($key) { |
52 | 52 | $key = strtolower($key); |
53 | - if (!isset($this->data[$key])) { |
|
53 | + if(!isset($this->data[$key])) { |
|
54 | 54 | return null; |
55 | 55 | } |
56 | 56 | |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | * @param string $value Item value |
67 | 67 | */ |
68 | 68 | public function offsetSet($key, $value) { |
69 | - if ($key === null) { |
|
69 | + if($key === null) { |
|
70 | 70 | throw new Requests_Exception('Object is a dictionary, not a list', 'invalidset'); |
71 | 71 | } |
72 | 72 |
@@ -30,15 +30,15 @@ |
||
30 | 30 | protected $reason = 'Unknown'; |
31 | 31 | |
32 | 32 | public function __construct($message, $type, $data = null, $code = 0) { |
33 | - if ($type !== null) { |
|
33 | + if($type !== null) { |
|
34 | 34 | $this->type = $type; |
35 | 35 | } |
36 | 36 | |
37 | - if ($code !== null) { |
|
37 | + if($code !== null) { |
|
38 | 38 | $this->code = $code; |
39 | 39 | } |
40 | 40 | |
41 | - if ($message !== null) { |
|
41 | + if($message !== null) { |
|
42 | 42 | $this->reason = $message; |
43 | 43 | } |
44 | 44 |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | * @param mixed $data Associated data |
36 | 36 | */ |
37 | 37 | public function __construct($reason = null, $data = null) { |
38 | - if ($reason !== null) { |
|
38 | + if($reason !== null) { |
|
39 | 39 | $this->reason = $reason; |
40 | 40 | } |
41 | 41 | |
@@ -57,12 +57,12 @@ discard block |
||
57 | 57 | * @return string Exception class name to use |
58 | 58 | */ |
59 | 59 | public static function get_class($code) { |
60 | - if (!$code) { |
|
60 | + if(!$code) { |
|
61 | 61 | return 'Requests_Exception_HTTP_Unknown'; |
62 | 62 | } |
63 | 63 | |
64 | 64 | $class = sprintf('Requests_Exception_HTTP_%d', $code); |
65 | - if (class_exists($class)) { |
|
65 | + if(class_exists($class)) { |
|
66 | 66 | return $class; |
67 | 67 | } |
68 | 68 |
@@ -35,7 +35,7 @@ |
||
35 | 35 | * @param mixed $data Associated data |
36 | 36 | */ |
37 | 37 | public function __construct($reason = null, $data = null) { |
38 | - if ($data instanceof Requests_Response) { |
|
38 | + if($data instanceof Requests_Response) { |
|
39 | 39 | $this->code = $data->status_code; |
40 | 40 | } |
41 | 41 |
@@ -35,10 +35,10 @@ discard block |
||
35 | 35 | * @param int $priority Priority number. <0 is executed earlier, >0 is executed later |
36 | 36 | */ |
37 | 37 | public function register($hook, $callback, $priority = 0) { |
38 | - if (!isset($this->hooks[$hook])) { |
|
38 | + if(!isset($this->hooks[$hook])) { |
|
39 | 39 | $this->hooks[$hook] = array(); |
40 | 40 | } |
41 | - if (!isset($this->hooks[$hook][$priority])) { |
|
41 | + if(!isset($this->hooks[$hook][$priority])) { |
|
42 | 42 | $this->hooks[$hook][$priority] = array(); |
43 | 43 | } |
44 | 44 | |
@@ -53,12 +53,12 @@ discard block |
||
53 | 53 | * @return boolean Successfulness |
54 | 54 | */ |
55 | 55 | public function dispatch($hook, $parameters = array()) { |
56 | - if (empty($this->hooks[$hook])) { |
|
56 | + if(empty($this->hooks[$hook])) { |
|
57 | 57 | return false; |
58 | 58 | } |
59 | 59 | |
60 | - foreach ($this->hooks[$hook] as $priority => $hooked) { |
|
61 | - foreach ($hooked as $callback) { |
|
60 | + foreach($this->hooks[$hook] as $priority => $hooked) { |
|
61 | + foreach($hooked as $callback) { |
|
62 | 62 | call_user_func_array($callback, $parameters); |
63 | 63 | } |
64 | 64 | } |
@@ -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 | } |
@@ -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 | } |