@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | } |
189 | 189 | |
190 | 190 | if ($this->_enable_cache && $this->getMethod() === 'GET') { |
191 | - $cache_key = urlencode($request_uri) . implode(',', $send_headers); |
|
191 | + $cache_key = urlencode($request_uri).implode(',', $send_headers); |
|
192 | 192 | if (array_key_exists($cache_key, self::$_cache)) { |
193 | 193 | return self::$_cache[$cache_key]; |
194 | 194 | } |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | curl_setopt($ch, CURLOPT_AUTOREFERER, true); |
209 | 209 | |
210 | 210 | if (!empty($send_headers)) curl_setopt($ch, CURLOPT_HTTPHEADER, $send_headers); |
211 | - if (!is_null($post_data)) { |
|
211 | + if (!is_null($post_data)) { |
|
212 | 212 | curl_setopt($ch, CURLOPT_POST, 1); |
213 | 213 | curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); |
214 | 214 | } |
@@ -39,9 +39,15 @@ discard block |
||
39 | 39 | */ |
40 | 40 | public function __construct(string $url = null, array $data = [], array $headers = []) |
41 | 41 | { |
42 | - if (!is_null($url)) $this->setURL($url); |
|
43 | - foreach ($data as $name => $value) $this->addDataParam($name, $value); |
|
44 | - foreach ($headers as $name => $value) $this->addHeader($name, $value); |
|
42 | + if (!is_null($url)) { |
|
43 | + $this->setURL($url); |
|
44 | + } |
|
45 | + foreach ($data as $name => $value) { |
|
46 | + $this->addDataParam($name, $value); |
|
47 | + } |
|
48 | + foreach ($headers as $name => $value) { |
|
49 | + $this->addHeader($name, $value); |
|
50 | + } |
|
45 | 51 | } |
46 | 52 | |
47 | 53 | /** |
@@ -98,7 +104,9 @@ discard block |
||
98 | 104 | |
99 | 105 | public function removeDataParam(string $name): Curl |
100 | 106 | { |
101 | - if (array_key_exists($name, $this->_data)) unset($this->_data[$name]); |
|
107 | + if (array_key_exists($name, $this->_data)) { |
|
108 | + unset($this->_data[$name]); |
|
109 | + } |
|
102 | 110 | return $this; |
103 | 111 | } |
104 | 112 | |
@@ -127,7 +135,9 @@ discard block |
||
127 | 135 | */ |
128 | 136 | public function removeHeader(string $name): Curl |
129 | 137 | { |
130 | - if (array_key_exists($name, $this->_headers)) unset($this->_headers[$name]); |
|
138 | + if (array_key_exists($name, $this->_headers)) { |
|
139 | + unset($this->_headers[$name]); |
|
140 | + } |
|
131 | 141 | return $this; |
132 | 142 | } |
133 | 143 | |
@@ -171,13 +181,17 @@ discard block |
||
171 | 181 | $request_uri = $this->getURL(); |
172 | 182 | |
173 | 183 | // Headers |
174 | - foreach ($this->getHeaders() as $k => $v) $send_headers[] = "{$k}: {$v}"; |
|
184 | + foreach ($this->getHeaders() as $k => $v) { |
|
185 | + $send_headers[] = "{$k}: {$v}"; |
|
186 | + } |
|
175 | 187 | |
176 | 188 | // Request Data |
177 | 189 | switch ($this->getMethod()) { |
178 | 190 | case 'GET': |
179 | 191 | case 'DELETE': |
180 | - foreach ($this->getDataParams() as $name => $value) $request_uri = URL::setGetVar($name, $value, $request_uri); |
|
192 | + foreach ($this->getDataParams() as $name => $value) { |
|
193 | + $request_uri = URL::setGetVar($name, $value, $request_uri); |
|
194 | + } |
|
181 | 195 | break; |
182 | 196 | |
183 | 197 | case 'POST': |
@@ -208,7 +222,9 @@ discard block |
||
208 | 222 | curl_setopt($ch, CURLINFO_HEADER_OUT, true); |
209 | 223 | curl_setopt($ch, CURLOPT_AUTOREFERER, true); |
210 | 224 | |
211 | - if (!empty($send_headers)) curl_setopt($ch, CURLOPT_HTTPHEADER, $send_headers); |
|
225 | + if (!empty($send_headers)) { |
|
226 | + curl_setopt($ch, CURLOPT_HTTPHEADER, $send_headers); |
|
227 | + } |
|
212 | 228 | if (!is_null($post_data)) { |
213 | 229 | curl_setopt($ch, CURLOPT_POST, 1); |
214 | 230 | curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); |
@@ -218,7 +234,9 @@ discard block |
||
218 | 234 | $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
219 | 235 | |
220 | 236 | $response = new CurlResponse($http_code, $result); |
221 | - if ($this->_enable_cache && isset($cache_key)) self::$_cache[$cache_key] = $response; |
|
237 | + if ($this->_enable_cache && isset($cache_key)) { |
|
238 | + self::$_cache[$cache_key] = $response; |
|
239 | + } |
|
222 | 240 | |
223 | 241 | return $response; |
224 | 242 | } |
@@ -21,15 +21,15 @@ discard block |
||
21 | 21 | { |
22 | 22 | if (!self::is_absolute_url($url)) { |
23 | 23 | $isRelative = true; |
24 | - $url = 'http://dummy.com/' . ltrim($url, '/'); |
|
25 | - } else { |
|
24 | + $url = 'http://dummy.com/'.ltrim($url, '/'); |
|
25 | + }else { |
|
26 | 26 | $isRelative = false; |
27 | 27 | } |
28 | 28 | |
29 | 29 | // try to parse uri |
30 | 30 | $parts = parse_url($url); |
31 | 31 | if (empty($parts)) { |
32 | - throw new InvalidArgumentException("Can't parse URL: " . $url); |
|
32 | + throw new InvalidArgumentException("Can't parse URL: ".$url); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | // Parse params and add new variable |
@@ -42,18 +42,18 @@ discard block |
||
42 | 42 | // Generate URI segments and formatting |
43 | 43 | $scheme = (array_key_exists('scheme', $parts)) ? $parts['scheme'] : 'http'; |
44 | 44 | $user = (array_key_exists('user', $parts)) ? $parts['user'] : ''; |
45 | - $port = (array_key_exists('port', $parts) && $parts['port']) ? ':' . $parts['port'] : ''; |
|
45 | + $port = (array_key_exists('port', $parts) && $parts['port']) ? ':'.$parts['port'] : ''; |
|
46 | 46 | |
47 | 47 | if ($user != '') { |
48 | 48 | // format in either user:[email protected] or [email protected] |
49 | - $user .= (array_key_exists('pass', $parts) && $parts['pass']) ? ':' . $parts['pass'] . '@' : ''; |
|
49 | + $user .= (array_key_exists('pass', $parts) && $parts['pass']) ? ':'.$parts['pass'].'@' : ''; |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | // handle URL params which are existing / new |
53 | - $params = ($params) ? '?' . http_build_query($params) : ''; |
|
53 | + $params = ($params) ? '?'.http_build_query($params) : ''; |
|
54 | 54 | |
55 | 55 | // Recompile URI segments |
56 | - $newUri = $scheme . '://' . $user . $parts['host'] . $port . $parts['path'] . $params; |
|
56 | + $newUri = $scheme.'://'.$user.$parts['host'].$port.$parts['path'].$params; |
|
57 | 57 | |
58 | 58 | if ($isRelative) { |
59 | 59 | return str_replace('http://dummy.com/', '', $newUri); |
@@ -70,10 +70,10 @@ discard block |
||
70 | 70 | { |
71 | 71 | // Strip off the query and fragment parts of the URL before checking |
72 | 72 | if (($queryPosition = strpos($url, '?')) !== false) { |
73 | - $url = substr($url, 0, $queryPosition - 1); |
|
73 | + $url = substr($url, 0, $queryPosition-1); |
|
74 | 74 | } |
75 | 75 | if (($hashPosition = strpos($url, '#')) !== false) { |
76 | - $url = substr($url, 0, $hashPosition - 1); |
|
76 | + $url = substr($url, 0, $hashPosition-1); |
|
77 | 77 | } |
78 | 78 | $colonPosition = strpos($url, ':'); |
79 | 79 | $slashPosition = strpos($url, '/'); |