@@ -1,7 +1,8 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | |
| 4 | -class SetLocation extends AbstractRequest { |
|
| 4 | +class SetLocation extends AbstractRequest |
|
| 5 | +{ |
|
| 5 | 6 | /** |
| 6 | 7 | * @var Location |
| 7 | 8 | */ |
@@ -3,37 +3,37 @@ |
||
| 3 | 3 | |
| 4 | 4 | class SetLocation 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 | |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | * @return Requests_Cookie |
| 37 | 37 | */ |
| 38 | 38 | public function normalize_cookie($cookie, $key = null) { |
| 39 | - if ($cookie instanceof Requests_Cookie) { |
|
| 39 | + if($cookie instanceof Requests_Cookie) { |
|
| 40 | 40 | return $cookie; |
| 41 | 41 | } |
| 42 | 42 | |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | * @return string Item value |
| 72 | 72 | */ |
| 73 | 73 | public function offsetGet($key) { |
| 74 | - if (!isset($this->cookies[$key])) { |
|
| 74 | + if(!isset($this->cookies[$key])) { |
|
| 75 | 75 | return null; |
| 76 | 76 | } |
| 77 | 77 | |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | * @param string $value Item value |
| 88 | 88 | */ |
| 89 | 89 | public function offsetSet($key, $value) { |
| 90 | - if ($key === null) { |
|
| 90 | + if($key === null) { |
|
| 91 | 91 | throw new Requests_Exception('Object is a dictionary, not a list', 'invalidset'); |
| 92 | 92 | } |
| 93 | 93 | |
@@ -134,21 +134,21 @@ discard block |
||
| 134 | 134 | * @param array $options |
| 135 | 135 | */ |
| 136 | 136 | public function before_request($url, &$headers, &$data, &$type, &$options) { |
| 137 | - if (!$url instanceof Requests_IRI) { |
|
| 137 | + if(!$url instanceof Requests_IRI) { |
|
| 138 | 138 | $url = new Requests_IRI($url); |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - if (!empty($this->cookies)) { |
|
| 141 | + if(!empty($this->cookies)) { |
|
| 142 | 142 | $cookies = array(); |
| 143 | - foreach ($this->cookies as $key => $cookie) { |
|
| 143 | + foreach($this->cookies as $key => $cookie) { |
|
| 144 | 144 | $cookie = $this->normalize_cookie($cookie, $key); |
| 145 | 145 | |
| 146 | 146 | // Skip expired cookies |
| 147 | - if ($cookie->is_expired()) { |
|
| 147 | + if($cookie->is_expired()) { |
|
| 148 | 148 | continue; |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | - if ($cookie->domain_matches($url->host)) { |
|
| 151 | + if($cookie->domain_matches($url->host)) { |
|
| 152 | 152 | $cookies[] = $cookie->format_for_header(); |
| 153 | 153 | } |
| 154 | 154 | } |
@@ -162,9 +162,9 @@ discard block |
||
| 162 | 162 | * |
| 163 | 163 | * @var Requests_Response $response |
| 164 | 164 | */ |
| 165 | - public function before_redirect_check(Requests_Response &$return) { |
|
| 165 | + public function before_redirect_check(Requests_Response&$return) { |
|
| 166 | 166 | $url = $return->url; |
| 167 | - if (!$url instanceof Requests_IRI) { |
|
| 167 | + if(!$url instanceof Requests_IRI) { |
|
| 168 | 168 | $url = new Requests_IRI($url); |
| 169 | 169 | } |
| 170 | 170 | |
@@ -25,7 +25,8 @@ discard block |
||
| 25 | 25 | * |
| 26 | 26 | * @param array $cookies Existing cookie values |
| 27 | 27 | */ |
| 28 | - public function __construct($cookies = array()) { |
|
| 28 | + public function __construct($cookies = array()) |
|
| 29 | + { |
|
| 29 | 30 | $this->cookies = $cookies; |
| 30 | 31 | } |
| 31 | 32 | |
@@ -35,8 +36,10 @@ discard block |
||
| 35 | 36 | * @param string|Requests_Cookie $cookie |
| 36 | 37 | * @return Requests_Cookie |
| 37 | 38 | */ |
| 38 | - public function normalize_cookie($cookie, $key = null) { |
|
| 39 | - if ($cookie instanceof Requests_Cookie) { |
|
| 39 | + public function normalize_cookie($cookie, $key = null) |
|
| 40 | + { |
|
| 41 | + if ($cookie instanceof Requests_Cookie) |
|
| 42 | + { |
|
| 40 | 43 | return $cookie; |
| 41 | 44 | } |
| 42 | 45 | |
@@ -50,7 +53,8 @@ discard block |
||
| 50 | 53 | * @deprecated Use {@see Requests_Cookie_Jar::normalize_cookie} |
| 51 | 54 | * @return Requests_Cookie |
| 52 | 55 | */ |
| 53 | - public function normalizeCookie($cookie, $key = null) { |
|
| 56 | + public function normalizeCookie($cookie, $key = null) |
|
| 57 | + { |
|
| 54 | 58 | return $this->normalize_cookie($cookie, $key); |
| 55 | 59 | } |
| 56 | 60 | |
@@ -60,7 +64,8 @@ discard block |
||
| 60 | 64 | * @param string $key Item key |
| 61 | 65 | * @return boolean Does the item exist? |
| 62 | 66 | */ |
| 63 | - public function offsetExists($key) { |
|
| 67 | + public function offsetExists($key) |
|
| 68 | + { |
|
| 64 | 69 | return isset($this->cookies[$key]); |
| 65 | 70 | } |
| 66 | 71 | |
@@ -70,8 +75,10 @@ discard block |
||
| 70 | 75 | * @param string $key Item key |
| 71 | 76 | * @return string Item value |
| 72 | 77 | */ |
| 73 | - public function offsetGet($key) { |
|
| 74 | - if (!isset($this->cookies[$key])) { |
|
| 78 | + public function offsetGet($key) |
|
| 79 | + { |
|
| 80 | + if (!isset($this->cookies[$key])) |
|
| 81 | + { |
|
| 75 | 82 | return null; |
| 76 | 83 | } |
| 77 | 84 | |
@@ -86,8 +93,10 @@ discard block |
||
| 86 | 93 | * @param string $key Item name |
| 87 | 94 | * @param string $value Item value |
| 88 | 95 | */ |
| 89 | - public function offsetSet($key, $value) { |
|
| 90 | - if ($key === null) { |
|
| 96 | + public function offsetSet($key, $value) |
|
| 97 | + { |
|
| 98 | + if ($key === null) |
|
| 99 | + { |
|
| 91 | 100 | throw new Requests_Exception('Object is a dictionary, not a list', 'invalidset'); |
| 92 | 101 | } |
| 93 | 102 | |
@@ -99,7 +108,8 @@ discard block |
||
| 99 | 108 | * |
| 100 | 109 | * @param string $key |
| 101 | 110 | */ |
| 102 | - public function offsetUnset($key) { |
|
| 111 | + public function offsetUnset($key) |
|
| 112 | + { |
|
| 103 | 113 | unset($this->cookies[$key]); |
| 104 | 114 | } |
| 105 | 115 | |
@@ -108,7 +118,8 @@ discard block |
||
| 108 | 118 | * |
| 109 | 119 | * @return ArrayIterator |
| 110 | 120 | */ |
| 111 | - public function getIterator() { |
|
| 121 | + public function getIterator() |
|
| 122 | + { |
|
| 112 | 123 | return new ArrayIterator($this->cookies); |
| 113 | 124 | } |
| 114 | 125 | |
@@ -117,7 +128,8 @@ discard block |
||
| 117 | 128 | * |
| 118 | 129 | * @param Requests_Hooker $hooks Hooking system |
| 119 | 130 | */ |
| 120 | - public function register(Requests_Hooker $hooks) { |
|
| 131 | + public function register(Requests_Hooker $hooks) |
|
| 132 | + { |
|
| 121 | 133 | $hooks->register('requests.before_request', array($this, 'before_request')); |
| 122 | 134 | $hooks->register('requests.before_redirect_check', array($this, 'before_redirect_check')); |
| 123 | 135 | } |
@@ -133,22 +145,28 @@ discard block |
||
| 133 | 145 | * @param string $type |
| 134 | 146 | * @param array $options |
| 135 | 147 | */ |
| 136 | - public function before_request($url, &$headers, &$data, &$type, &$options) { |
|
| 137 | - if (!$url instanceof Requests_IRI) { |
|
| 148 | + public function before_request($url, &$headers, &$data, &$type, &$options) |
|
| 149 | + { |
|
| 150 | + if (!$url instanceof Requests_IRI) |
|
| 151 | + { |
|
| 138 | 152 | $url = new Requests_IRI($url); |
| 139 | 153 | } |
| 140 | 154 | |
| 141 | - if (!empty($this->cookies)) { |
|
| 155 | + if (!empty($this->cookies)) |
|
| 156 | + { |
|
| 142 | 157 | $cookies = array(); |
| 143 | - foreach ($this->cookies as $key => $cookie) { |
|
| 158 | + foreach ($this->cookies as $key => $cookie) |
|
| 159 | + { |
|
| 144 | 160 | $cookie = $this->normalize_cookie($cookie, $key); |
| 145 | 161 | |
| 146 | 162 | // Skip expired cookies |
| 147 | - if ($cookie->is_expired()) { |
|
| 163 | + if ($cookie->is_expired()) |
|
| 164 | + { |
|
| 148 | 165 | continue; |
| 149 | 166 | } |
| 150 | 167 | |
| 151 | - if ($cookie->domain_matches($url->host)) { |
|
| 168 | + if ($cookie->domain_matches($url->host)) |
|
| 169 | + { |
|
| 152 | 170 | $cookies[] = $cookie->format_for_header(); |
| 153 | 171 | } |
| 154 | 172 | } |
@@ -162,9 +180,11 @@ discard block |
||
| 162 | 180 | * |
| 163 | 181 | * @var Requests_Response $response |
| 164 | 182 | */ |
| 165 | - public function before_redirect_check(Requests_Response &$return) { |
|
| 183 | + public function before_redirect_check(Requests_Response &$return) |
|
| 184 | + { |
|
| 166 | 185 | $url = $return->url; |
| 167 | - if (!$url instanceof Requests_IRI) { |
|
| 186 | + if (!$url instanceof Requests_IRI) |
|
| 187 | + { |
|
| 168 | 188 | $url = new Requests_IRI($url); |
| 169 | 189 | } |
| 170 | 190 | |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | * @param string|Requests_Cookie $cookie |
| 36 | 36 | * @return Requests_Cookie |
| 37 | 37 | */ |
| 38 | - public function normalize_cookie($cookie, $key = null) { |
|
| 38 | + public function normalize_cookie($cookie, $key = NULL) { |
|
| 39 | 39 | if ($cookie instanceof Requests_Cookie) { |
| 40 | 40 | return $cookie; |
| 41 | 41 | } |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | * @deprecated Use {@see Requests_Cookie_Jar::normalize_cookie} |
| 51 | 51 | * @return Requests_Cookie |
| 52 | 52 | */ |
| 53 | - public function normalizeCookie($cookie, $key = null) { |
|
| 53 | + public function normalizeCookie($cookie, $key = NULL) { |
|
| 54 | 54 | return $this->normalize_cookie($cookie, $key); |
| 55 | 55 | } |
| 56 | 56 | |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | */ |
| 73 | 73 | public function offsetGet($key) { |
| 74 | 74 | if (!isset($this->cookies[$key])) { |
| 75 | - return null; |
|
| 75 | + return NULL; |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | return $this->cookies[$key]; |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | * @param string $value Item value |
| 88 | 88 | */ |
| 89 | 89 | public function offsetSet($key, $value) { |
| 90 | - if ($key === null) { |
|
| 90 | + if ($key === NULL) { |
|
| 91 | 91 | throw new Requests_Exception('Object is a dictionary, not a list', 'invalidset'); |
| 92 | 92 | } |
| 93 | 93 | |
@@ -55,14 +55,14 @@ discard block |
||
| 55 | 55 | * @param array|null $args Array of user and password. Must have exactly two elements |
| 56 | 56 | */ |
| 57 | 57 | public function __construct($args = null) { |
| 58 | - if (is_string($args)) { |
|
| 58 | + if(is_string($args)) { |
|
| 59 | 59 | $this->proxy = $args; |
| 60 | 60 | } |
| 61 | - elseif (is_array($args)) { |
|
| 62 | - if (count($args) == 1) { |
|
| 61 | + elseif(is_array($args)) { |
|
| 62 | + if(count($args) == 1) { |
|
| 63 | 63 | list($this->proxy) = $args; |
| 64 | 64 | } |
| 65 | - elseif (count($args) == 3) { |
|
| 65 | + elseif(count($args) == 3) { |
|
| 66 | 66 | list($this->proxy, $this->user, $this->pass) = $args; |
| 67 | 67 | $this->use_authentication = true; |
| 68 | 68 | } |
@@ -82,12 +82,12 @@ discard block |
||
| 82 | 82 | * @see fsockopen_header |
| 83 | 83 | * @param Requests_Hooks $hooks Hook system |
| 84 | 84 | */ |
| 85 | - public function register(Requests_Hooks &$hooks) { |
|
| 85 | + public function register(Requests_Hooks&$hooks) { |
|
| 86 | 86 | $hooks->register('curl.before_send', array(&$this, 'curl_before_send')); |
| 87 | 87 | |
| 88 | 88 | $hooks->register('fsockopen.remote_socket', array(&$this, 'fsockopen_remote_socket')); |
| 89 | 89 | $hooks->register('fsockopen.remote_host_path', array(&$this, 'fsockopen_remote_host_path')); |
| 90 | - if ($this->use_authentication) { |
|
| 90 | + if($this->use_authentication) { |
|
| 91 | 91 | $hooks->register('fsockopen.after_headers', array(&$this, 'fsockopen_header')); |
| 92 | 92 | } |
| 93 | 93 | } |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | curl_setopt($handle, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); |
| 103 | 103 | curl_setopt($handle, CURLOPT_PROXY, $this->proxy); |
| 104 | 104 | |
| 105 | - if ($this->use_authentication) { |
|
| 105 | + if($this->use_authentication) { |
|
| 106 | 106 | curl_setopt($handle, CURLOPT_PROXYAUTH, CURLAUTH_ANY); |
| 107 | 107 | curl_setopt($handle, CURLOPT_PROXYUSERPWD, $this->get_auth_string()); |
| 108 | 108 | } |
@@ -16,7 +16,8 @@ discard block |
||
| 16 | 16 | * @subpackage Proxy |
| 17 | 17 | * @since 1.6 |
| 18 | 18 | */ |
| 19 | -class Requests_Proxy_HTTP implements Requests_Proxy { |
|
| 19 | +class Requests_Proxy_HTTP implements Requests_Proxy |
|
| 20 | +{ |
|
| 20 | 21 | /** |
| 21 | 22 | * Proxy host and port |
| 22 | 23 | * |
@@ -54,19 +55,25 @@ discard block |
||
| 54 | 55 | * @throws Requests_Exception On incorrect number of arguments (`authbasicbadargs`) |
| 55 | 56 | * @param array|null $args Array of user and password. Must have exactly two elements |
| 56 | 57 | */ |
| 57 | - public function __construct($args = null) { |
|
| 58 | - if (is_string($args)) { |
|
| 58 | + public function __construct($args = null) |
|
| 59 | + { |
|
| 60 | + if (is_string($args)) |
|
| 61 | + { |
|
| 59 | 62 | $this->proxy = $args; |
| 60 | 63 | } |
| 61 | - elseif (is_array($args)) { |
|
| 62 | - if (count($args) == 1) { |
|
| 64 | + elseif (is_array($args)) |
|
| 65 | + { |
|
| 66 | + if (count($args) == 1) |
|
| 67 | + { |
|
| 63 | 68 | list($this->proxy) = $args; |
| 64 | 69 | } |
| 65 | - elseif (count($args) == 3) { |
|
| 70 | + elseif (count($args) == 3) |
|
| 71 | + { |
|
| 66 | 72 | list($this->proxy, $this->user, $this->pass) = $args; |
| 67 | 73 | $this->use_authentication = true; |
| 68 | 74 | } |
| 69 | - else { |
|
| 75 | + else |
|
| 76 | + { |
|
| 70 | 77 | throw new Requests_Exception('Invalid number of arguments', 'proxyhttpbadargs'); |
| 71 | 78 | } |
| 72 | 79 | } |
@@ -82,12 +89,14 @@ discard block |
||
| 82 | 89 | * @see fsockopen_header |
| 83 | 90 | * @param Requests_Hooks $hooks Hook system |
| 84 | 91 | */ |
| 85 | - public function register(Requests_Hooks &$hooks) { |
|
| 92 | + public function register(Requests_Hooks &$hooks) |
|
| 93 | + { |
|
| 86 | 94 | $hooks->register('curl.before_send', array(&$this, 'curl_before_send')); |
| 87 | 95 | |
| 88 | 96 | $hooks->register('fsockopen.remote_socket', array(&$this, 'fsockopen_remote_socket')); |
| 89 | 97 | $hooks->register('fsockopen.remote_host_path', array(&$this, 'fsockopen_remote_host_path')); |
| 90 | - if ($this->use_authentication) { |
|
| 98 | + if ($this->use_authentication) |
|
| 99 | + { |
|
| 91 | 100 | $hooks->register('fsockopen.after_headers', array(&$this, 'fsockopen_header')); |
| 92 | 101 | } |
| 93 | 102 | } |
@@ -98,11 +107,13 @@ discard block |
||
| 98 | 107 | * @since 1.6 |
| 99 | 108 | * @param resource $handle cURL resource |
| 100 | 109 | */ |
| 101 | - public function curl_before_send(&$handle) { |
|
| 110 | + public function curl_before_send(&$handle) |
|
| 111 | + { |
|
| 102 | 112 | curl_setopt($handle, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); |
| 103 | 113 | curl_setopt($handle, CURLOPT_PROXY, $this->proxy); |
| 104 | 114 | |
| 105 | - if ($this->use_authentication) { |
|
| 115 | + if ($this->use_authentication) |
|
| 116 | + { |
|
| 106 | 117 | curl_setopt($handle, CURLOPT_PROXYAUTH, CURLAUTH_ANY); |
| 107 | 118 | curl_setopt($handle, CURLOPT_PROXYUSERPWD, $this->get_auth_string()); |
| 108 | 119 | } |
@@ -114,7 +125,8 @@ discard block |
||
| 114 | 125 | * @since 1.6 |
| 115 | 126 | * @param string $remote_socket Socket connection string |
| 116 | 127 | */ |
| 117 | - public function fsockopen_remote_socket(&$remote_socket) { |
|
| 128 | + public function fsockopen_remote_socket(&$remote_socket) |
|
| 129 | + { |
|
| 118 | 130 | $remote_socket = $this->proxy; |
| 119 | 131 | } |
| 120 | 132 | |
@@ -125,7 +137,8 @@ discard block |
||
| 125 | 137 | * @param string $path Path to send in HTTP request string ("GET ...") |
| 126 | 138 | * @param string $url Full URL we're requesting |
| 127 | 139 | */ |
| 128 | - public function fsockopen_remote_host_path(&$path, $url) { |
|
| 140 | + public function fsockopen_remote_host_path(&$path, $url) |
|
| 141 | + { |
|
| 129 | 142 | $path = $url; |
| 130 | 143 | } |
| 131 | 144 | |
@@ -135,7 +148,8 @@ discard block |
||
| 135 | 148 | * @since 1.6 |
| 136 | 149 | * @param string $out HTTP header string |
| 137 | 150 | */ |
| 138 | - public function fsockopen_header(&$out) { |
|
| 151 | + public function fsockopen_header(&$out) |
|
| 152 | + { |
|
| 139 | 153 | $out .= sprintf("Proxy-Authorization: Basic %s\r\n", base64_encode($this->get_auth_string())); |
| 140 | 154 | } |
| 141 | 155 | |
@@ -145,7 +159,8 @@ discard block |
||
| 145 | 159 | * @since 1.6 |
| 146 | 160 | * @return string |
| 147 | 161 | */ |
| 148 | - public function get_auth_string() { |
|
| 162 | + public function get_auth_string() |
|
| 163 | + { |
|
| 149 | 164 | return $this->user . ':' . $this->pass; |
| 150 | 165 | } |
| 151 | 166 | } |
| 152 | 167 | \ No newline at end of file |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | * @throws Requests_Exception On incorrect number of arguments (`authbasicbadargs`) |
| 55 | 55 | * @param array|null $args Array of user and password. Must have exactly two elements |
| 56 | 56 | */ |
| 57 | - public function __construct($args = null) { |
|
| 57 | + public function __construct($args = NULL) { |
|
| 58 | 58 | if (is_string($args)) { |
| 59 | 59 | $this->proxy = $args; |
| 60 | 60 | } |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | } |
| 65 | 65 | elseif (count($args) == 3) { |
| 66 | 66 | list($this->proxy, $this->user, $this->pass) = $args; |
| 67 | - $this->use_authentication = true; |
|
| 67 | + $this->use_authentication = TRUE; |
|
| 68 | 68 | } |
| 69 | 69 | else { |
| 70 | 70 | throw new Requests_Exception('Invalid number of arguments', 'proxyhttpbadargs'); |
@@ -96,14 +96,14 @@ discard block |
||
| 96 | 96 | |
| 97 | 97 | curl_setopt($this->handle, CURLOPT_HEADER, false); |
| 98 | 98 | curl_setopt($this->handle, CURLOPT_RETURNTRANSFER, 1); |
| 99 | - if ($this->version >= self::CURL_7_10_5) { |
|
| 99 | + if($this->version >= self::CURL_7_10_5) { |
|
| 100 | 100 | curl_setopt($this->handle, CURLOPT_ENCODING, ''); |
| 101 | 101 | } |
| 102 | - if (defined('CURLOPT_PROTOCOLS')) { |
|
| 103 | - curl_setopt($this->handle, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS); |
|
| 102 | + if(defined('CURLOPT_PROTOCOLS')) { |
|
| 103 | + curl_setopt($this->handle, CURLOPT_PROTOCOLS, CURLPROTO_HTTP|CURLPROTO_HTTPS); |
|
| 104 | 104 | } |
| 105 | - if (defined('CURLOPT_REDIR_PROTOCOLS')) { |
|
| 106 | - curl_setopt($this->handle, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS); |
|
| 105 | + if(defined('CURLOPT_REDIR_PROTOCOLS')) { |
|
| 106 | + curl_setopt($this->handle, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP|CURLPROTO_HTTPS); |
|
| 107 | 107 | } |
| 108 | 108 | } |
| 109 | 109 | |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | * Destructor |
| 112 | 112 | */ |
| 113 | 113 | public function __destruct() { |
| 114 | - if (is_resource($this->handle)) { |
|
| 114 | + if(is_resource($this->handle)) { |
|
| 115 | 115 | curl_close($this->handle); |
| 116 | 116 | } |
| 117 | 117 | } |
@@ -134,28 +134,28 @@ discard block |
||
| 134 | 134 | |
| 135 | 135 | $options['hooks']->dispatch('curl.before_send', array(&$this->handle)); |
| 136 | 136 | |
| 137 | - if ($options['filename'] !== false) { |
|
| 137 | + if($options['filename'] !== false) { |
|
| 138 | 138 | $this->stream_handle = fopen($options['filename'], 'wb'); |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | $this->response_data = ''; |
| 142 | 142 | $this->response_bytes = 0; |
| 143 | 143 | $this->response_byte_limit = false; |
| 144 | - if ($options['max_bytes'] !== false) { |
|
| 144 | + if($options['max_bytes'] !== false) { |
|
| 145 | 145 | $this->response_byte_limit = $options['max_bytes']; |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | - if (isset($options['verify'])) { |
|
| 149 | - if ($options['verify'] === false) { |
|
| 148 | + if(isset($options['verify'])) { |
|
| 149 | + if($options['verify'] === false) { |
|
| 150 | 150 | curl_setopt($this->handle, CURLOPT_SSL_VERIFYHOST, 0); |
| 151 | 151 | curl_setopt($this->handle, CURLOPT_SSL_VERIFYPEER, 0); |
| 152 | 152 | } |
| 153 | - elseif (is_string($options['verify'])) { |
|
| 153 | + elseif(is_string($options['verify'])) { |
|
| 154 | 154 | curl_setopt($this->handle, CURLOPT_CAINFO, $options['verify']); |
| 155 | 155 | } |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | - if (isset($options['verifyname']) && $options['verifyname'] === false) { |
|
| 158 | + if(isset($options['verifyname']) && $options['verifyname'] === false) { |
|
| 159 | 159 | curl_setopt($this->handle, CURLOPT_SSL_VERIFYHOST, 0); |
| 160 | 160 | } |
| 161 | 161 | |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | |
| 165 | 165 | $options['hooks']->dispatch('curl.after_send', array()); |
| 166 | 166 | |
| 167 | - if (curl_errno($this->handle) === 23 || curl_errno($this->handle) === 61) { |
|
| 167 | + if(curl_errno($this->handle) === 23 || curl_errno($this->handle) === 61) { |
|
| 168 | 168 | // Reset encoding and try again |
| 169 | 169 | curl_setopt($this->handle, CURLOPT_ENCODING, 'none'); |
| 170 | 170 | |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | */ |
| 194 | 194 | public function request_multiple($requests, $options) { |
| 195 | 195 | // If you're not requesting, we can't get any responses ¯\_(ツ)_/¯ |
| 196 | - if (empty($requests)) { |
|
| 196 | + if(empty($requests)) { |
|
| 197 | 197 | return array(); |
| 198 | 198 | } |
| 199 | 199 | |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | $subhandles = array(); |
| 203 | 203 | |
| 204 | 204 | $class = get_class($this); |
| 205 | - foreach ($requests as $id => $request) { |
|
| 205 | + foreach($requests as $id => $request) { |
|
| 206 | 206 | $subrequests[$id] = new $class(); |
| 207 | 207 | $subhandles[$id] = $subrequests[$id]->get_subrequest_handle($request['url'], $request['headers'], $request['data'], $request['options']); |
| 208 | 208 | $request['options']['hooks']->dispatch('curl.before_multi_add', array(&$subhandles[$id])); |
@@ -220,22 +220,22 @@ discard block |
||
| 220 | 220 | do { |
| 221 | 221 | $status = curl_multi_exec($multihandle, $active); |
| 222 | 222 | } |
| 223 | - while ($status === CURLM_CALL_MULTI_PERFORM); |
|
| 223 | + while($status === CURLM_CALL_MULTI_PERFORM); |
|
| 224 | 224 | |
| 225 | 225 | $to_process = array(); |
| 226 | 226 | |
| 227 | 227 | // Read the information as needed |
| 228 | - while ($done = curl_multi_info_read($multihandle)) { |
|
| 228 | + while($done = curl_multi_info_read($multihandle)) { |
|
| 229 | 229 | $key = array_search($done['handle'], $subhandles, true); |
| 230 | - if (!isset($to_process[$key])) { |
|
| 230 | + if(!isset($to_process[$key])) { |
|
| 231 | 231 | $to_process[$key] = $done; |
| 232 | 232 | } |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | // Parse the finished requests before we start getting the new ones |
| 236 | - foreach ($to_process as $key => $done) { |
|
| 236 | + foreach($to_process as $key => $done) { |
|
| 237 | 237 | $options = $requests[$key]['options']; |
| 238 | - if (CURLE_OK !== $done['result']) { |
|
| 238 | + if(CURLE_OK !== $done['result']) { |
|
| 239 | 239 | //get error string for handle. |
| 240 | 240 | $reason = curl_error($done['handle']); |
| 241 | 241 | $exception = new Requests_Exception_Transport_cURL( |
@@ -256,13 +256,13 @@ discard block |
||
| 256 | 256 | curl_multi_remove_handle($multihandle, $done['handle']); |
| 257 | 257 | curl_close($done['handle']); |
| 258 | 258 | |
| 259 | - if (!is_string($responses[$key])) { |
|
| 259 | + if(!is_string($responses[$key])) { |
|
| 260 | 260 | $options['hooks']->dispatch('multiple.request.complete', array(&$responses[$key], $key)); |
| 261 | 261 | } |
| 262 | 262 | $completed++; |
| 263 | 263 | } |
| 264 | 264 | } |
| 265 | - while ($active || $completed < count($subrequests)); |
|
| 265 | + while($active || $completed < count($subrequests)); |
|
| 266 | 266 | |
| 267 | 267 | $request['options']['hooks']->dispatch('curl.after_multi_exec', array(&$multihandle)); |
| 268 | 268 | |
@@ -283,14 +283,14 @@ discard block |
||
| 283 | 283 | public function &get_subrequest_handle($url, $headers, $data, $options) { |
| 284 | 284 | $this->setup_handle($url, $headers, $data, $options); |
| 285 | 285 | |
| 286 | - if ($options['filename'] !== false) { |
|
| 286 | + if($options['filename'] !== false) { |
|
| 287 | 287 | $this->stream_handle = fopen($options['filename'], 'wb'); |
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | $this->response_data = ''; |
| 291 | 291 | $this->response_bytes = 0; |
| 292 | 292 | $this->response_byte_limit = false; |
| 293 | - if ($options['max_bytes'] !== false) { |
|
| 293 | + if($options['max_bytes'] !== false) { |
|
| 294 | 294 | $this->response_byte_limit = $options['max_bytes']; |
| 295 | 295 | } |
| 296 | 296 | $this->hooks = $options['hooks']; |
@@ -310,25 +310,25 @@ discard block |
||
| 310 | 310 | $options['hooks']->dispatch('curl.before_request', array(&$this->handle)); |
| 311 | 311 | |
| 312 | 312 | // Force closing the connection for old versions of cURL (<7.22). |
| 313 | - if ( ! isset( $headers['Connection'] ) ) { |
|
| 313 | + if(!isset($headers['Connection'])) { |
|
| 314 | 314 | $headers['Connection'] = 'close'; |
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | $headers = Requests::flatten($headers); |
| 318 | 318 | |
| 319 | - if (!empty($data)) { |
|
| 319 | + if(!empty($data)) { |
|
| 320 | 320 | $data_format = $options['data_format']; |
| 321 | 321 | |
| 322 | - if ($data_format === 'query') { |
|
| 322 | + if($data_format === 'query') { |
|
| 323 | 323 | $url = self::format_get($url, $data); |
| 324 | 324 | $data = ''; |
| 325 | 325 | } |
| 326 | - elseif (!is_string($data)) { |
|
| 326 | + elseif(!is_string($data)) { |
|
| 327 | 327 | $data = http_build_query($data, null, '&'); |
| 328 | 328 | } |
| 329 | 329 | } |
| 330 | 330 | |
| 331 | - switch ($options['type']) { |
|
| 331 | + switch($options['type']) { |
|
| 332 | 332 | case Requests::POST: |
| 333 | 333 | curl_setopt($this->handle, CURLOPT_POST, true); |
| 334 | 334 | curl_setopt($this->handle, CURLOPT_POSTFIELDS, $data); |
@@ -346,7 +346,7 @@ discard block |
||
| 346 | 346 | case Requests::OPTIONS: |
| 347 | 347 | default: |
| 348 | 348 | curl_setopt($this->handle, CURLOPT_CUSTOMREQUEST, $options['type']); |
| 349 | - if (!empty($data)) { |
|
| 349 | + if(!empty($data)) { |
|
| 350 | 350 | curl_setopt($this->handle, CURLOPT_POSTFIELDS, $data); |
| 351 | 351 | } |
| 352 | 352 | } |
@@ -359,14 +359,14 @@ discard block |
||
| 359 | 359 | // https://github.com/curl/curl/blob/4f45240bc84a9aa648c8f7243be7b79e9f9323a5/lib/hostip.c#L606-L609 |
| 360 | 360 | $timeout = max($options['timeout'], 1); |
| 361 | 361 | |
| 362 | - if (is_int($timeout) || $this->version < self::CURL_7_16_2) { |
|
| 362 | + if(is_int($timeout) || $this->version < self::CURL_7_16_2) { |
|
| 363 | 363 | curl_setopt($this->handle, CURLOPT_TIMEOUT, ceil($timeout)); |
| 364 | 364 | } |
| 365 | 365 | else { |
| 366 | 366 | curl_setopt($this->handle, CURLOPT_TIMEOUT_MS, round($timeout * 1000)); |
| 367 | 367 | } |
| 368 | 368 | |
| 369 | - if (is_int($options['connect_timeout']) || $this->version < self::CURL_7_16_2) { |
|
| 369 | + if(is_int($options['connect_timeout']) || $this->version < self::CURL_7_16_2) { |
|
| 370 | 370 | curl_setopt($this->handle, CURLOPT_CONNECTTIMEOUT, ceil($options['connect_timeout'])); |
| 371 | 371 | } |
| 372 | 372 | else { |
@@ -375,17 +375,17 @@ discard block |
||
| 375 | 375 | curl_setopt($this->handle, CURLOPT_URL, $url); |
| 376 | 376 | curl_setopt($this->handle, CURLOPT_REFERER, $url); |
| 377 | 377 | curl_setopt($this->handle, CURLOPT_USERAGENT, $options['useragent']); |
| 378 | - if (!empty($headers)) { |
|
| 378 | + if(!empty($headers)) { |
|
| 379 | 379 | curl_setopt($this->handle, CURLOPT_HTTPHEADER, $headers); |
| 380 | 380 | } |
| 381 | - if ($options['protocol_version'] === 1.1) { |
|
| 381 | + if($options['protocol_version'] === 1.1) { |
|
| 382 | 382 | curl_setopt($this->handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
| 383 | 383 | } |
| 384 | 384 | else { |
| 385 | 385 | curl_setopt($this->handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); |
| 386 | 386 | } |
| 387 | 387 | |
| 388 | - if (true === $options['blocking']) { |
|
| 388 | + if(true === $options['blocking']) { |
|
| 389 | 389 | curl_setopt($this->handle, CURLOPT_HEADERFUNCTION, array(&$this, 'stream_headers')); |
| 390 | 390 | curl_setopt($this->handle, CURLOPT_WRITEFUNCTION, array(&$this, 'stream_body')); |
| 391 | 391 | curl_setopt($this->handle, CURLOPT_BUFFERSIZE, Requests::BUFFER_SIZE); |
@@ -400,12 +400,12 @@ discard block |
||
| 400 | 400 | * @return string HTTP response data including headers |
| 401 | 401 | */ |
| 402 | 402 | public function process_response($response, $options) { |
| 403 | - if ($options['blocking'] === false) { |
|
| 403 | + if($options['blocking'] === false) { |
|
| 404 | 404 | $fake_headers = ''; |
| 405 | 405 | $options['hooks']->dispatch('curl.after_request', array(&$fake_headers)); |
| 406 | 406 | return false; |
| 407 | 407 | } |
| 408 | - if ($options['filename'] !== false) { |
|
| 408 | + if($options['filename'] !== false) { |
|
| 409 | 409 | fclose($this->stream_handle); |
| 410 | 410 | $this->headers = trim($this->headers); |
| 411 | 411 | } |
@@ -413,7 +413,7 @@ discard block |
||
| 413 | 413 | $this->headers .= $response; |
| 414 | 414 | } |
| 415 | 415 | |
| 416 | - if (curl_errno($this->handle)) { |
|
| 416 | + if(curl_errno($this->handle)) { |
|
| 417 | 417 | $error = sprintf( |
| 418 | 418 | 'cURL error %s: %s', |
| 419 | 419 | curl_errno($this->handle), |
@@ -438,13 +438,13 @@ discard block |
||
| 438 | 438 | // Why do we do this? cURL will send both the final response and any |
| 439 | 439 | // interim responses, such as a 100 Continue. We don't need that. |
| 440 | 440 | // (We may want to keep this somewhere just in case) |
| 441 | - if ($this->done_headers) { |
|
| 441 | + if($this->done_headers) { |
|
| 442 | 442 | $this->headers = ''; |
| 443 | 443 | $this->done_headers = false; |
| 444 | 444 | } |
| 445 | 445 | $this->headers .= $headers; |
| 446 | 446 | |
| 447 | - if ($headers === "\r\n") { |
|
| 447 | + if($headers === "\r\n") { |
|
| 448 | 448 | $this->done_headers = true; |
| 449 | 449 | } |
| 450 | 450 | return strlen($headers); |
@@ -464,20 +464,20 @@ discard block |
||
| 464 | 464 | $data_length = strlen($data); |
| 465 | 465 | |
| 466 | 466 | // Are we limiting the response size? |
| 467 | - if ($this->response_byte_limit) { |
|
| 468 | - if ($this->response_bytes === $this->response_byte_limit) { |
|
| 467 | + if($this->response_byte_limit) { |
|
| 468 | + if($this->response_bytes === $this->response_byte_limit) { |
|
| 469 | 469 | // Already at maximum, move on |
| 470 | 470 | return $data_length; |
| 471 | 471 | } |
| 472 | 472 | |
| 473 | - if (($this->response_bytes + $data_length) > $this->response_byte_limit) { |
|
| 473 | + if(($this->response_bytes + $data_length) > $this->response_byte_limit) { |
|
| 474 | 474 | // Limit the length |
| 475 | 475 | $limited_length = ($this->response_byte_limit - $this->response_bytes); |
| 476 | 476 | $data = substr($data, 0, $limited_length); |
| 477 | 477 | } |
| 478 | 478 | } |
| 479 | 479 | |
| 480 | - if ($this->stream_handle) { |
|
| 480 | + if($this->stream_handle) { |
|
| 481 | 481 | fwrite($this->stream_handle, $data); |
| 482 | 482 | } |
| 483 | 483 | else { |
@@ -496,9 +496,9 @@ discard block |
||
| 496 | 496 | * @return string URL with data |
| 497 | 497 | */ |
| 498 | 498 | protected static function format_get($url, $data) { |
| 499 | - if (!empty($data)) { |
|
| 499 | + if(!empty($data)) { |
|
| 500 | 500 | $url_parts = parse_url($url); |
| 501 | - if (empty($url_parts['query'])) { |
|
| 501 | + if(empty($url_parts['query'])) { |
|
| 502 | 502 | $query = $url_parts['query'] = ''; |
| 503 | 503 | } |
| 504 | 504 | else { |
@@ -508,7 +508,7 @@ discard block |
||
| 508 | 508 | $query .= '&' . http_build_query($data, null, '&'); |
| 509 | 509 | $query = trim($query, '&'); |
| 510 | 510 | |
| 511 | - if (empty($url_parts['query'])) { |
|
| 511 | + if(empty($url_parts['query'])) { |
|
| 512 | 512 | $url .= '?' . $query; |
| 513 | 513 | } |
| 514 | 514 | else { |
@@ -525,14 +525,14 @@ discard block |
||
| 525 | 525 | * @return boolean True if the transport is valid, false otherwise. |
| 526 | 526 | */ |
| 527 | 527 | public static function test($capabilities = array()) { |
| 528 | - if (!function_exists('curl_init') || !function_exists('curl_exec')) { |
|
| 528 | + if(!function_exists('curl_init') || !function_exists('curl_exec')) { |
|
| 529 | 529 | return false; |
| 530 | 530 | } |
| 531 | 531 | |
| 532 | 532 | // If needed, check that our installed curl version supports SSL |
| 533 | - if (isset($capabilities['ssl']) && $capabilities['ssl']) { |
|
| 533 | + if(isset($capabilities['ssl']) && $capabilities['ssl']) { |
|
| 534 | 534 | $curl_version = curl_version(); |
| 535 | - if (!(CURL_VERSION_SSL & $curl_version['features'])) { |
|
| 535 | + if(!(CURL_VERSION_SSL&$curl_version['features'])) { |
|
| 536 | 536 | return false; |
| 537 | 537 | } |
| 538 | 538 | } |
@@ -12,7 +12,8 @@ discard block |
||
| 12 | 12 | * @package Requests |
| 13 | 13 | * @subpackage Transport |
| 14 | 14 | */ |
| 15 | -class Requests_Transport_cURL implements Requests_Transport { |
|
| 15 | +class Requests_Transport_cURL implements Requests_Transport |
|
| 16 | +{ |
|
| 16 | 17 | const CURL_7_10_5 = 0x070A05; |
| 17 | 18 | const CURL_7_16_2 = 0x071002; |
| 18 | 19 | |
@@ -89,20 +90,24 @@ discard block |
||
| 89 | 90 | /** |
| 90 | 91 | * Constructor |
| 91 | 92 | */ |
| 92 | - public function __construct() { |
|
| 93 | + public function __construct() |
|
| 94 | + { |
|
| 93 | 95 | $curl = curl_version(); |
| 94 | 96 | $this->version = $curl['version_number']; |
| 95 | 97 | $this->handle = curl_init(); |
| 96 | 98 | |
| 97 | 99 | curl_setopt($this->handle, CURLOPT_HEADER, false); |
| 98 | 100 | curl_setopt($this->handle, CURLOPT_RETURNTRANSFER, 1); |
| 99 | - if ($this->version >= self::CURL_7_10_5) { |
|
| 101 | + if ($this->version >= self::CURL_7_10_5) |
|
| 102 | + { |
|
| 100 | 103 | curl_setopt($this->handle, CURLOPT_ENCODING, ''); |
| 101 | 104 | } |
| 102 | - if (defined('CURLOPT_PROTOCOLS')) { |
|
| 105 | + if (defined('CURLOPT_PROTOCOLS')) |
|
| 106 | + { |
|
| 103 | 107 | curl_setopt($this->handle, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS); |
| 104 | 108 | } |
| 105 | - if (defined('CURLOPT_REDIR_PROTOCOLS')) { |
|
| 109 | + if (defined('CURLOPT_REDIR_PROTOCOLS')) |
|
| 110 | + { |
|
| 106 | 111 | curl_setopt($this->handle, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS); |
| 107 | 112 | } |
| 108 | 113 | } |
@@ -110,8 +115,10 @@ discard block |
||
| 110 | 115 | /** |
| 111 | 116 | * Destructor |
| 112 | 117 | */ |
| 113 | - public function __destruct() { |
|
| 114 | - if (is_resource($this->handle)) { |
|
| 118 | + public function __destruct() |
|
| 119 | + { |
|
| 120 | + if (is_resource($this->handle)) |
|
| 121 | + { |
|
| 115 | 122 | curl_close($this->handle); |
| 116 | 123 | } |
| 117 | 124 | } |
@@ -127,35 +134,42 @@ discard block |
||
| 127 | 134 | * @param array $options Request options, see {@see Requests::response()} for documentation |
| 128 | 135 | * @return string Raw HTTP result |
| 129 | 136 | */ |
| 130 | - public function request($url, $headers = array(), $data = array(), $options = array()) { |
|
| 137 | + public function request($url, $headers = array(), $data = array(), $options = array()) |
|
| 138 | + { |
|
| 131 | 139 | $this->hooks = $options['hooks']; |
| 132 | 140 | |
| 133 | 141 | $this->setup_handle($url, $headers, $data, $options); |
| 134 | 142 | |
| 135 | 143 | $options['hooks']->dispatch('curl.before_send', array(&$this->handle)); |
| 136 | 144 | |
| 137 | - if ($options['filename'] !== false) { |
|
| 145 | + if ($options['filename'] !== false) |
|
| 146 | + { |
|
| 138 | 147 | $this->stream_handle = fopen($options['filename'], 'wb'); |
| 139 | 148 | } |
| 140 | 149 | |
| 141 | 150 | $this->response_data = ''; |
| 142 | 151 | $this->response_bytes = 0; |
| 143 | 152 | $this->response_byte_limit = false; |
| 144 | - if ($options['max_bytes'] !== false) { |
|
| 153 | + if ($options['max_bytes'] !== false) |
|
| 154 | + { |
|
| 145 | 155 | $this->response_byte_limit = $options['max_bytes']; |
| 146 | 156 | } |
| 147 | 157 | |
| 148 | - if (isset($options['verify'])) { |
|
| 149 | - if ($options['verify'] === false) { |
|
| 158 | + if (isset($options['verify'])) |
|
| 159 | + { |
|
| 160 | + if ($options['verify'] === false) |
|
| 161 | + { |
|
| 150 | 162 | curl_setopt($this->handle, CURLOPT_SSL_VERIFYHOST, 0); |
| 151 | 163 | curl_setopt($this->handle, CURLOPT_SSL_VERIFYPEER, 0); |
| 152 | 164 | } |
| 153 | - elseif (is_string($options['verify'])) { |
|
| 165 | + elseif (is_string($options['verify'])) |
|
| 166 | + { |
|
| 154 | 167 | curl_setopt($this->handle, CURLOPT_CAINFO, $options['verify']); |
| 155 | 168 | } |
| 156 | 169 | } |
| 157 | 170 | |
| 158 | - if (isset($options['verifyname']) && $options['verifyname'] === false) { |
|
| 171 | + if (isset($options['verifyname']) && $options['verifyname'] === false) |
|
| 172 | + { |
|
| 159 | 173 | curl_setopt($this->handle, CURLOPT_SSL_VERIFYHOST, 0); |
| 160 | 174 | } |
| 161 | 175 | |
@@ -164,7 +178,8 @@ discard block |
||
| 164 | 178 | |
| 165 | 179 | $options['hooks']->dispatch('curl.after_send', array()); |
| 166 | 180 | |
| 167 | - if (curl_errno($this->handle) === 23 || curl_errno($this->handle) === 61) { |
|
| 181 | + if (curl_errno($this->handle) === 23 || curl_errno($this->handle) === 61) |
|
| 182 | + { |
|
| 168 | 183 | // Reset encoding and try again |
| 169 | 184 | curl_setopt($this->handle, CURLOPT_ENCODING, 'none'); |
| 170 | 185 | |
@@ -191,9 +206,11 @@ discard block |
||
| 191 | 206 | * @param array $options Global options |
| 192 | 207 | * @return array Array of Requests_Response objects (may contain Requests_Exception or string responses as well) |
| 193 | 208 | */ |
| 194 | - public function request_multiple($requests, $options) { |
|
| 209 | + public function request_multiple($requests, $options) |
|
| 210 | + { |
|
| 195 | 211 | // If you're not requesting, we can't get any responses ¯\_(ツ)_/¯ |
| 196 | - if (empty($requests)) { |
|
| 212 | + if (empty($requests)) |
|
| 213 | + { |
|
| 197 | 214 | return array(); |
| 198 | 215 | } |
| 199 | 216 | |
@@ -202,7 +219,8 @@ discard block |
||
| 202 | 219 | $subhandles = array(); |
| 203 | 220 | |
| 204 | 221 | $class = get_class($this); |
| 205 | - foreach ($requests as $id => $request) { |
|
| 222 | + foreach ($requests as $id => $request) |
|
| 223 | + { |
|
| 206 | 224 | $subrequests[$id] = new $class(); |
| 207 | 225 | $subhandles[$id] = $subrequests[$id]->get_subrequest_handle($request['url'], $request['headers'], $request['data'], $request['options']); |
| 208 | 226 | $request['options']['hooks']->dispatch('curl.before_multi_add', array(&$subhandles[$id])); |
@@ -214,10 +232,12 @@ discard block |
||
| 214 | 232 | |
| 215 | 233 | $request['options']['hooks']->dispatch('curl.before_multi_exec', array(&$multihandle)); |
| 216 | 234 | |
| 217 | - do { |
|
| 235 | + do |
|
| 236 | + { |
|
| 218 | 237 | $active = false; |
| 219 | 238 | |
| 220 | - do { |
|
| 239 | + do |
|
| 240 | + { |
|
| 221 | 241 | $status = curl_multi_exec($multihandle, $active); |
| 222 | 242 | } |
| 223 | 243 | while ($status === CURLM_CALL_MULTI_PERFORM); |
@@ -225,17 +245,21 @@ discard block |
||
| 225 | 245 | $to_process = array(); |
| 226 | 246 | |
| 227 | 247 | // Read the information as needed |
| 228 | - while ($done = curl_multi_info_read($multihandle)) { |
|
| 248 | + while ($done = curl_multi_info_read($multihandle)) |
|
| 249 | + { |
|
| 229 | 250 | $key = array_search($done['handle'], $subhandles, true); |
| 230 | - if (!isset($to_process[$key])) { |
|
| 251 | + if (!isset($to_process[$key])) |
|
| 252 | + { |
|
| 231 | 253 | $to_process[$key] = $done; |
| 232 | 254 | } |
| 233 | 255 | } |
| 234 | 256 | |
| 235 | 257 | // Parse the finished requests before we start getting the new ones |
| 236 | - foreach ($to_process as $key => $done) { |
|
| 258 | + foreach ($to_process as $key => $done) |
|
| 259 | + { |
|
| 237 | 260 | $options = $requests[$key]['options']; |
| 238 | - if (CURLE_OK !== $done['result']) { |
|
| 261 | + if (CURLE_OK !== $done['result']) |
|
| 262 | + { |
|
| 239 | 263 | //get error string for handle. |
| 240 | 264 | $reason = curl_error($done['handle']); |
| 241 | 265 | $exception = new Requests_Exception_Transport_cURL( |
@@ -247,7 +271,8 @@ discard block |
||
| 247 | 271 | $responses[$key] = $exception; |
| 248 | 272 | $options['hooks']->dispatch('transport.internal.parse_error', array(&$responses[$key], $requests[$key])); |
| 249 | 273 | } |
| 250 | - else { |
|
| 274 | + else |
|
| 275 | + { |
|
| 251 | 276 | $responses[$key] = $subrequests[$key]->process_response($subrequests[$key]->response_data, $options); |
| 252 | 277 | |
| 253 | 278 | $options['hooks']->dispatch('transport.internal.parse_response', array(&$responses[$key], $requests[$key])); |
@@ -256,7 +281,8 @@ discard block |
||
| 256 | 281 | curl_multi_remove_handle($multihandle, $done['handle']); |
| 257 | 282 | curl_close($done['handle']); |
| 258 | 283 | |
| 259 | - if (!is_string($responses[$key])) { |
|
| 284 | + if (!is_string($responses[$key])) |
|
| 285 | + { |
|
| 260 | 286 | $options['hooks']->dispatch('multiple.request.complete', array(&$responses[$key], $key)); |
| 261 | 287 | } |
| 262 | 288 | $completed++; |
@@ -283,14 +309,16 @@ discard block |
||
| 283 | 309 | public function &get_subrequest_handle($url, $headers, $data, $options) { |
| 284 | 310 | $this->setup_handle($url, $headers, $data, $options); |
| 285 | 311 | |
| 286 | - if ($options['filename'] !== false) { |
|
| 312 | + if ($options['filename'] !== false) |
|
| 313 | + { |
|
| 287 | 314 | $this->stream_handle = fopen($options['filename'], 'wb'); |
| 288 | 315 | } |
| 289 | 316 | |
| 290 | 317 | $this->response_data = ''; |
| 291 | 318 | $this->response_bytes = 0; |
| 292 | 319 | $this->response_byte_limit = false; |
| 293 | - if ($options['max_bytes'] !== false) { |
|
| 320 | + if ($options['max_bytes'] !== false) |
|
| 321 | + { |
|
| 294 | 322 | $this->response_byte_limit = $options['max_bytes']; |
| 295 | 323 | } |
| 296 | 324 | $this->hooks = $options['hooks']; |
@@ -306,29 +334,35 @@ discard block |
||
| 306 | 334 | * @param string|array $data Data to send either as the POST body, or as parameters in the URL for a GET/HEAD |
| 307 | 335 | * @param array $options Request options, see {@see Requests::response()} for documentation |
| 308 | 336 | */ |
| 309 | - protected function setup_handle($url, $headers, $data, $options) { |
|
| 337 | + protected function setup_handle($url, $headers, $data, $options) |
|
| 338 | + { |
|
| 310 | 339 | $options['hooks']->dispatch('curl.before_request', array(&$this->handle)); |
| 311 | 340 | |
| 312 | 341 | // Force closing the connection for old versions of cURL (<7.22). |
| 313 | - if ( ! isset( $headers['Connection'] ) ) { |
|
| 342 | + if ( ! isset( $headers['Connection'] ) ) |
|
| 343 | + { |
|
| 314 | 344 | $headers['Connection'] = 'close'; |
| 315 | 345 | } |
| 316 | 346 | |
| 317 | 347 | $headers = Requests::flatten($headers); |
| 318 | 348 | |
| 319 | - if (!empty($data)) { |
|
| 349 | + if (!empty($data)) |
|
| 350 | + { |
|
| 320 | 351 | $data_format = $options['data_format']; |
| 321 | 352 | |
| 322 | - if ($data_format === 'query') { |
|
| 353 | + if ($data_format === 'query') |
|
| 354 | + { |
|
| 323 | 355 | $url = self::format_get($url, $data); |
| 324 | 356 | $data = ''; |
| 325 | 357 | } |
| 326 | - elseif (!is_string($data)) { |
|
| 358 | + elseif (!is_string($data)) |
|
| 359 | + { |
|
| 327 | 360 | $data = http_build_query($data, null, '&'); |
| 328 | 361 | } |
| 329 | 362 | } |
| 330 | 363 | |
| 331 | - switch ($options['type']) { |
|
| 364 | + switch ($options['type']) |
|
| 365 | + { |
|
| 332 | 366 | case Requests::POST: |
| 333 | 367 | curl_setopt($this->handle, CURLOPT_POST, true); |
| 334 | 368 | curl_setopt($this->handle, CURLOPT_POSTFIELDS, $data); |
@@ -346,7 +380,8 @@ discard block |
||
| 346 | 380 | case Requests::OPTIONS: |
| 347 | 381 | default: |
| 348 | 382 | curl_setopt($this->handle, CURLOPT_CUSTOMREQUEST, $options['type']); |
| 349 | - if (!empty($data)) { |
|
| 383 | + if (!empty($data)) |
|
| 384 | + { |
|
| 350 | 385 | curl_setopt($this->handle, CURLOPT_POSTFIELDS, $data); |
| 351 | 386 | } |
| 352 | 387 | } |
@@ -359,33 +394,41 @@ discard block |
||
| 359 | 394 | // https://github.com/curl/curl/blob/4f45240bc84a9aa648c8f7243be7b79e9f9323a5/lib/hostip.c#L606-L609 |
| 360 | 395 | $timeout = max($options['timeout'], 1); |
| 361 | 396 | |
| 362 | - if (is_int($timeout) || $this->version < self::CURL_7_16_2) { |
|
| 397 | + if (is_int($timeout) || $this->version < self::CURL_7_16_2) |
|
| 398 | + { |
|
| 363 | 399 | curl_setopt($this->handle, CURLOPT_TIMEOUT, ceil($timeout)); |
| 364 | 400 | } |
| 365 | - else { |
|
| 401 | + else |
|
| 402 | + { |
|
| 366 | 403 | curl_setopt($this->handle, CURLOPT_TIMEOUT_MS, round($timeout * 1000)); |
| 367 | 404 | } |
| 368 | 405 | |
| 369 | - if (is_int($options['connect_timeout']) || $this->version < self::CURL_7_16_2) { |
|
| 406 | + if (is_int($options['connect_timeout']) || $this->version < self::CURL_7_16_2) |
|
| 407 | + { |
|
| 370 | 408 | curl_setopt($this->handle, CURLOPT_CONNECTTIMEOUT, ceil($options['connect_timeout'])); |
| 371 | 409 | } |
| 372 | - else { |
|
| 410 | + else |
|
| 411 | + { |
|
| 373 | 412 | curl_setopt($this->handle, CURLOPT_CONNECTTIMEOUT_MS, round($options['connect_timeout'] * 1000)); |
| 374 | 413 | } |
| 375 | 414 | curl_setopt($this->handle, CURLOPT_URL, $url); |
| 376 | 415 | curl_setopt($this->handle, CURLOPT_REFERER, $url); |
| 377 | 416 | curl_setopt($this->handle, CURLOPT_USERAGENT, $options['useragent']); |
| 378 | - if (!empty($headers)) { |
|
| 417 | + if (!empty($headers)) |
|
| 418 | + { |
|
| 379 | 419 | curl_setopt($this->handle, CURLOPT_HTTPHEADER, $headers); |
| 380 | 420 | } |
| 381 | - if ($options['protocol_version'] === 1.1) { |
|
| 421 | + if ($options['protocol_version'] === 1.1) |
|
| 422 | + { |
|
| 382 | 423 | curl_setopt($this->handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
| 383 | 424 | } |
| 384 | - else { |
|
| 425 | + else |
|
| 426 | + { |
|
| 385 | 427 | curl_setopt($this->handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); |
| 386 | 428 | } |
| 387 | 429 | |
| 388 | - if (true === $options['blocking']) { |
|
| 430 | + if (true === $options['blocking']) |
|
| 431 | + { |
|
| 389 | 432 | curl_setopt($this->handle, CURLOPT_HEADERFUNCTION, array(&$this, 'stream_headers')); |
| 390 | 433 | curl_setopt($this->handle, CURLOPT_WRITEFUNCTION, array(&$this, 'stream_body')); |
| 391 | 434 | curl_setopt($this->handle, CURLOPT_BUFFERSIZE, Requests::BUFFER_SIZE); |
@@ -399,21 +442,26 @@ discard block |
||
| 399 | 442 | * @param array $options Request options |
| 400 | 443 | * @return string HTTP response data including headers |
| 401 | 444 | */ |
| 402 | - public function process_response($response, $options) { |
|
| 403 | - if ($options['blocking'] === false) { |
|
| 445 | + public function process_response($response, $options) |
|
| 446 | + { |
|
| 447 | + if ($options['blocking'] === false) |
|
| 448 | + { |
|
| 404 | 449 | $fake_headers = ''; |
| 405 | 450 | $options['hooks']->dispatch('curl.after_request', array(&$fake_headers)); |
| 406 | 451 | return false; |
| 407 | 452 | } |
| 408 | - if ($options['filename'] !== false) { |
|
| 453 | + if ($options['filename'] !== false) |
|
| 454 | + { |
|
| 409 | 455 | fclose($this->stream_handle); |
| 410 | 456 | $this->headers = trim($this->headers); |
| 411 | 457 | } |
| 412 | - else { |
|
| 458 | + else |
|
| 459 | + { |
|
| 413 | 460 | $this->headers .= $response; |
| 414 | 461 | } |
| 415 | 462 | |
| 416 | - if (curl_errno($this->handle)) { |
|
| 463 | + if (curl_errno($this->handle)) |
|
| 464 | + { |
|
| 417 | 465 | $error = sprintf( |
| 418 | 466 | 'cURL error %s: %s', |
| 419 | 467 | curl_errno($this->handle), |
@@ -434,17 +482,20 @@ discard block |
||
| 434 | 482 | * @param string $headers Header string |
| 435 | 483 | * @return integer Length of provided header |
| 436 | 484 | */ |
| 437 | - public function stream_headers($handle, $headers) { |
|
| 485 | + public function stream_headers($handle, $headers) |
|
| 486 | + { |
|
| 438 | 487 | // Why do we do this? cURL will send both the final response and any |
| 439 | 488 | // interim responses, such as a 100 Continue. We don't need that. |
| 440 | 489 | // (We may want to keep this somewhere just in case) |
| 441 | - if ($this->done_headers) { |
|
| 490 | + if ($this->done_headers) |
|
| 491 | + { |
|
| 442 | 492 | $this->headers = ''; |
| 443 | 493 | $this->done_headers = false; |
| 444 | 494 | } |
| 445 | 495 | $this->headers .= $headers; |
| 446 | 496 | |
| 447 | - if ($headers === "\r\n") { |
|
| 497 | + if ($headers === "\r\n") |
|
| 498 | + { |
|
| 448 | 499 | $this->done_headers = true; |
| 449 | 500 | } |
| 450 | 501 | return strlen($headers); |
@@ -459,28 +510,34 @@ discard block |
||
| 459 | 510 | * @param string $data Body data |
| 460 | 511 | * @return integer Length of provided data |
| 461 | 512 | */ |
| 462 | - public function stream_body($handle, $data) { |
|
| 513 | + public function stream_body($handle, $data) |
|
| 514 | + { |
|
| 463 | 515 | $this->hooks->dispatch('request.progress', array($data, $this->response_bytes, $this->response_byte_limit)); |
| 464 | 516 | $data_length = strlen($data); |
| 465 | 517 | |
| 466 | 518 | // Are we limiting the response size? |
| 467 | - if ($this->response_byte_limit) { |
|
| 468 | - if ($this->response_bytes === $this->response_byte_limit) { |
|
| 519 | + if ($this->response_byte_limit) |
|
| 520 | + { |
|
| 521 | + if ($this->response_bytes === $this->response_byte_limit) |
|
| 522 | + { |
|
| 469 | 523 | // Already at maximum, move on |
| 470 | 524 | return $data_length; |
| 471 | 525 | } |
| 472 | 526 | |
| 473 | - if (($this->response_bytes + $data_length) > $this->response_byte_limit) { |
|
| 527 | + if (($this->response_bytes + $data_length) > $this->response_byte_limit) |
|
| 528 | + { |
|
| 474 | 529 | // Limit the length |
| 475 | 530 | $limited_length = ($this->response_byte_limit - $this->response_bytes); |
| 476 | 531 | $data = substr($data, 0, $limited_length); |
| 477 | 532 | } |
| 478 | 533 | } |
| 479 | 534 | |
| 480 | - if ($this->stream_handle) { |
|
| 535 | + if ($this->stream_handle) |
|
| 536 | + { |
|
| 481 | 537 | fwrite($this->stream_handle, $data); |
| 482 | 538 | } |
| 483 | - else { |
|
| 539 | + else |
|
| 540 | + { |
|
| 484 | 541 | $this->response_data .= $data; |
| 485 | 542 | } |
| 486 | 543 | |
@@ -495,23 +552,29 @@ discard block |
||
| 495 | 552 | * @param array|object $data Data to build query using, see {@see https://secure.php.net/http_build_query} |
| 496 | 553 | * @return string URL with data |
| 497 | 554 | */ |
| 498 | - protected static function format_get($url, $data) { |
|
| 499 | - if (!empty($data)) { |
|
| 555 | + protected static function format_get($url, $data) |
|
| 556 | + { |
|
| 557 | + if (!empty($data)) |
|
| 558 | + { |
|
| 500 | 559 | $url_parts = parse_url($url); |
| 501 | - if (empty($url_parts['query'])) { |
|
| 560 | + if (empty($url_parts['query'])) |
|
| 561 | + { |
|
| 502 | 562 | $query = $url_parts['query'] = ''; |
| 503 | 563 | } |
| 504 | - else { |
|
| 564 | + else |
|
| 565 | + { |
|
| 505 | 566 | $query = $url_parts['query']; |
| 506 | 567 | } |
| 507 | 568 | |
| 508 | 569 | $query .= '&' . http_build_query($data, null, '&'); |
| 509 | 570 | $query = trim($query, '&'); |
| 510 | 571 | |
| 511 | - if (empty($url_parts['query'])) { |
|
| 572 | + if (empty($url_parts['query'])) |
|
| 573 | + { |
|
| 512 | 574 | $url .= '?' . $query; |
| 513 | 575 | } |
| 514 | - else { |
|
| 576 | + else |
|
| 577 | + { |
|
| 515 | 578 | $url = str_replace($url_parts['query'], $query, $url); |
| 516 | 579 | } |
| 517 | 580 | } |
@@ -524,15 +587,19 @@ discard block |
||
| 524 | 587 | * @codeCoverageIgnore |
| 525 | 588 | * @return boolean True if the transport is valid, false otherwise. |
| 526 | 589 | */ |
| 527 | - public static function test($capabilities = array()) { |
|
| 528 | - if (!function_exists('curl_init') || !function_exists('curl_exec')) { |
|
| 590 | + public static function test($capabilities = array()) |
|
| 591 | + { |
|
| 592 | + if (!function_exists('curl_init') || !function_exists('curl_exec')) |
|
| 593 | + { |
|
| 529 | 594 | return false; |
| 530 | 595 | } |
| 531 | 596 | |
| 532 | 597 | // If needed, check that our installed curl version supports SSL |
| 533 | - if (isset($capabilities['ssl']) && $capabilities['ssl']) { |
|
| 598 | + if (isset($capabilities['ssl']) && $capabilities['ssl']) |
|
| 599 | + { |
|
| 534 | 600 | $curl_version = curl_version(); |
| 535 | - if (!(CURL_VERSION_SSL & $curl_version['features'])) { |
|
| 601 | + if (!(CURL_VERSION_SSL & $curl_version['features'])) |
|
| 602 | + { |
|
| 536 | 603 | return false; |
| 537 | 604 | } |
| 538 | 605 | } |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | * |
| 64 | 64 | * @var boolean |
| 65 | 65 | */ |
| 66 | - protected $done_headers = false; |
|
| 66 | + protected $done_headers = FALSE; |
|
| 67 | 67 | |
| 68 | 68 | /** |
| 69 | 69 | * If streaming to a file, keep the file pointer |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | $this->version = $curl['version_number']; |
| 95 | 95 | $this->handle = curl_init(); |
| 96 | 96 | |
| 97 | - curl_setopt($this->handle, CURLOPT_HEADER, false); |
|
| 97 | + curl_setopt($this->handle, CURLOPT_HEADER, FALSE); |
|
| 98 | 98 | curl_setopt($this->handle, CURLOPT_RETURNTRANSFER, 1); |
| 99 | 99 | if ($this->version >= self::CURL_7_10_5) { |
| 100 | 100 | curl_setopt($this->handle, CURLOPT_ENCODING, ''); |
@@ -134,19 +134,19 @@ discard block |
||
| 134 | 134 | |
| 135 | 135 | $options['hooks']->dispatch('curl.before_send', array(&$this->handle)); |
| 136 | 136 | |
| 137 | - if ($options['filename'] !== false) { |
|
| 137 | + if ($options['filename'] !== FALSE) { |
|
| 138 | 138 | $this->stream_handle = fopen($options['filename'], 'wb'); |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | $this->response_data = ''; |
| 142 | 142 | $this->response_bytes = 0; |
| 143 | - $this->response_byte_limit = false; |
|
| 144 | - if ($options['max_bytes'] !== false) { |
|
| 143 | + $this->response_byte_limit = FALSE; |
|
| 144 | + if ($options['max_bytes'] !== FALSE) { |
|
| 145 | 145 | $this->response_byte_limit = $options['max_bytes']; |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | if (isset($options['verify'])) { |
| 149 | - if ($options['verify'] === false) { |
|
| 149 | + if ($options['verify'] === FALSE) { |
|
| 150 | 150 | curl_setopt($this->handle, CURLOPT_SSL_VERIFYHOST, 0); |
| 151 | 151 | curl_setopt($this->handle, CURLOPT_SSL_VERIFYPEER, 0); |
| 152 | 152 | } |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | } |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | - if (isset($options['verifyname']) && $options['verifyname'] === false) { |
|
| 158 | + if (isset($options['verifyname']) && $options['verifyname'] === FALSE) { |
|
| 159 | 159 | curl_setopt($this->handle, CURLOPT_SSL_VERIFYHOST, 0); |
| 160 | 160 | } |
| 161 | 161 | |
@@ -178,8 +178,8 @@ discard block |
||
| 178 | 178 | |
| 179 | 179 | // Need to remove the $this reference from the curl handle. |
| 180 | 180 | // Otherwise Requests_Transport_cURL wont be garbage collected and the curl_close() will never be called. |
| 181 | - curl_setopt($this->handle, CURLOPT_HEADERFUNCTION, null); |
|
| 182 | - curl_setopt($this->handle, CURLOPT_WRITEFUNCTION, null); |
|
| 181 | + curl_setopt($this->handle, CURLOPT_HEADERFUNCTION, NULL); |
|
| 182 | + curl_setopt($this->handle, CURLOPT_WRITEFUNCTION, NULL); |
|
| 183 | 183 | |
| 184 | 184 | return $this->headers; |
| 185 | 185 | } |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | $request['options']['hooks']->dispatch('curl.before_multi_exec', array(&$multihandle)); |
| 216 | 216 | |
| 217 | 217 | do { |
| 218 | - $active = false; |
|
| 218 | + $active = FALSE; |
|
| 219 | 219 | |
| 220 | 220 | do { |
| 221 | 221 | $status = curl_multi_exec($multihandle, $active); |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | |
| 227 | 227 | // Read the information as needed |
| 228 | 228 | while ($done = curl_multi_info_read($multihandle)) { |
| 229 | - $key = array_search($done['handle'], $subhandles, true); |
|
| 229 | + $key = array_search($done['handle'], $subhandles, TRUE); |
|
| 230 | 230 | if (!isset($to_process[$key])) { |
| 231 | 231 | $to_process[$key] = $done; |
| 232 | 232 | } |
@@ -283,14 +283,14 @@ discard block |
||
| 283 | 283 | public function &get_subrequest_handle($url, $headers, $data, $options) { |
| 284 | 284 | $this->setup_handle($url, $headers, $data, $options); |
| 285 | 285 | |
| 286 | - if ($options['filename'] !== false) { |
|
| 286 | + if ($options['filename'] !== FALSE) { |
|
| 287 | 287 | $this->stream_handle = fopen($options['filename'], 'wb'); |
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | $this->response_data = ''; |
| 291 | 291 | $this->response_bytes = 0; |
| 292 | - $this->response_byte_limit = false; |
|
| 293 | - if ($options['max_bytes'] !== false) { |
|
| 292 | + $this->response_byte_limit = FALSE; |
|
| 293 | + if ($options['max_bytes'] !== FALSE) { |
|
| 294 | 294 | $this->response_byte_limit = $options['max_bytes']; |
| 295 | 295 | } |
| 296 | 296 | $this->hooks = $options['hooks']; |
@@ -324,18 +324,18 @@ discard block |
||
| 324 | 324 | $data = ''; |
| 325 | 325 | } |
| 326 | 326 | elseif (!is_string($data)) { |
| 327 | - $data = http_build_query($data, null, '&'); |
|
| 327 | + $data = http_build_query($data, NULL, '&'); |
|
| 328 | 328 | } |
| 329 | 329 | } |
| 330 | 330 | |
| 331 | 331 | switch ($options['type']) { |
| 332 | 332 | case Requests::POST: |
| 333 | - curl_setopt($this->handle, CURLOPT_POST, true); |
|
| 333 | + curl_setopt($this->handle, CURLOPT_POST, TRUE); |
|
| 334 | 334 | curl_setopt($this->handle, CURLOPT_POSTFIELDS, $data); |
| 335 | 335 | break; |
| 336 | 336 | case Requests::HEAD: |
| 337 | 337 | curl_setopt($this->handle, CURLOPT_CUSTOMREQUEST, $options['type']); |
| 338 | - curl_setopt($this->handle, CURLOPT_NOBODY, true); |
|
| 338 | + curl_setopt($this->handle, CURLOPT_NOBODY, TRUE); |
|
| 339 | 339 | break; |
| 340 | 340 | case Requests::TRACE: |
| 341 | 341 | curl_setopt($this->handle, CURLOPT_CUSTOMREQUEST, $options['type']); |
@@ -385,7 +385,7 @@ discard block |
||
| 385 | 385 | curl_setopt($this->handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); |
| 386 | 386 | } |
| 387 | 387 | |
| 388 | - if (true === $options['blocking']) { |
|
| 388 | + if (TRUE === $options['blocking']) { |
|
| 389 | 389 | curl_setopt($this->handle, CURLOPT_HEADERFUNCTION, array(&$this, 'stream_headers')); |
| 390 | 390 | curl_setopt($this->handle, CURLOPT_WRITEFUNCTION, array(&$this, 'stream_body')); |
| 391 | 391 | curl_setopt($this->handle, CURLOPT_BUFFERSIZE, Requests::BUFFER_SIZE); |
@@ -400,12 +400,12 @@ discard block |
||
| 400 | 400 | * @return string HTTP response data including headers |
| 401 | 401 | */ |
| 402 | 402 | public function process_response($response, $options) { |
| 403 | - if ($options['blocking'] === false) { |
|
| 403 | + if ($options['blocking'] === FALSE) { |
|
| 404 | 404 | $fake_headers = ''; |
| 405 | 405 | $options['hooks']->dispatch('curl.after_request', array(&$fake_headers)); |
| 406 | - return false; |
|
| 406 | + return FALSE; |
|
| 407 | 407 | } |
| 408 | - if ($options['filename'] !== false) { |
|
| 408 | + if ($options['filename'] !== FALSE) { |
|
| 409 | 409 | fclose($this->stream_handle); |
| 410 | 410 | $this->headers = trim($this->headers); |
| 411 | 411 | } |
@@ -440,12 +440,12 @@ discard block |
||
| 440 | 440 | // (We may want to keep this somewhere just in case) |
| 441 | 441 | if ($this->done_headers) { |
| 442 | 442 | $this->headers = ''; |
| 443 | - $this->done_headers = false; |
|
| 443 | + $this->done_headers = FALSE; |
|
| 444 | 444 | } |
| 445 | 445 | $this->headers .= $headers; |
| 446 | 446 | |
| 447 | 447 | if ($headers === "\r\n") { |
| 448 | - $this->done_headers = true; |
|
| 448 | + $this->done_headers = TRUE; |
|
| 449 | 449 | } |
| 450 | 450 | return strlen($headers); |
| 451 | 451 | } |
@@ -505,7 +505,7 @@ discard block |
||
| 505 | 505 | $query = $url_parts['query']; |
| 506 | 506 | } |
| 507 | 507 | |
| 508 | - $query .= '&' . http_build_query($data, null, '&'); |
|
| 508 | + $query .= '&' . http_build_query($data, NULL, '&'); |
|
| 509 | 509 | $query = trim($query, '&'); |
| 510 | 510 | |
| 511 | 511 | if (empty($url_parts['query'])) { |
@@ -526,17 +526,17 @@ discard block |
||
| 526 | 526 | */ |
| 527 | 527 | public static function test($capabilities = array()) { |
| 528 | 528 | if (!function_exists('curl_init') || !function_exists('curl_exec')) { |
| 529 | - return false; |
|
| 529 | + return FALSE; |
|
| 530 | 530 | } |
| 531 | 531 | |
| 532 | 532 | // If needed, check that our installed curl version supports SSL |
| 533 | 533 | if (isset($capabilities['ssl']) && $capabilities['ssl']) { |
| 534 | 534 | $curl_version = curl_version(); |
| 535 | 535 | if (!(CURL_VERSION_SSL & $curl_version['features'])) { |
| 536 | - return false; |
|
| 536 | + return FALSE; |
|
| 537 | 537 | } |
| 538 | 538 | } |
| 539 | 539 | |
| 540 | - return true; |
|
| 540 | + return TRUE; |
|
| 541 | 541 | } |
| 542 | 542 | } |
@@ -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 | } |
@@ -12,7 +12,8 @@ discard block |
||
| 12 | 12 | * @package Requests |
| 13 | 13 | * @subpackage Transport |
| 14 | 14 | */ |
| 15 | -class Requests_Transport_fsockopen implements Requests_Transport { |
|
| 15 | +class Requests_Transport_fsockopen implements Requests_Transport |
|
| 16 | +{ |
|
| 16 | 17 | /** |
| 17 | 18 | * Second to microsecond conversion |
| 18 | 19 | * |
@@ -55,11 +56,13 @@ discard block |
||
| 55 | 56 | * @param array $options Request options, see {@see Requests::response()} for documentation |
| 56 | 57 | * @return string Raw HTTP result |
| 57 | 58 | */ |
| 58 | - public function request($url, $headers = array(), $data = array(), $options = array()) { |
|
| 59 | + public function request($url, $headers = array(), $data = array(), $options = array()) |
|
| 60 | + { |
|
| 59 | 61 | $options['hooks']->dispatch('fsockopen.before_request'); |
| 60 | 62 | |
| 61 | 63 | $url_parts = parse_url($url); |
| 62 | - if (empty($url_parts)) { |
|
| 64 | + if (empty($url_parts)) |
|
| 65 | + { |
|
| 63 | 66 | throw new Requests_Exception('Invalid URL.', 'invalidurl', $url); |
| 64 | 67 | } |
| 65 | 68 | $host = $url_parts['host']; |
@@ -68,9 +71,11 @@ discard block |
||
| 68 | 71 | $case_insensitive_headers = new Requests_Utility_CaseInsensitiveDictionary($headers); |
| 69 | 72 | |
| 70 | 73 | // HTTPS support |
| 71 | - if (isset($url_parts['scheme']) && strtolower($url_parts['scheme']) === 'https') { |
|
| 74 | + if (isset($url_parts['scheme']) && strtolower($url_parts['scheme']) === 'https') |
|
| 75 | + { |
|
| 72 | 76 | $remote_socket = 'ssl://' . $host; |
| 73 | - if (!isset($url_parts['port'])) { |
|
| 77 | + if (!isset($url_parts['port'])) |
|
| 78 | + { |
|
| 74 | 79 | $url_parts['port'] = 443; |
| 75 | 80 | } |
| 76 | 81 | |
@@ -82,36 +87,44 @@ discard block |
||
| 82 | 87 | $verifyname = true; |
| 83 | 88 | |
| 84 | 89 | // SNI, if enabled (OpenSSL >=0.9.8j) |
| 85 | - if (defined('OPENSSL_TLSEXT_SERVER_NAME') && OPENSSL_TLSEXT_SERVER_NAME) { |
|
| 90 | + if (defined('OPENSSL_TLSEXT_SERVER_NAME') && OPENSSL_TLSEXT_SERVER_NAME) |
|
| 91 | + { |
|
| 86 | 92 | $context_options['SNI_enabled'] = true; |
| 87 | - if (isset($options['verifyname']) && $options['verifyname'] === false) { |
|
| 93 | + if (isset($options['verifyname']) && $options['verifyname'] === false) |
|
| 94 | + { |
|
| 88 | 95 | $context_options['SNI_enabled'] = false; |
| 89 | 96 | } |
| 90 | 97 | } |
| 91 | 98 | |
| 92 | - if (isset($options['verify'])) { |
|
| 93 | - if ($options['verify'] === false) { |
|
| 99 | + if (isset($options['verify'])) |
|
| 100 | + { |
|
| 101 | + if ($options['verify'] === false) |
|
| 102 | + { |
|
| 94 | 103 | $context_options['verify_peer'] = false; |
| 95 | 104 | } |
| 96 | - elseif (is_string($options['verify'])) { |
|
| 105 | + elseif (is_string($options['verify'])) |
|
| 106 | + { |
|
| 97 | 107 | $context_options['cafile'] = $options['verify']; |
| 98 | 108 | } |
| 99 | 109 | } |
| 100 | 110 | |
| 101 | - if (isset($options['verifyname']) && $options['verifyname'] === false) { |
|
| 111 | + if (isset($options['verifyname']) && $options['verifyname'] === false) |
|
| 112 | + { |
|
| 102 | 113 | $context_options['verify_peer_name'] = false; |
| 103 | 114 | $verifyname = false; |
| 104 | 115 | } |
| 105 | 116 | |
| 106 | 117 | stream_context_set_option($context, array('ssl' => $context_options)); |
| 107 | 118 | } |
| 108 | - else { |
|
| 119 | + else |
|
| 120 | + { |
|
| 109 | 121 | $remote_socket = 'tcp://' . $host; |
| 110 | 122 | } |
| 111 | 123 | |
| 112 | 124 | $this->max_bytes = $options['max_bytes']; |
| 113 | 125 | |
| 114 | - if (!isset($url_parts['port'])) { |
|
| 126 | + if (!isset($url_parts['port'])) |
|
| 127 | + { |
|
| 115 | 128 | $url_parts['port'] = 80; |
| 116 | 129 | } |
| 117 | 130 | $remote_socket .= ':' . $url_parts['port']; |
@@ -124,12 +137,15 @@ discard block |
||
| 124 | 137 | |
| 125 | 138 | restore_error_handler(); |
| 126 | 139 | |
| 127 | - if ($verifyname && !$this->verify_certificate_from_context($host, $context)) { |
|
| 140 | + if ($verifyname && !$this->verify_certificate_from_context($host, $context)) |
|
| 141 | + { |
|
| 128 | 142 | throw new Requests_Exception('SSL certificate did not match the requested domain name', 'ssl.no_match'); |
| 129 | 143 | } |
| 130 | 144 | |
| 131 | - if (!$socket) { |
|
| 132 | - if ($errno === 0) { |
|
| 145 | + if (!$socket) |
|
| 146 | + { |
|
| 147 | + if ($errno === 0) |
|
| 148 | + { |
|
| 133 | 149 | // Connection issue |
| 134 | 150 | throw new Requests_Exception(rtrim($this->connect_error), 'fsockopen.connect_error'); |
| 135 | 151 | } |
@@ -139,11 +155,13 @@ discard block |
||
| 139 | 155 | |
| 140 | 156 | $data_format = $options['data_format']; |
| 141 | 157 | |
| 142 | - if ($data_format === 'query') { |
|
| 158 | + if ($data_format === 'query') |
|
| 159 | + { |
|
| 143 | 160 | $path = self::format_get($url_parts, $data); |
| 144 | 161 | $data = ''; |
| 145 | 162 | } |
| 146 | - else { |
|
| 163 | + else |
|
| 164 | + { |
|
| 147 | 165 | $path = self::format_get($url_parts, array()); |
| 148 | 166 | } |
| 149 | 167 | |
@@ -152,56 +170,69 @@ discard block |
||
| 152 | 170 | $request_body = ''; |
| 153 | 171 | $out = sprintf("%s %s HTTP/%.1f\r\n", $options['type'], $path, $options['protocol_version']); |
| 154 | 172 | |
| 155 | - if ($options['type'] !== Requests::TRACE) { |
|
| 156 | - if (is_array($data)) { |
|
| 173 | + if ($options['type'] !== Requests::TRACE) |
|
| 174 | + { |
|
| 175 | + if (is_array($data)) |
|
| 176 | + { |
|
| 157 | 177 | $request_body = http_build_query($data, null, '&'); |
| 158 | 178 | } |
| 159 | - else { |
|
| 179 | + else |
|
| 180 | + { |
|
| 160 | 181 | $request_body = $data; |
| 161 | 182 | } |
| 162 | 183 | |
| 163 | - if (!empty($data)) { |
|
| 164 | - if (!isset($case_insensitive_headers['Content-Length'])) { |
|
| 184 | + if (!empty($data)) |
|
| 185 | + { |
|
| 186 | + if (!isset($case_insensitive_headers['Content-Length'])) |
|
| 187 | + { |
|
| 165 | 188 | $headers['Content-Length'] = strlen($request_body); |
| 166 | 189 | } |
| 167 | 190 | |
| 168 | - if (!isset($case_insensitive_headers['Content-Type'])) { |
|
| 191 | + if (!isset($case_insensitive_headers['Content-Type'])) |
|
| 192 | + { |
|
| 169 | 193 | $headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8'; |
| 170 | 194 | } |
| 171 | 195 | } |
| 172 | 196 | } |
| 173 | 197 | |
| 174 | - if (!isset($case_insensitive_headers['Host'])) { |
|
| 198 | + if (!isset($case_insensitive_headers['Host'])) |
|
| 199 | + { |
|
| 175 | 200 | $out .= sprintf('Host: %s', $url_parts['host']); |
| 176 | 201 | |
| 177 | - if (( 'http' === strtolower($url_parts['scheme']) && $url_parts['port'] !== 80 ) || ( 'https' === strtolower($url_parts['scheme']) && $url_parts['port'] !== 443 )) { |
|
| 202 | + if (( 'http' === strtolower($url_parts['scheme']) && $url_parts['port'] !== 80 ) || ( 'https' === strtolower($url_parts['scheme']) && $url_parts['port'] !== 443 )) |
|
| 203 | + { |
|
| 178 | 204 | $out .= ':' . $url_parts['port']; |
| 179 | 205 | } |
| 180 | 206 | $out .= "\r\n"; |
| 181 | 207 | } |
| 182 | 208 | |
| 183 | - if (!isset($case_insensitive_headers['User-Agent'])) { |
|
| 209 | + if (!isset($case_insensitive_headers['User-Agent'])) |
|
| 210 | + { |
|
| 184 | 211 | $out .= sprintf("User-Agent: %s\r\n", $options['useragent']); |
| 185 | 212 | } |
| 186 | 213 | |
| 187 | 214 | $accept_encoding = $this->accept_encoding(); |
| 188 | - if (!isset($case_insensitive_headers['Accept-Encoding']) && !empty($accept_encoding)) { |
|
| 215 | + if (!isset($case_insensitive_headers['Accept-Encoding']) && !empty($accept_encoding)) |
|
| 216 | + { |
|
| 189 | 217 | $out .= sprintf("Accept-Encoding: %s\r\n", $accept_encoding); |
| 190 | 218 | } |
| 191 | 219 | |
| 192 | 220 | $headers = Requests::flatten($headers); |
| 193 | 221 | |
| 194 | - if (!empty($headers)) { |
|
| 222 | + if (!empty($headers)) |
|
| 223 | + { |
|
| 195 | 224 | $out .= implode($headers, "\r\n") . "\r\n"; |
| 196 | 225 | } |
| 197 | 226 | |
| 198 | 227 | $options['hooks']->dispatch('fsockopen.after_headers', array(&$out)); |
| 199 | 228 | |
| 200 | - if (substr($out, -2) !== "\r\n") { |
|
| 229 | + if (substr($out, -2) !== "\r\n") |
|
| 230 | + { |
|
| 201 | 231 | $out .= "\r\n"; |
| 202 | 232 | } |
| 203 | 233 | |
| 204 | - if (!isset($case_insensitive_headers['Connection'])) { |
|
| 234 | + if (!isset($case_insensitive_headers['Connection'])) |
|
| 235 | + { |
|
| 205 | 236 | $out .= "Connection: Close\r\n"; |
| 206 | 237 | } |
| 207 | 238 | |
@@ -212,7 +243,8 @@ discard block |
||
| 212 | 243 | fwrite($socket, $out); |
| 213 | 244 | $options['hooks']->dispatch('fsockopen.after_send', array($out)); |
| 214 | 245 | |
| 215 | - if (!$options['blocking']) { |
|
| 246 | + if (!$options['blocking']) |
|
| 247 | + { |
|
| 216 | 248 | fclose($socket); |
| 217 | 249 | $fake_headers = ''; |
| 218 | 250 | $options['hooks']->dispatch('fsockopen.after_request', array(&$fake_headers)); |
@@ -220,10 +252,12 @@ discard block |
||
| 220 | 252 | } |
| 221 | 253 | |
| 222 | 254 | $timeout_sec = (int) floor($options['timeout']); |
| 223 | - if ($timeout_sec == $options['timeout']) { |
|
| 255 | + if ($timeout_sec == $options['timeout']) |
|
| 256 | + { |
|
| 224 | 257 | $timeout_msec = 0; |
| 225 | 258 | } |
| 226 | - else { |
|
| 259 | + else |
|
| 260 | + { |
|
| 227 | 261 | $timeout_msec = self::SECOND_IN_MICROSECONDS * $options['timeout'] % self::SECOND_IN_MICROSECONDS; |
| 228 | 262 | } |
| 229 | 263 | stream_set_timeout($socket, $timeout_sec, $timeout_msec); |
@@ -233,35 +267,44 @@ discard block |
||
| 233 | 267 | $size = 0; |
| 234 | 268 | $doingbody = false; |
| 235 | 269 | $download = false; |
| 236 | - if ($options['filename']) { |
|
| 270 | + if ($options['filename']) |
|
| 271 | + { |
|
| 237 | 272 | $download = fopen($options['filename'], 'wb'); |
| 238 | 273 | } |
| 239 | 274 | |
| 240 | - while (!feof($socket)) { |
|
| 275 | + while (!feof($socket)) |
|
| 276 | + { |
|
| 241 | 277 | $this->info = stream_get_meta_data($socket); |
| 242 | - if ($this->info['timed_out']) { |
|
| 278 | + if ($this->info['timed_out']) |
|
| 279 | + { |
|
| 243 | 280 | throw new Requests_Exception('fsocket timed out', 'timeout'); |
| 244 | 281 | } |
| 245 | 282 | |
| 246 | 283 | $block = fread($socket, Requests::BUFFER_SIZE); |
| 247 | - if (!$doingbody) { |
|
| 284 | + if (!$doingbody) |
|
| 285 | + { |
|
| 248 | 286 | $response .= $block; |
| 249 | - if (strpos($response, "\r\n\r\n")) { |
|
| 287 | + if (strpos($response, "\r\n\r\n")) |
|
| 288 | + { |
|
| 250 | 289 | list($headers, $block) = explode("\r\n\r\n", $response, 2); |
| 251 | 290 | $doingbody = true; |
| 252 | 291 | } |
| 253 | 292 | } |
| 254 | 293 | |
| 255 | 294 | // Are we in body mode now? |
| 256 | - if ($doingbody) { |
|
| 295 | + if ($doingbody) |
|
| 296 | + { |
|
| 257 | 297 | $options['hooks']->dispatch('request.progress', array($block, $size, $this->max_bytes)); |
| 258 | 298 | $data_length = strlen($block); |
| 259 | - if ($this->max_bytes) { |
|
| 299 | + if ($this->max_bytes) |
|
| 300 | + { |
|
| 260 | 301 | // Have we already hit a limit? |
| 261 | - if ($size === $this->max_bytes) { |
|
| 302 | + if ($size === $this->max_bytes) |
|
| 303 | + { |
|
| 262 | 304 | continue; |
| 263 | 305 | } |
| 264 | - if (($size + $data_length) > $this->max_bytes) { |
|
| 306 | + if (($size + $data_length) > $this->max_bytes) |
|
| 307 | + { |
|
| 265 | 308 | // Limit the length |
| 266 | 309 | $limited_length = ($this->max_bytes - $size); |
| 267 | 310 | $block = substr($block, 0, $limited_length); |
@@ -269,20 +312,24 @@ discard block |
||
| 269 | 312 | } |
| 270 | 313 | |
| 271 | 314 | $size += strlen($block); |
| 272 | - if ($download) { |
|
| 315 | + if ($download) |
|
| 316 | + { |
|
| 273 | 317 | fwrite($download, $block); |
| 274 | 318 | } |
| 275 | - else { |
|
| 319 | + else |
|
| 320 | + { |
|
| 276 | 321 | $body .= $block; |
| 277 | 322 | } |
| 278 | 323 | } |
| 279 | 324 | } |
| 280 | 325 | $this->headers = $headers; |
| 281 | 326 | |
| 282 | - if ($download) { |
|
| 327 | + if ($download) |
|
| 328 | + { |
|
| 283 | 329 | fclose($download); |
| 284 | 330 | } |
| 285 | - else { |
|
| 331 | + else |
|
| 332 | + { |
|
| 286 | 333 | $this->headers .= "\r\n\r\n" . $body; |
| 287 | 334 | } |
| 288 | 335 | fclose($socket); |
@@ -298,21 +345,26 @@ discard block |
||
| 298 | 345 | * @param array $options Global options, see {@see Requests::response()} for documentation |
| 299 | 346 | * @return array Array of Requests_Response objects (may contain Requests_Exception or string responses as well) |
| 300 | 347 | */ |
| 301 | - public function request_multiple($requests, $options) { |
|
| 348 | + public function request_multiple($requests, $options) |
|
| 349 | + { |
|
| 302 | 350 | $responses = array(); |
| 303 | 351 | $class = get_class($this); |
| 304 | - foreach ($requests as $id => $request) { |
|
| 305 | - try { |
|
| 352 | + foreach ($requests as $id => $request) |
|
| 353 | + { |
|
| 354 | + try |
|
| 355 | + { |
|
| 306 | 356 | $handler = new $class(); |
| 307 | 357 | $responses[$id] = $handler->request($request['url'], $request['headers'], $request['data'], $request['options']); |
| 308 | 358 | |
| 309 | 359 | $request['options']['hooks']->dispatch('transport.internal.parse_response', array(&$responses[$id], $request)); |
| 310 | 360 | } |
| 311 | - catch (Requests_Exception $e) { |
|
| 361 | + catch (Requests_Exception $e) |
|
| 362 | + { |
|
| 312 | 363 | $responses[$id] = $e; |
| 313 | 364 | } |
| 314 | 365 | |
| 315 | - if (!is_string($responses[$id])) { |
|
| 366 | + if (!is_string($responses[$id])) |
|
| 367 | + { |
|
| 316 | 368 | $request['options']['hooks']->dispatch('multiple.request.complete', array(&$responses[$id], $id)); |
| 317 | 369 | } |
| 318 | 370 | } |
@@ -325,13 +377,16 @@ discard block |
||
| 325 | 377 | * |
| 326 | 378 | * @return string Accept-Encoding header value |
| 327 | 379 | */ |
| 328 | - protected static function accept_encoding() { |
|
| 380 | + protected static function accept_encoding() |
|
| 381 | + { |
|
| 329 | 382 | $type = array(); |
| 330 | - if (function_exists('gzinflate')) { |
|
| 383 | + if (function_exists('gzinflate')) |
|
| 384 | + { |
|
| 331 | 385 | $type[] = 'deflate;q=1.0'; |
| 332 | 386 | } |
| 333 | 387 | |
| 334 | - if (function_exists('gzuncompress')) { |
|
| 388 | + if (function_exists('gzuncompress')) |
|
| 389 | + { |
|
| 335 | 390 | $type[] = 'compress;q=0.5'; |
| 336 | 391 | } |
| 337 | 392 | |
@@ -347,24 +402,31 @@ discard block |
||
| 347 | 402 | * @param array|object $data Data to build query using, see {@see https://secure.php.net/http_build_query} |
| 348 | 403 | * @return string URL with data |
| 349 | 404 | */ |
| 350 | - protected static function format_get($url_parts, $data) { |
|
| 351 | - if (!empty($data)) { |
|
| 352 | - if (empty($url_parts['query'])) { |
|
| 405 | + protected static function format_get($url_parts, $data) |
|
| 406 | + { |
|
| 407 | + if (!empty($data)) |
|
| 408 | + { |
|
| 409 | + if (empty($url_parts['query'])) |
|
| 410 | + { |
|
| 353 | 411 | $url_parts['query'] = ''; |
| 354 | 412 | } |
| 355 | 413 | |
| 356 | 414 | $url_parts['query'] .= '&' . http_build_query($data, null, '&'); |
| 357 | 415 | $url_parts['query'] = trim($url_parts['query'], '&'); |
| 358 | 416 | } |
| 359 | - if (isset($url_parts['path'])) { |
|
| 360 | - if (isset($url_parts['query'])) { |
|
| 417 | + if (isset($url_parts['path'])) |
|
| 418 | + { |
|
| 419 | + if (isset($url_parts['query'])) |
|
| 420 | + { |
|
| 361 | 421 | $get = $url_parts['path'] . '?' . $url_parts['query']; |
| 362 | 422 | } |
| 363 | - else { |
|
| 423 | + else |
|
| 424 | + { |
|
| 364 | 425 | $get = $url_parts['path']; |
| 365 | 426 | } |
| 366 | 427 | } |
| 367 | - else { |
|
| 428 | + else |
|
| 429 | + { |
|
| 368 | 430 | $get = '/'; |
| 369 | 431 | } |
| 370 | 432 | return $get; |
@@ -376,9 +438,11 @@ discard block |
||
| 376 | 438 | * @param int $errno Error number (e.g. E_WARNING) |
| 377 | 439 | * @param string $errstr Error message |
| 378 | 440 | */ |
| 379 | - public function connect_error_handler($errno, $errstr) { |
|
| 441 | + public function connect_error_handler($errno, $errstr) |
|
| 442 | + { |
|
| 380 | 443 | // Double-check we can handle it |
| 381 | - if (($errno & E_WARNING) === 0 && ($errno & E_NOTICE) === 0) { |
|
| 444 | + if (($errno & E_WARNING) === 0 && ($errno & E_NOTICE) === 0) |
|
| 445 | + { |
|
| 382 | 446 | // Return false to indicate the default error handler should engage |
| 383 | 447 | return false; |
| 384 | 448 | } |
@@ -402,12 +466,14 @@ discard block |
||
| 402 | 466 | * @param resource $context Stream context |
| 403 | 467 | * @return bool |
| 404 | 468 | */ |
| 405 | - public function verify_certificate_from_context($host, $context) { |
|
| 469 | + public function verify_certificate_from_context($host, $context) |
|
| 470 | + { |
|
| 406 | 471 | $meta = stream_context_get_options($context); |
| 407 | 472 | |
| 408 | 473 | // If we don't have SSL options, then we couldn't make the connection at |
| 409 | 474 | // all |
| 410 | - if (empty($meta) || empty($meta['ssl']) || empty($meta['ssl']['peer_certificate'])) { |
|
| 475 | + if (empty($meta) || empty($meta['ssl']) || empty($meta['ssl']['peer_certificate'])) |
|
| 476 | + { |
|
| 411 | 477 | throw new Requests_Exception(rtrim($this->connect_error), 'ssl.connect_error'); |
| 412 | 478 | } |
| 413 | 479 | |
@@ -422,19 +488,24 @@ discard block |
||
| 422 | 488 | * @codeCoverageIgnore |
| 423 | 489 | * @return boolean True if the transport is valid, false otherwise. |
| 424 | 490 | */ |
| 425 | - public static function test($capabilities = array()) { |
|
| 426 | - if (!function_exists('fsockopen')) { |
|
| 491 | + public static function test($capabilities = array()) |
|
| 492 | + { |
|
| 493 | + if (!function_exists('fsockopen')) |
|
| 494 | + { |
|
| 427 | 495 | return false; |
| 428 | 496 | } |
| 429 | 497 | |
| 430 | 498 | // If needed, check that streams support SSL |
| 431 | - if (isset($capabilities['ssl']) && $capabilities['ssl']) { |
|
| 432 | - if (!extension_loaded('openssl') || !function_exists('openssl_x509_parse')) { |
|
| 499 | + if (isset($capabilities['ssl']) && $capabilities['ssl']) |
|
| 500 | + { |
|
| 501 | + if (!extension_loaded('openssl') || !function_exists('openssl_x509_parse')) |
|
| 502 | + { |
|
| 433 | 503 | return false; |
| 434 | 504 | } |
| 435 | 505 | |
| 436 | 506 | // Currently broken, thanks to https://github.com/facebook/hhvm/issues/2156 |
| 437 | - if (defined('HHVM_VERSION')) { |
|
| 507 | + if (defined('HHVM_VERSION')) |
|
| 508 | + { |
|
| 438 | 509 | return false; |
| 439 | 510 | } |
| 440 | 511 | } |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | * |
| 40 | 40 | * @var int|bool Byte count, or false if no limit. |
| 41 | 41 | */ |
| 42 | - protected $max_bytes = false; |
|
| 42 | + protected $max_bytes = FALSE; |
|
| 43 | 43 | |
| 44 | 44 | protected $connect_error = ''; |
| 45 | 45 | |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | } |
| 65 | 65 | $host = $url_parts['host']; |
| 66 | 66 | $context = stream_context_create(); |
| 67 | - $verifyname = false; |
|
| 67 | + $verifyname = FALSE; |
|
| 68 | 68 | $case_insensitive_headers = new Requests_Utility_CaseInsensitiveDictionary($headers); |
| 69 | 69 | |
| 70 | 70 | // HTTPS support |
@@ -75,32 +75,32 @@ discard block |
||
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | $context_options = array( |
| 78 | - 'verify_peer' => true, |
|
| 78 | + 'verify_peer' => TRUE, |
|
| 79 | 79 | // 'CN_match' => $host, |
| 80 | - 'capture_peer_cert' => true |
|
| 80 | + 'capture_peer_cert' => TRUE |
|
| 81 | 81 | ); |
| 82 | - $verifyname = true; |
|
| 82 | + $verifyname = TRUE; |
|
| 83 | 83 | |
| 84 | 84 | // SNI, if enabled (OpenSSL >=0.9.8j) |
| 85 | 85 | if (defined('OPENSSL_TLSEXT_SERVER_NAME') && OPENSSL_TLSEXT_SERVER_NAME) { |
| 86 | - $context_options['SNI_enabled'] = true; |
|
| 87 | - if (isset($options['verifyname']) && $options['verifyname'] === false) { |
|
| 88 | - $context_options['SNI_enabled'] = false; |
|
| 86 | + $context_options['SNI_enabled'] = TRUE; |
|
| 87 | + if (isset($options['verifyname']) && $options['verifyname'] === FALSE) { |
|
| 88 | + $context_options['SNI_enabled'] = FALSE; |
|
| 89 | 89 | } |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | if (isset($options['verify'])) { |
| 93 | - if ($options['verify'] === false) { |
|
| 94 | - $context_options['verify_peer'] = false; |
|
| 93 | + if ($options['verify'] === FALSE) { |
|
| 94 | + $context_options['verify_peer'] = FALSE; |
|
| 95 | 95 | } |
| 96 | 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) { |
|
| 102 | - $context_options['verify_peer_name'] = false; |
|
| 103 | - $verifyname = false; |
|
| 101 | + if (isset($options['verifyname']) && $options['verifyname'] === FALSE) { |
|
| 102 | + $context_options['verify_peer_name'] = FALSE; |
|
| 103 | + $verifyname = FALSE; |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | stream_context_set_option($context, array('ssl' => $context_options)); |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | throw new Requests_Exception(rtrim($this->connect_error), 'fsockopen.connect_error'); |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - throw new Requests_Exception($errstr, 'fsockopenerror', null, $errno); |
|
| 137 | + throw new Requests_Exception($errstr, 'fsockopenerror', NULL, $errno); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | $data_format = $options['data_format']; |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | |
| 155 | 155 | if ($options['type'] !== Requests::TRACE) { |
| 156 | 156 | if (is_array($data)) { |
| 157 | - $request_body = http_build_query($data, null, '&'); |
|
| 157 | + $request_body = http_build_query($data, NULL, '&'); |
|
| 158 | 158 | } |
| 159 | 159 | else { |
| 160 | 160 | $request_body = $data; |
@@ -231,8 +231,8 @@ discard block |
||
| 231 | 231 | $response = $body = $headers = ''; |
| 232 | 232 | $this->info = stream_get_meta_data($socket); |
| 233 | 233 | $size = 0; |
| 234 | - $doingbody = false; |
|
| 235 | - $download = false; |
|
| 234 | + $doingbody = FALSE; |
|
| 235 | + $download = FALSE; |
|
| 236 | 236 | if ($options['filename']) { |
| 237 | 237 | $download = fopen($options['filename'], 'wb'); |
| 238 | 238 | } |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | $response .= $block; |
| 249 | 249 | if (strpos($response, "\r\n\r\n")) { |
| 250 | 250 | list($headers, $block) = explode("\r\n\r\n", $response, 2); |
| 251 | - $doingbody = true; |
|
| 251 | + $doingbody = TRUE; |
|
| 252 | 252 | } |
| 253 | 253 | } |
| 254 | 254 | |
@@ -353,7 +353,7 @@ discard block |
||
| 353 | 353 | $url_parts['query'] = ''; |
| 354 | 354 | } |
| 355 | 355 | |
| 356 | - $url_parts['query'] .= '&' . http_build_query($data, null, '&'); |
|
| 356 | + $url_parts['query'] .= '&' . http_build_query($data, NULL, '&'); |
|
| 357 | 357 | $url_parts['query'] = trim($url_parts['query'], '&'); |
| 358 | 358 | } |
| 359 | 359 | if (isset($url_parts['path'])) { |
@@ -380,11 +380,11 @@ discard block |
||
| 380 | 380 | // Double-check we can handle it |
| 381 | 381 | if (($errno & E_WARNING) === 0 && ($errno & E_NOTICE) === 0) { |
| 382 | 382 | // Return false to indicate the default error handler should engage |
| 383 | - return false; |
|
| 383 | + return FALSE; |
|
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | $this->connect_error .= $errstr . "\n"; |
| 387 | - return true; |
|
| 387 | + return TRUE; |
|
| 388 | 388 | } |
| 389 | 389 | |
| 390 | 390 | /** |
@@ -424,21 +424,21 @@ discard block |
||
| 424 | 424 | */ |
| 425 | 425 | public static function test($capabilities = array()) { |
| 426 | 426 | if (!function_exists('fsockopen')) { |
| 427 | - return false; |
|
| 427 | + return FALSE; |
|
| 428 | 428 | } |
| 429 | 429 | |
| 430 | 430 | // If needed, check that streams support SSL |
| 431 | 431 | if (isset($capabilities['ssl']) && $capabilities['ssl']) { |
| 432 | 432 | if (!extension_loaded('openssl') || !function_exists('openssl_x509_parse')) { |
| 433 | - return false; |
|
| 433 | + return FALSE; |
|
| 434 | 434 | } |
| 435 | 435 | |
| 436 | 436 | // Currently broken, thanks to https://github.com/facebook/hhvm/issues/2156 |
| 437 | 437 | if (defined('HHVM_VERSION')) { |
| 438 | - return false; |
|
| 438 | + return FALSE; |
|
| 439 | 439 | } |
| 440 | 440 | } |
| 441 | 441 | |
| 442 | - return true; |
|
| 442 | + return TRUE; |
|
| 443 | 443 | } |
| 444 | 444 | } |
@@ -12,7 +12,8 @@ |
||
| 12 | 12 | * @package Requests |
| 13 | 13 | * @subpackage Transport |
| 14 | 14 | */ |
| 15 | -interface Requests_Transport { |
|
| 15 | +interface Requests_Transport |
|
| 16 | +{ |
|
| 16 | 17 | /** |
| 17 | 18 | * Perform a request |
| 18 | 19 | * |
@@ -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 | |
@@ -25,8 +25,10 @@ discard block |
||
| 25 | 25 | * |
| 26 | 26 | * @param array $data Dictionary/map to convert to case-insensitive |
| 27 | 27 | */ |
| 28 | - public function __construct(array $data = array()) { |
|
| 29 | - foreach ($data as $key => $value) { |
|
| 28 | + public function __construct(array $data = array()) |
|
| 29 | + { |
|
| 30 | + foreach ($data as $key => $value) |
|
| 31 | + { |
|
| 30 | 32 | $this->offsetSet($key, $value); |
| 31 | 33 | } |
| 32 | 34 | } |
@@ -37,7 +39,8 @@ discard block |
||
| 37 | 39 | * @param string $key Item key |
| 38 | 40 | * @return boolean Does the item exist? |
| 39 | 41 | */ |
| 40 | - public function offsetExists($key) { |
|
| 42 | + public function offsetExists($key) |
|
| 43 | + { |
|
| 41 | 44 | $key = strtolower($key); |
| 42 | 45 | return isset($this->data[$key]); |
| 43 | 46 | } |
@@ -48,9 +51,11 @@ discard block |
||
| 48 | 51 | * @param string $key Item key |
| 49 | 52 | * @return string Item value |
| 50 | 53 | */ |
| 51 | - public function offsetGet($key) { |
|
| 54 | + public function offsetGet($key) |
|
| 55 | + { |
|
| 52 | 56 | $key = strtolower($key); |
| 53 | - if (!isset($this->data[$key])) { |
|
| 57 | + if (!isset($this->data[$key])) |
|
| 58 | + { |
|
| 54 | 59 | return null; |
| 55 | 60 | } |
| 56 | 61 | |
@@ -65,8 +70,10 @@ discard block |
||
| 65 | 70 | * @param string $key Item name |
| 66 | 71 | * @param string $value Item value |
| 67 | 72 | */ |
| 68 | - public function offsetSet($key, $value) { |
|
| 69 | - if ($key === null) { |
|
| 73 | + public function offsetSet($key, $value) |
|
| 74 | + { |
|
| 75 | + if ($key === null) |
|
| 76 | + { |
|
| 70 | 77 | throw new Requests_Exception('Object is a dictionary, not a list', 'invalidset'); |
| 71 | 78 | } |
| 72 | 79 | |
@@ -79,7 +86,8 @@ discard block |
||
| 79 | 86 | * |
| 80 | 87 | * @param string $key |
| 81 | 88 | */ |
| 82 | - public function offsetUnset($key) { |
|
| 89 | + public function offsetUnset($key) |
|
| 90 | + { |
|
| 83 | 91 | unset($this->data[strtolower($key)]); |
| 84 | 92 | } |
| 85 | 93 | |
@@ -88,7 +96,8 @@ discard block |
||
| 88 | 96 | * |
| 89 | 97 | * @return ArrayIterator |
| 90 | 98 | */ |
| 91 | - public function getIterator() { |
|
| 99 | + public function getIterator() |
|
| 100 | + { |
|
| 92 | 101 | return new ArrayIterator($this->data); |
| 93 | 102 | } |
| 94 | 103 | |
@@ -97,7 +106,8 @@ discard block |
||
| 97 | 106 | * |
| 98 | 107 | * @return array Header data |
| 99 | 108 | */ |
| 100 | - public function getAll() { |
|
| 109 | + public function getAll() |
|
| 110 | + { |
|
| 101 | 111 | return $this->data; |
| 102 | 112 | } |
| 103 | 113 | } |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | public function offsetGet($key) { |
| 52 | 52 | $key = strtolower($key); |
| 53 | 53 | if (!isset($this->data[$key])) { |
| 54 | - return null; |
|
| 54 | + return NULL; |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | return $this->data[$key]; |
@@ -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 | |
@@ -12,7 +12,8 @@ discard block |
||
| 12 | 12 | * @package Requests |
| 13 | 13 | * @subpackage Utilities |
| 14 | 14 | */ |
| 15 | -class Requests_Utility_FilteredIterator extends ArrayIterator { |
|
| 15 | +class Requests_Utility_FilteredIterator extends ArrayIterator |
|
| 16 | +{ |
|
| 16 | 17 | /** |
| 17 | 18 | * Callback to run as a filter |
| 18 | 19 | * |
@@ -26,7 +27,8 @@ discard block |
||
| 26 | 27 | * @param array $data |
| 27 | 28 | * @param callable $callback Callback to be called on each value |
| 28 | 29 | */ |
| 29 | - public function __construct($data, $callback) { |
|
| 30 | + public function __construct($data, $callback) |
|
| 31 | + { |
|
| 30 | 32 | parent::__construct($data); |
| 31 | 33 | |
| 32 | 34 | $this->callback = $callback; |
@@ -37,7 +39,8 @@ discard block |
||
| 37 | 39 | * |
| 38 | 40 | * @return string |
| 39 | 41 | */ |
| 40 | - public function current() { |
|
| 42 | + public function current() |
|
| 43 | + { |
|
| 41 | 44 | $value = parent::current(); |
| 42 | 45 | $value = call_user_func($this->callback, $value); |
| 43 | 46 | return $value; |
@@ -1,5 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -class Requests_Exception_Transport extends Requests_Exception { |
|
| 3 | +class Requests_Exception_Transport extends Requests_Exception |
|
| 4 | +{ |
|
| 4 | 5 | |
| 5 | 6 | } |