@@ -10,7 +10,8 @@ |
||
| 10 | 10 | * |
| 11 | 11 | * @package Requests |
| 12 | 12 | */ |
| 13 | -class Requests_Exception_HTTP_400 extends Requests_Exception_HTTP { |
|
| 13 | +class Requests_Exception_HTTP_400 extends Requests_Exception_HTTP |
|
| 14 | +{ |
|
| 14 | 15 | /** |
| 15 | 16 | * HTTP status code |
| 16 | 17 | * |
@@ -10,7 +10,8 @@ |
||
| 10 | 10 | * |
| 11 | 11 | * @package Requests |
| 12 | 12 | */ |
| 13 | -class Requests_Exception_HTTP_404 extends Requests_Exception_HTTP { |
|
| 13 | +class Requests_Exception_HTTP_404 extends Requests_Exception_HTTP |
|
| 14 | +{ |
|
| 14 | 15 | /** |
| 15 | 16 | * HTTP status code |
| 16 | 17 | * |
@@ -10,7 +10,8 @@ |
||
| 10 | 10 | * |
| 11 | 11 | * @package Requests |
| 12 | 12 | */ |
| 13 | -class Requests_Exception_HTTP_417 extends Requests_Exception_HTTP { |
|
| 13 | +class Requests_Exception_HTTP_417 extends Requests_Exception_HTTP |
|
| 14 | +{ |
|
| 14 | 15 | /** |
| 15 | 16 | * HTTP status code |
| 16 | 17 | * |
@@ -10,7 +10,8 @@ |
||
| 10 | 10 | * |
| 11 | 11 | * @package Requests |
| 12 | 12 | */ |
| 13 | -class Requests_Exception_HTTP_305 extends Requests_Exception_HTTP { |
|
| 13 | +class Requests_Exception_HTTP_305 extends Requests_Exception_HTTP |
|
| 14 | +{ |
|
| 14 | 15 | /** |
| 15 | 16 | * HTTP status code |
| 16 | 17 | * |
@@ -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 | } |
@@ -12,7 +12,8 @@ discard block |
||
| 12 | 12 | * @package Requests |
| 13 | 13 | * @subpackage Utilities |
| 14 | 14 | */ |
| 15 | -class Requests_Hooks implements Requests_Hooker { |
|
| 15 | +class Requests_Hooks implements Requests_Hooker |
|
| 16 | +{ |
|
| 16 | 17 | /** |
| 17 | 18 | * Registered callbacks for each hook |
| 18 | 19 | * |
@@ -23,7 +24,8 @@ discard block |
||
| 23 | 24 | /** |
| 24 | 25 | * Constructor |
| 25 | 26 | */ |
| 26 | - public function __construct() { |
|
| 27 | + public function __construct() |
|
| 28 | + { |
|
| 27 | 29 | // pass |
| 28 | 30 | } |
| 29 | 31 | |
@@ -34,11 +36,14 @@ discard block |
||
| 34 | 36 | * @param callback $callback Function/method to call on event |
| 35 | 37 | * @param int $priority Priority number. <0 is executed earlier, >0 is executed later |
| 36 | 38 | */ |
| 37 | - public function register($hook, $callback, $priority = 0) { |
|
| 38 | - if (!isset($this->hooks[$hook])) { |
|
| 39 | + public function register($hook, $callback, $priority = 0) |
|
| 40 | + { |
|
| 41 | + if (!isset($this->hooks[$hook])) |
|
| 42 | + { |
|
| 39 | 43 | $this->hooks[$hook] = array(); |
| 40 | 44 | } |
| 41 | - if (!isset($this->hooks[$hook][$priority])) { |
|
| 45 | + if (!isset($this->hooks[$hook][$priority])) |
|
| 46 | + { |
|
| 42 | 47 | $this->hooks[$hook][$priority] = array(); |
| 43 | 48 | } |
| 44 | 49 | |
@@ -52,13 +57,17 @@ discard block |
||
| 52 | 57 | * @param array $parameters Parameters to pass to callbacks |
| 53 | 58 | * @return boolean Successfulness |
| 54 | 59 | */ |
| 55 | - public function dispatch($hook, $parameters = array()) { |
|
| 56 | - if (empty($this->hooks[$hook])) { |
|
| 60 | + public function dispatch($hook, $parameters = array()) |
|
| 61 | + { |
|
| 62 | + if (empty($this->hooks[$hook])) |
|
| 63 | + { |
|
| 57 | 64 | return false; |
| 58 | 65 | } |
| 59 | 66 | |
| 60 | - foreach ($this->hooks[$hook] as $priority => $hooked) { |
|
| 61 | - foreach ($hooked as $callback) { |
|
| 67 | + foreach ($this->hooks[$hook] as $priority => $hooked) |
|
| 68 | + { |
|
| 69 | + foreach ($hooked as $callback) |
|
| 70 | + { |
|
| 62 | 71 | call_user_func_array($callback, $parameters); |
| 63 | 72 | } |
| 64 | 73 | } |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | */ |
| 55 | 55 | public function dispatch($hook, $parameters = array()) { |
| 56 | 56 | if (empty($this->hooks[$hook])) { |
| 57 | - return false; |
|
| 57 | + return FALSE; |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | foreach ($this->hooks[$hook] as $priority => $hooked) { |
@@ -63,6 +63,6 @@ discard block |
||
| 63 | 63 | } |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - return true; |
|
| 66 | + return TRUE; |
|
| 67 | 67 | } |
| 68 | 68 | } |
| 69 | 69 | \ No newline at end of file |
@@ -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 | } |