@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -class Location{ |
|
3 | +class Location { |
|
4 | 4 | |
5 | 5 | public $cityName; |
6 | 6 | |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | { |
38 | 38 | $this->lng = $lng; |
39 | 39 | } |
40 | - public function toArray(){ |
|
40 | + public function toArray() { |
|
41 | 41 | return array( |
42 | 42 | "city" => $this->getCityName(), |
43 | 43 | "country" => 'DE', |
@@ -1,6 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -class Location{ |
|
3 | +class Location |
|
4 | +{ |
|
4 | 5 | |
5 | 6 | public $cityName; |
6 | 7 | |
@@ -37,7 +38,8 @@ discard block |
||
37 | 38 | { |
38 | 39 | $this->lng = $lng; |
39 | 40 | } |
40 | - public function toArray(){ |
|
41 | + public function toArray() |
|
42 | + { |
|
41 | 43 | return array( |
42 | 44 | "city" => $this->getCityName(), |
43 | 45 | "country" => 'DE', |
@@ -13,6 +13,9 @@ discard block |
||
13 | 13 | return $this->cityName; |
14 | 14 | } |
15 | 15 | |
16 | + /** |
|
17 | + * @param string $cityName |
|
18 | + */ |
|
16 | 19 | public function setCityName($cityName) |
17 | 20 | { |
18 | 21 | $this->cityName = $cityName; |
@@ -23,6 +26,9 @@ discard block |
||
23 | 26 | return $this->lat; |
24 | 27 | } |
25 | 28 | |
29 | + /** |
|
30 | + * @param double $lat |
|
31 | + */ |
|
26 | 32 | public function setLat($lat) |
27 | 33 | { |
28 | 34 | $this->lat = $lat; |
@@ -33,6 +39,9 @@ discard block |
||
33 | 39 | return $this->lng; |
34 | 40 | } |
35 | 41 | |
42 | + /** |
|
43 | + * @param double $lng |
|
44 | + */ |
|
36 | 45 | public function setLng($lng) |
37 | 46 | { |
38 | 47 | $this->lng = $lng; |
@@ -2,51 +2,51 @@ |
||
2 | 2 | |
3 | 3 | class Location{ |
4 | 4 | |
5 | - public $cityName; |
|
6 | - |
|
7 | - public $lat; |
|
8 | - |
|
9 | - public $lng; |
|
10 | - |
|
11 | - public function getCityName() |
|
12 | - { |
|
13 | - return $this->cityName; |
|
14 | - } |
|
15 | - |
|
16 | - public function setCityName($cityName) |
|
17 | - { |
|
18 | - $this->cityName = $cityName; |
|
19 | - } |
|
20 | - |
|
21 | - public function getLat() |
|
22 | - { |
|
23 | - return $this->lat; |
|
24 | - } |
|
25 | - |
|
26 | - public function setLat($lat) |
|
27 | - { |
|
28 | - $this->lat = $lat; |
|
29 | - } |
|
30 | - |
|
31 | - public function getLng() |
|
32 | - { |
|
33 | - return $this->lng; |
|
34 | - } |
|
35 | - |
|
36 | - public function setLng($lng) |
|
37 | - { |
|
38 | - $this->lng = $lng; |
|
39 | - } |
|
40 | - public function toArray(){ |
|
41 | - return array( |
|
42 | - "city" => $this->getCityName(), |
|
43 | - "country" => 'DE', |
|
44 | - "loc_accuracy" => '0.0', |
|
45 | - "loc_coordinates" => array( |
|
46 | - "lat" => $this->getLat(), |
|
47 | - "lng" => $this->getLng(), |
|
48 | - ), |
|
49 | - "name" => $this->getCityName() |
|
50 | - ); |
|
51 | - } |
|
5 | + public $cityName; |
|
6 | + |
|
7 | + public $lat; |
|
8 | + |
|
9 | + public $lng; |
|
10 | + |
|
11 | + public function getCityName() |
|
12 | + { |
|
13 | + return $this->cityName; |
|
14 | + } |
|
15 | + |
|
16 | + public function setCityName($cityName) |
|
17 | + { |
|
18 | + $this->cityName = $cityName; |
|
19 | + } |
|
20 | + |
|
21 | + public function getLat() |
|
22 | + { |
|
23 | + return $this->lat; |
|
24 | + } |
|
25 | + |
|
26 | + public function setLat($lat) |
|
27 | + { |
|
28 | + $this->lat = $lat; |
|
29 | + } |
|
30 | + |
|
31 | + public function getLng() |
|
32 | + { |
|
33 | + return $this->lng; |
|
34 | + } |
|
35 | + |
|
36 | + public function setLng($lng) |
|
37 | + { |
|
38 | + $this->lng = $lng; |
|
39 | + } |
|
40 | + public function toArray(){ |
|
41 | + return array( |
|
42 | + "city" => $this->getCityName(), |
|
43 | + "country" => 'DE', |
|
44 | + "loc_accuracy" => '0.0', |
|
45 | + "loc_coordinates" => array( |
|
46 | + "lat" => $this->getLat(), |
|
47 | + "lng" => $this->getLng(), |
|
48 | + ), |
|
49 | + "name" => $this->getCityName() |
|
50 | + ); |
|
51 | + } |
|
52 | 52 | } |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | * |
63 | 63 | * @param string $name |
64 | 64 | * @param string $value |
65 | - * @param array|Requests_Utility_CaseInsensitiveDictionary $attributes Associative array of attribute data |
|
65 | + * @param Requests_Utility_CaseInsensitiveDictionary $attributes Associative array of attribute data |
|
66 | 66 | */ |
67 | 67 | public function __construct($name, $value, $attributes = array(), $flags = array(), $reference_time = null) { |
68 | 68 | $this->name = $name; |
@@ -377,6 +377,7 @@ discard block |
||
377 | 377 | * specifies some of this handling, but not in a thorough manner. |
378 | 378 | * |
379 | 379 | * @param string Cookie header value (from a Set-Cookie header) |
380 | + * @param integer $reference_time |
|
380 | 381 | * @return Requests_Cookie Parsed cookie object |
381 | 382 | */ |
382 | 383 | public static function parse($string, $name = '', $reference_time = null) { |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | $this->flags = array_merge($default_flags, $flags); |
78 | 78 | |
79 | 79 | $this->reference_time = time(); |
80 | - if ($reference_time !== null) { |
|
80 | + if($reference_time !== null) { |
|
81 | 81 | $this->reference_time = $reference_time; |
82 | 82 | } |
83 | 83 | |
@@ -97,12 +97,12 @@ discard block |
||
97 | 97 | // If a cookie has both the Max-Age and the Expires attribute, the Max- |
98 | 98 | // Age attribute has precedence and controls the expiration date of the |
99 | 99 | // cookie. |
100 | - if (isset($this->attributes['max-age'])) { |
|
100 | + if(isset($this->attributes['max-age'])) { |
|
101 | 101 | $max_age = $this->attributes['max-age']; |
102 | 102 | return $max_age < $this->reference_time; |
103 | 103 | } |
104 | 104 | |
105 | - if (isset($this->attributes['expires'])) { |
|
105 | + if(isset($this->attributes['expires'])) { |
|
106 | 106 | $expires = $this->attributes['expires']; |
107 | 107 | return $expires < $this->reference_time; |
108 | 108 | } |
@@ -117,11 +117,11 @@ discard block |
||
117 | 117 | * @return boolean Whether the cookie is valid for the given URI |
118 | 118 | */ |
119 | 119 | public function uri_matches(Requests_IRI $uri) { |
120 | - if (!$this->domain_matches($uri->host)) { |
|
120 | + if(!$this->domain_matches($uri->host)) { |
|
121 | 121 | return false; |
122 | 122 | } |
123 | 123 | |
124 | - if (!$this->path_matches($uri->path)) { |
|
124 | + if(!$this->path_matches($uri->path)) { |
|
125 | 125 | return false; |
126 | 126 | } |
127 | 127 | |
@@ -135,37 +135,37 @@ discard block |
||
135 | 135 | * @return boolean Whether the cookie is valid for the given domain |
136 | 136 | */ |
137 | 137 | public function domain_matches($string) { |
138 | - if (!isset($this->attributes['domain'])) { |
|
138 | + if(!isset($this->attributes['domain'])) { |
|
139 | 139 | // Cookies created manually; cookies created by Requests will set |
140 | 140 | // the domain to the requested domain |
141 | 141 | return true; |
142 | 142 | } |
143 | 143 | |
144 | 144 | $domain_string = $this->attributes['domain']; |
145 | - if ($domain_string === $string) { |
|
145 | + if($domain_string === $string) { |
|
146 | 146 | // The domain string and the string are identical. |
147 | 147 | return true; |
148 | 148 | } |
149 | 149 | |
150 | 150 | // If the cookie is marked as host-only and we don't have an exact |
151 | 151 | // match, reject the cookie |
152 | - if ($this->flags['host-only'] === true) { |
|
152 | + if($this->flags['host-only'] === true) { |
|
153 | 153 | return false; |
154 | 154 | } |
155 | 155 | |
156 | - if (strlen($string) <= strlen($domain_string)) { |
|
156 | + if(strlen($string) <= strlen($domain_string)) { |
|
157 | 157 | // For obvious reasons, the string cannot be a suffix if the domain |
158 | 158 | // is shorter than the domain string |
159 | 159 | return false; |
160 | 160 | } |
161 | 161 | |
162 | - if (substr($string, -1 * strlen($domain_string)) !== $domain_string) { |
|
162 | + if(substr($string, -1 * strlen($domain_string)) !== $domain_string) { |
|
163 | 163 | // The domain string should be a suffix of the string. |
164 | 164 | return false; |
165 | 165 | } |
166 | 166 | |
167 | 167 | $prefix = substr($string, 0, strlen($string) - strlen($domain_string)); |
168 | - if (substr($prefix, -1) !== '.') { |
|
168 | + if(substr($prefix, -1) !== '.') { |
|
169 | 169 | // The last character of the string that is not included in the |
170 | 170 | // domain string should be a %x2E (".") character. |
171 | 171 | return false; |
@@ -184,12 +184,12 @@ discard block |
||
184 | 184 | * @return boolean Whether the cookie is valid for the given path |
185 | 185 | */ |
186 | 186 | public function path_matches($request_path) { |
187 | - if (empty($request_path)) { |
|
187 | + if(empty($request_path)) { |
|
188 | 188 | // Normalize empty path to root |
189 | 189 | $request_path = '/'; |
190 | 190 | } |
191 | 191 | |
192 | - if (!isset($this->attributes['path'])) { |
|
192 | + if(!isset($this->attributes['path'])) { |
|
193 | 193 | // Cookies created manually; cookies created by Requests will set |
194 | 194 | // the path to the requested path |
195 | 195 | return true; |
@@ -197,19 +197,19 @@ discard block |
||
197 | 197 | |
198 | 198 | $cookie_path = $this->attributes['path']; |
199 | 199 | |
200 | - if ($cookie_path === $request_path) { |
|
200 | + if($cookie_path === $request_path) { |
|
201 | 201 | // The cookie-path and the request-path are identical. |
202 | 202 | return true; |
203 | 203 | } |
204 | 204 | |
205 | - if (strlen($request_path) > strlen($cookie_path) && substr($request_path, 0, strlen($cookie_path)) === $cookie_path) { |
|
206 | - if (substr($cookie_path, -1) === '/') { |
|
205 | + if(strlen($request_path) > strlen($cookie_path) && substr($request_path, 0, strlen($cookie_path)) === $cookie_path) { |
|
206 | + if(substr($cookie_path, -1) === '/') { |
|
207 | 207 | // The cookie-path is a prefix of the request-path, and the last |
208 | 208 | // character of the cookie-path is %x2F ("/"). |
209 | 209 | return true; |
210 | 210 | } |
211 | 211 | |
212 | - if (substr($request_path, strlen($cookie_path), 1) === '/') { |
|
212 | + if(substr($request_path, strlen($cookie_path), 1) === '/') { |
|
213 | 213 | // The cookie-path is a prefix of the request-path, and the |
214 | 214 | // first character of the request-path that is not included in |
215 | 215 | // the cookie-path is a %x2F ("/") character. |
@@ -226,15 +226,15 @@ discard block |
||
226 | 226 | * @return boolean Whether the cookie was successfully normalized |
227 | 227 | */ |
228 | 228 | public function normalize() { |
229 | - foreach ($this->attributes as $key => $value) { |
|
229 | + foreach($this->attributes as $key => $value) { |
|
230 | 230 | $orig_value = $value; |
231 | 231 | $value = $this->normalize_attribute($key, $value); |
232 | - if ($value === null) { |
|
232 | + if($value === null) { |
|
233 | 233 | unset($this->attributes[$key]); |
234 | 234 | continue; |
235 | 235 | } |
236 | 236 | |
237 | - if ($value !== $orig_value) { |
|
237 | + if($value !== $orig_value) { |
|
238 | 238 | $this->attributes[$key] = $value; |
239 | 239 | } |
240 | 240 | } |
@@ -252,15 +252,15 @@ discard block |
||
252 | 252 | * @return mixed Value if available, or null if the attribute value is invalid (and should be skipped) |
253 | 253 | */ |
254 | 254 | protected function normalize_attribute($name, $value) { |
255 | - switch (strtolower($name)) { |
|
255 | + switch(strtolower($name)) { |
|
256 | 256 | case 'expires': |
257 | 257 | // Expiration parsing, as per RFC 6265 section 5.2.1 |
258 | - if (is_int($value)) { |
|
258 | + if(is_int($value)) { |
|
259 | 259 | return $value; |
260 | 260 | } |
261 | 261 | |
262 | 262 | $expiry_time = strtotime($value); |
263 | - if ($expiry_time === false) { |
|
263 | + if($expiry_time === false) { |
|
264 | 264 | return null; |
265 | 265 | } |
266 | 266 | |
@@ -268,17 +268,17 @@ discard block |
||
268 | 268 | |
269 | 269 | case 'max-age': |
270 | 270 | // Expiration parsing, as per RFC 6265 section 5.2.2 |
271 | - if (is_int($value)) { |
|
271 | + if(is_int($value)) { |
|
272 | 272 | return $value; |
273 | 273 | } |
274 | 274 | |
275 | 275 | // Check that we have a valid age |
276 | - if (!preg_match('/^-?\d+$/', $value)) { |
|
276 | + if(!preg_match('/^-?\d+$/', $value)) { |
|
277 | 277 | return null; |
278 | 278 | } |
279 | 279 | |
280 | - $delta_seconds = (int) $value; |
|
281 | - if ($delta_seconds <= 0) { |
|
280 | + $delta_seconds = (int)$value; |
|
281 | + if($delta_seconds <= 0) { |
|
282 | 282 | $expiry_time = 0; |
283 | 283 | } |
284 | 284 | else { |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | |
290 | 290 | case 'domain': |
291 | 291 | // Domain normalization, as per RFC 6265 section 5.2.3 |
292 | - if ($value[0] === '.') { |
|
292 | + if($value[0] === '.') { |
|
293 | 293 | $value = substr($value, 1); |
294 | 294 | } |
295 | 295 | |
@@ -332,11 +332,11 @@ discard block |
||
332 | 332 | */ |
333 | 333 | public function format_for_set_cookie() { |
334 | 334 | $header_value = $this->format_for_header(); |
335 | - if (!empty($this->attributes)) { |
|
335 | + if(!empty($this->attributes)) { |
|
336 | 336 | $parts = array(); |
337 | - foreach ($this->attributes as $key => $value) { |
|
337 | + foreach($this->attributes as $key => $value) { |
|
338 | 338 | // Ignore non-associative attributes |
339 | - if (is_numeric($key)) { |
|
339 | + if(is_numeric($key)) { |
|
340 | 340 | $parts[] = $value; |
341 | 341 | } |
342 | 342 | else { |
@@ -383,10 +383,10 @@ discard block |
||
383 | 383 | $parts = explode(';', $string); |
384 | 384 | $kvparts = array_shift($parts); |
385 | 385 | |
386 | - if (!empty($name)) { |
|
386 | + if(!empty($name)) { |
|
387 | 387 | $value = $string; |
388 | 388 | } |
389 | - elseif (strpos($kvparts, '=') === false) { |
|
389 | + elseif(strpos($kvparts, '=') === false) { |
|
390 | 390 | // Some sites might only have a value without the equals separator. |
391 | 391 | // Deviate from RFC 6265 and pretend it was actually a blank name |
392 | 392 | // (`=foo`) |
@@ -404,9 +404,9 @@ discard block |
||
404 | 404 | // Attribute key are handled case-insensitively |
405 | 405 | $attributes = new Requests_Utility_CaseInsensitiveDictionary(); |
406 | 406 | |
407 | - if (!empty($parts)) { |
|
408 | - foreach ($parts as $part) { |
|
409 | - if (strpos($part, '=') === false) { |
|
407 | + if(!empty($parts)) { |
|
408 | + foreach($parts as $part) { |
|
409 | + if(strpos($part, '=') === false) { |
|
410 | 410 | $part_key = $part; |
411 | 411 | $part_value = true; |
412 | 412 | } |
@@ -433,16 +433,16 @@ discard block |
||
433 | 433 | */ |
434 | 434 | public static function parse_from_headers(Requests_Response_Headers $headers, Requests_IRI $origin = null, $time = null) { |
435 | 435 | $cookie_headers = $headers->getValues('Set-Cookie'); |
436 | - if (empty($cookie_headers)) { |
|
436 | + if(empty($cookie_headers)) { |
|
437 | 437 | return array(); |
438 | 438 | } |
439 | 439 | |
440 | 440 | $cookies = array(); |
441 | - foreach ($cookie_headers as $header) { |
|
441 | + foreach($cookie_headers as $header) { |
|
442 | 442 | $parsed = self::parse($header, '', $time); |
443 | 443 | |
444 | 444 | // Default domain/path attributes |
445 | - if (empty($parsed->attributes['domain']) && !empty($origin)) { |
|
445 | + if(empty($parsed->attributes['domain']) && !empty($origin)) { |
|
446 | 446 | $parsed->attributes['domain'] = $origin->host; |
447 | 447 | $parsed->flags['host-only'] = true; |
448 | 448 | } |
@@ -451,17 +451,17 @@ discard block |
||
451 | 451 | } |
452 | 452 | |
453 | 453 | $path_is_valid = (!empty($parsed->attributes['path']) && $parsed->attributes['path'][0] === '/'); |
454 | - if (!$path_is_valid && !empty($origin)) { |
|
454 | + if(!$path_is_valid && !empty($origin)) { |
|
455 | 455 | $path = $origin->path; |
456 | 456 | |
457 | 457 | // Default path normalization as per RFC 6265 section 5.1.4 |
458 | - if (substr($path, 0, 1) !== '/') { |
|
458 | + if(substr($path, 0, 1) !== '/') { |
|
459 | 459 | // If the uri-path is empty or if the first character of |
460 | 460 | // the uri-path is not a %x2F ("/") character, output |
461 | 461 | // %x2F ("/") and skip the remaining steps. |
462 | 462 | $path = '/'; |
463 | 463 | } |
464 | - elseif (substr_count($path, '/') === 1) { |
|
464 | + elseif(substr_count($path, '/') === 1) { |
|
465 | 465 | // If the uri-path contains no more than one %x2F ("/") |
466 | 466 | // character, output %x2F ("/") and skip the remaining |
467 | 467 | // step. |
@@ -477,7 +477,7 @@ discard block |
||
477 | 477 | } |
478 | 478 | |
479 | 479 | // Reject invalid cookie domains |
480 | - if (!empty($origin) && !$parsed->domain_matches($origin->host)) { |
|
480 | + if(!empty($origin) && !$parsed->domain_matches($origin->host)) { |
|
481 | 481 | continue; |
482 | 482 | } |
483 | 483 |
@@ -12,7 +12,8 @@ discard block |
||
12 | 12 | * @package Requests |
13 | 13 | * @subpackage Cookies |
14 | 14 | */ |
15 | -class Requests_Cookie { |
|
15 | +class Requests_Cookie |
|
16 | +{ |
|
16 | 17 | /** |
17 | 18 | * Cookie name. |
18 | 19 | * |
@@ -64,7 +65,8 @@ discard block |
||
64 | 65 | * @param string $value |
65 | 66 | * @param array|Requests_Utility_CaseInsensitiveDictionary $attributes Associative array of attribute data |
66 | 67 | */ |
67 | - public function __construct($name, $value, $attributes = array(), $flags = array(), $reference_time = null) { |
|
68 | + public function __construct($name, $value, $attributes = array(), $flags = array(), $reference_time = null) |
|
69 | + { |
|
68 | 70 | $this->name = $name; |
69 | 71 | $this->value = $value; |
70 | 72 | $this->attributes = $attributes; |
@@ -77,7 +79,8 @@ discard block |
||
77 | 79 | $this->flags = array_merge($default_flags, $flags); |
78 | 80 | |
79 | 81 | $this->reference_time = time(); |
80 | - if ($reference_time !== null) { |
|
82 | + if ($reference_time !== null) |
|
83 | + { |
|
81 | 84 | $this->reference_time = $reference_time; |
82 | 85 | } |
83 | 86 | |
@@ -92,17 +95,20 @@ discard block |
||
92 | 95 | * |
93 | 96 | * @return boolean True if expired, false if time is valid. |
94 | 97 | */ |
95 | - public function is_expired() { |
|
98 | + public function is_expired() |
|
99 | + { |
|
96 | 100 | // RFC6265, s. 4.1.2.2: |
97 | 101 | // If a cookie has both the Max-Age and the Expires attribute, the Max- |
98 | 102 | // Age attribute has precedence and controls the expiration date of the |
99 | 103 | // cookie. |
100 | - if (isset($this->attributes['max-age'])) { |
|
104 | + if (isset($this->attributes['max-age'])) |
|
105 | + { |
|
101 | 106 | $max_age = $this->attributes['max-age']; |
102 | 107 | return $max_age < $this->reference_time; |
103 | 108 | } |
104 | 109 | |
105 | - if (isset($this->attributes['expires'])) { |
|
110 | + if (isset($this->attributes['expires'])) |
|
111 | + { |
|
106 | 112 | $expires = $this->attributes['expires']; |
107 | 113 | return $expires < $this->reference_time; |
108 | 114 | } |
@@ -116,12 +122,15 @@ discard block |
||
116 | 122 | * @param Requests_IRI $uri URI to check |
117 | 123 | * @return boolean Whether the cookie is valid for the given URI |
118 | 124 | */ |
119 | - public function uri_matches(Requests_IRI $uri) { |
|
120 | - if (!$this->domain_matches($uri->host)) { |
|
125 | + public function uri_matches(Requests_IRI $uri) |
|
126 | + { |
|
127 | + if (!$this->domain_matches($uri->host)) |
|
128 | + { |
|
121 | 129 | return false; |
122 | 130 | } |
123 | 131 | |
124 | - if (!$this->path_matches($uri->path)) { |
|
132 | + if (!$this->path_matches($uri->path)) |
|
133 | + { |
|
125 | 134 | return false; |
126 | 135 | } |
127 | 136 | |
@@ -134,38 +143,45 @@ discard block |
||
134 | 143 | * @param string $string Domain to check |
135 | 144 | * @return boolean Whether the cookie is valid for the given domain |
136 | 145 | */ |
137 | - public function domain_matches($string) { |
|
138 | - if (!isset($this->attributes['domain'])) { |
|
146 | + public function domain_matches($string) |
|
147 | + { |
|
148 | + if (!isset($this->attributes['domain'])) |
|
149 | + { |
|
139 | 150 | // Cookies created manually; cookies created by Requests will set |
140 | 151 | // the domain to the requested domain |
141 | 152 | return true; |
142 | 153 | } |
143 | 154 | |
144 | 155 | $domain_string = $this->attributes['domain']; |
145 | - if ($domain_string === $string) { |
|
156 | + if ($domain_string === $string) |
|
157 | + { |
|
146 | 158 | // The domain string and the string are identical. |
147 | 159 | return true; |
148 | 160 | } |
149 | 161 | |
150 | 162 | // If the cookie is marked as host-only and we don't have an exact |
151 | 163 | // match, reject the cookie |
152 | - if ($this->flags['host-only'] === true) { |
|
164 | + if ($this->flags['host-only'] === true) |
|
165 | + { |
|
153 | 166 | return false; |
154 | 167 | } |
155 | 168 | |
156 | - if (strlen($string) <= strlen($domain_string)) { |
|
169 | + if (strlen($string) <= strlen($domain_string)) |
|
170 | + { |
|
157 | 171 | // For obvious reasons, the string cannot be a suffix if the domain |
158 | 172 | // is shorter than the domain string |
159 | 173 | return false; |
160 | 174 | } |
161 | 175 | |
162 | - if (substr($string, -1 * strlen($domain_string)) !== $domain_string) { |
|
176 | + if (substr($string, -1 * strlen($domain_string)) !== $domain_string) |
|
177 | + { |
|
163 | 178 | // The domain string should be a suffix of the string. |
164 | 179 | return false; |
165 | 180 | } |
166 | 181 | |
167 | 182 | $prefix = substr($string, 0, strlen($string) - strlen($domain_string)); |
168 | - if (substr($prefix, -1) !== '.') { |
|
183 | + if (substr($prefix, -1) !== '.') |
|
184 | + { |
|
169 | 185 | // The last character of the string that is not included in the |
170 | 186 | // domain string should be a %x2E (".") character. |
171 | 187 | return false; |
@@ -183,13 +199,16 @@ discard block |
||
183 | 199 | * @param string $request_path Path to check |
184 | 200 | * @return boolean Whether the cookie is valid for the given path |
185 | 201 | */ |
186 | - public function path_matches($request_path) { |
|
187 | - if (empty($request_path)) { |
|
202 | + public function path_matches($request_path) |
|
203 | + { |
|
204 | + if (empty($request_path)) |
|
205 | + { |
|
188 | 206 | // Normalize empty path to root |
189 | 207 | $request_path = '/'; |
190 | 208 | } |
191 | 209 | |
192 | - if (!isset($this->attributes['path'])) { |
|
210 | + if (!isset($this->attributes['path'])) |
|
211 | + { |
|
193 | 212 | // Cookies created manually; cookies created by Requests will set |
194 | 213 | // the path to the requested path |
195 | 214 | return true; |
@@ -197,19 +216,23 @@ discard block |
||
197 | 216 | |
198 | 217 | $cookie_path = $this->attributes['path']; |
199 | 218 | |
200 | - if ($cookie_path === $request_path) { |
|
219 | + if ($cookie_path === $request_path) |
|
220 | + { |
|
201 | 221 | // The cookie-path and the request-path are identical. |
202 | 222 | return true; |
203 | 223 | } |
204 | 224 | |
205 | - if (strlen($request_path) > strlen($cookie_path) && substr($request_path, 0, strlen($cookie_path)) === $cookie_path) { |
|
206 | - if (substr($cookie_path, -1) === '/') { |
|
225 | + if (strlen($request_path) > strlen($cookie_path) && substr($request_path, 0, strlen($cookie_path)) === $cookie_path) |
|
226 | + { |
|
227 | + if (substr($cookie_path, -1) === '/') |
|
228 | + { |
|
207 | 229 | // The cookie-path is a prefix of the request-path, and the last |
208 | 230 | // character of the cookie-path is %x2F ("/"). |
209 | 231 | return true; |
210 | 232 | } |
211 | 233 | |
212 | - if (substr($request_path, strlen($cookie_path), 1) === '/') { |
|
234 | + if (substr($request_path, strlen($cookie_path), 1) === '/') |
|
235 | + { |
|
213 | 236 | // The cookie-path is a prefix of the request-path, and the |
214 | 237 | // first character of the request-path that is not included in |
215 | 238 | // the cookie-path is a %x2F ("/") character. |
@@ -225,16 +248,20 @@ discard block |
||
225 | 248 | * |
226 | 249 | * @return boolean Whether the cookie was successfully normalized |
227 | 250 | */ |
228 | - public function normalize() { |
|
229 | - foreach ($this->attributes as $key => $value) { |
|
251 | + public function normalize() |
|
252 | + { |
|
253 | + foreach ($this->attributes as $key => $value) |
|
254 | + { |
|
230 | 255 | $orig_value = $value; |
231 | 256 | $value = $this->normalize_attribute($key, $value); |
232 | - if ($value === null) { |
|
257 | + if ($value === null) |
|
258 | + { |
|
233 | 259 | unset($this->attributes[$key]); |
234 | 260 | continue; |
235 | 261 | } |
236 | 262 | |
237 | - if ($value !== $orig_value) { |
|
263 | + if ($value !== $orig_value) |
|
264 | + { |
|
238 | 265 | $this->attributes[$key] = $value; |
239 | 266 | } |
240 | 267 | } |
@@ -251,16 +278,20 @@ discard block |
||
251 | 278 | * @param string|boolean $value Attribute value (string value, or true if empty/flag) |
252 | 279 | * @return mixed Value if available, or null if the attribute value is invalid (and should be skipped) |
253 | 280 | */ |
254 | - protected function normalize_attribute($name, $value) { |
|
255 | - switch (strtolower($name)) { |
|
281 | + protected function normalize_attribute($name, $value) |
|
282 | + { |
|
283 | + switch (strtolower($name)) |
|
284 | + { |
|
256 | 285 | case 'expires': |
257 | 286 | // Expiration parsing, as per RFC 6265 section 5.2.1 |
258 | - if (is_int($value)) { |
|
287 | + if (is_int($value)) |
|
288 | + { |
|
259 | 289 | return $value; |
260 | 290 | } |
261 | 291 | |
262 | 292 | $expiry_time = strtotime($value); |
263 | - if ($expiry_time === false) { |
|
293 | + if ($expiry_time === false) |
|
294 | + { |
|
264 | 295 | return null; |
265 | 296 | } |
266 | 297 | |
@@ -268,20 +299,24 @@ discard block |
||
268 | 299 | |
269 | 300 | case 'max-age': |
270 | 301 | // Expiration parsing, as per RFC 6265 section 5.2.2 |
271 | - if (is_int($value)) { |
|
302 | + if (is_int($value)) |
|
303 | + { |
|
272 | 304 | return $value; |
273 | 305 | } |
274 | 306 | |
275 | 307 | // Check that we have a valid age |
276 | - if (!preg_match('/^-?\d+$/', $value)) { |
|
308 | + if (!preg_match('/^-?\d+$/', $value)) |
|
309 | + { |
|
277 | 310 | return null; |
278 | 311 | } |
279 | 312 | |
280 | 313 | $delta_seconds = (int) $value; |
281 | - if ($delta_seconds <= 0) { |
|
314 | + if ($delta_seconds <= 0) |
|
315 | + { |
|
282 | 316 | $expiry_time = 0; |
283 | 317 | } |
284 | - else { |
|
318 | + else |
|
319 | + { |
|
285 | 320 | $expiry_time = $this->reference_time + $delta_seconds; |
286 | 321 | } |
287 | 322 | |
@@ -289,7 +324,8 @@ discard block |
||
289 | 324 | |
290 | 325 | case 'domain': |
291 | 326 | // Domain normalization, as per RFC 6265 section 5.2.3 |
292 | - if ($value[0] === '.') { |
|
327 | + if ($value[0] === '.') |
|
328 | + { |
|
293 | 329 | $value = substr($value, 1); |
294 | 330 | } |
295 | 331 | |
@@ -307,7 +343,8 @@ discard block |
||
307 | 343 | * |
308 | 344 | * @return string Cookie formatted for Cookie header |
309 | 345 | */ |
310 | - public function format_for_header() { |
|
346 | + public function format_for_header() |
|
347 | + { |
|
311 | 348 | return sprintf('%s=%s', $this->name, $this->value); |
312 | 349 | } |
313 | 350 | |
@@ -318,7 +355,8 @@ discard block |
||
318 | 355 | * @deprecated Use {@see Requests_Cookie::format_for_header} |
319 | 356 | * @return string |
320 | 357 | */ |
321 | - public function formatForHeader() { |
|
358 | + public function formatForHeader() |
|
359 | + { |
|
322 | 360 | return $this->format_for_header(); |
323 | 361 | } |
324 | 362 | |
@@ -330,16 +368,21 @@ discard block |
||
330 | 368 | * |
331 | 369 | * @return string Cookie formatted for Set-Cookie header |
332 | 370 | */ |
333 | - public function format_for_set_cookie() { |
|
371 | + public function format_for_set_cookie() |
|
372 | + { |
|
334 | 373 | $header_value = $this->format_for_header(); |
335 | - if (!empty($this->attributes)) { |
|
374 | + if (!empty($this->attributes)) |
|
375 | + { |
|
336 | 376 | $parts = array(); |
337 | - foreach ($this->attributes as $key => $value) { |
|
377 | + foreach ($this->attributes as $key => $value) |
|
378 | + { |
|
338 | 379 | // Ignore non-associative attributes |
339 | - if (is_numeric($key)) { |
|
380 | + if (is_numeric($key)) |
|
381 | + { |
|
340 | 382 | $parts[] = $value; |
341 | 383 | } |
342 | - else { |
|
384 | + else |
|
385 | + { |
|
343 | 386 | $parts[] = sprintf('%s=%s', $key, $value); |
344 | 387 | } |
345 | 388 | } |
@@ -356,7 +399,8 @@ discard block |
||
356 | 399 | * @deprecated Use {@see Requests_Cookie::format_for_set_cookie} |
357 | 400 | * @return string |
358 | 401 | */ |
359 | - public function formatForSetCookie() { |
|
402 | + public function formatForSetCookie() |
|
403 | + { |
|
360 | 404 | return $this->format_for_set_cookie(); |
361 | 405 | } |
362 | 406 | |
@@ -365,7 +409,8 @@ discard block |
||
365 | 409 | * |
366 | 410 | * Attributes and other data can be accessed via methods. |
367 | 411 | */ |
368 | - public function __toString() { |
|
412 | + public function __toString() |
|
413 | + { |
|
369 | 414 | return $this->value; |
370 | 415 | } |
371 | 416 | |
@@ -379,14 +424,17 @@ discard block |
||
379 | 424 | * @param string Cookie header value (from a Set-Cookie header) |
380 | 425 | * @return Requests_Cookie Parsed cookie object |
381 | 426 | */ |
382 | - public static function parse($string, $name = '', $reference_time = null) { |
|
427 | + public static function parse($string, $name = '', $reference_time = null) |
|
428 | + { |
|
383 | 429 | $parts = explode(';', $string); |
384 | 430 | $kvparts = array_shift($parts); |
385 | 431 | |
386 | - if (!empty($name)) { |
|
432 | + if (!empty($name)) |
|
433 | + { |
|
387 | 434 | $value = $string; |
388 | 435 | } |
389 | - elseif (strpos($kvparts, '=') === false) { |
|
436 | + elseif (strpos($kvparts, '=') === false) |
|
437 | + { |
|
390 | 438 | // Some sites might only have a value without the equals separator. |
391 | 439 | // Deviate from RFC 6265 and pretend it was actually a blank name |
392 | 440 | // (`=foo`) |
@@ -395,7 +443,8 @@ discard block |
||
395 | 443 | $name = ''; |
396 | 444 | $value = $kvparts; |
397 | 445 | } |
398 | - else { |
|
446 | + else |
|
447 | + { |
|
399 | 448 | list($name, $value) = explode('=', $kvparts, 2); |
400 | 449 | } |
401 | 450 | $name = trim($name); |
@@ -404,13 +453,17 @@ discard block |
||
404 | 453 | // Attribute key are handled case-insensitively |
405 | 454 | $attributes = new Requests_Utility_CaseInsensitiveDictionary(); |
406 | 455 | |
407 | - if (!empty($parts)) { |
|
408 | - foreach ($parts as $part) { |
|
409 | - if (strpos($part, '=') === false) { |
|
456 | + if (!empty($parts)) |
|
457 | + { |
|
458 | + foreach ($parts as $part) |
|
459 | + { |
|
460 | + if (strpos($part, '=') === false) |
|
461 | + { |
|
410 | 462 | $part_key = $part; |
411 | 463 | $part_value = true; |
412 | 464 | } |
413 | - else { |
|
465 | + else |
|
466 | + { |
|
414 | 467 | list($part_key, $part_value) = explode('=', $part, 2); |
415 | 468 | $part_value = trim($part_value); |
416 | 469 | } |
@@ -431,43 +484,52 @@ discard block |
||
431 | 484 | * @param int|null $time Reference time for expiration calculation |
432 | 485 | * @return array |
433 | 486 | */ |
434 | - public static function parse_from_headers(Requests_Response_Headers $headers, Requests_IRI $origin = null, $time = null) { |
|
487 | + public static function parse_from_headers(Requests_Response_Headers $headers, Requests_IRI $origin = null, $time = null) |
|
488 | + { |
|
435 | 489 | $cookie_headers = $headers->getValues('Set-Cookie'); |
436 | - if (empty($cookie_headers)) { |
|
490 | + if (empty($cookie_headers)) |
|
491 | + { |
|
437 | 492 | return array(); |
438 | 493 | } |
439 | 494 | |
440 | 495 | $cookies = array(); |
441 | - foreach ($cookie_headers as $header) { |
|
496 | + foreach ($cookie_headers as $header) |
|
497 | + { |
|
442 | 498 | $parsed = self::parse($header, '', $time); |
443 | 499 | |
444 | 500 | // Default domain/path attributes |
445 | - if (empty($parsed->attributes['domain']) && !empty($origin)) { |
|
501 | + if (empty($parsed->attributes['domain']) && !empty($origin)) |
|
502 | + { |
|
446 | 503 | $parsed->attributes['domain'] = $origin->host; |
447 | 504 | $parsed->flags['host-only'] = true; |
448 | 505 | } |
449 | - else { |
|
506 | + else |
|
507 | + { |
|
450 | 508 | $parsed->flags['host-only'] = false; |
451 | 509 | } |
452 | 510 | |
453 | 511 | $path_is_valid = (!empty($parsed->attributes['path']) && $parsed->attributes['path'][0] === '/'); |
454 | - if (!$path_is_valid && !empty($origin)) { |
|
512 | + if (!$path_is_valid && !empty($origin)) |
|
513 | + { |
|
455 | 514 | $path = $origin->path; |
456 | 515 | |
457 | 516 | // Default path normalization as per RFC 6265 section 5.1.4 |
458 | - if (substr($path, 0, 1) !== '/') { |
|
517 | + if (substr($path, 0, 1) !== '/') |
|
518 | + { |
|
459 | 519 | // If the uri-path is empty or if the first character of |
460 | 520 | // the uri-path is not a %x2F ("/") character, output |
461 | 521 | // %x2F ("/") and skip the remaining steps. |
462 | 522 | $path = '/'; |
463 | 523 | } |
464 | - elseif (substr_count($path, '/') === 1) { |
|
524 | + elseif (substr_count($path, '/') === 1) |
|
525 | + { |
|
465 | 526 | // If the uri-path contains no more than one %x2F ("/") |
466 | 527 | // character, output %x2F ("/") and skip the remaining |
467 | 528 | // step. |
468 | 529 | $path = '/'; |
469 | 530 | } |
470 | - else { |
|
531 | + else |
|
532 | + { |
|
471 | 533 | // Output the characters of the uri-path from the first |
472 | 534 | // character up to, but not including, the right-most |
473 | 535 | // %x2F ("/"). |
@@ -477,7 +539,8 @@ discard block |
||
477 | 539 | } |
478 | 540 | |
479 | 541 | // Reject invalid cookie domains |
480 | - if (!empty($origin) && !$parsed->domain_matches($origin->host)) { |
|
542 | + if (!empty($origin) && !$parsed->domain_matches($origin->host)) |
|
543 | + { |
|
481 | 544 | continue; |
482 | 545 | } |
483 | 546 | |
@@ -494,7 +557,8 @@ discard block |
||
494 | 557 | * @deprecated Use {@see Requests_Cookie::parse_from_headers} |
495 | 558 | * @return string |
496 | 559 | */ |
497 | - public static function parseFromHeaders(Requests_Response_Headers $headers) { |
|
560 | + public static function parseFromHeaders(Requests_Response_Headers $headers) |
|
561 | + { |
|
498 | 562 | return self::parse_from_headers($headers); |
499 | 563 | } |
500 | 564 | } |
@@ -64,20 +64,20 @@ discard block |
||
64 | 64 | * @param string $value |
65 | 65 | * @param array|Requests_Utility_CaseInsensitiveDictionary $attributes Associative array of attribute data |
66 | 66 | */ |
67 | - public function __construct($name, $value, $attributes = array(), $flags = array(), $reference_time = null) { |
|
67 | + public function __construct($name, $value, $attributes = array(), $flags = array(), $reference_time = NULL) { |
|
68 | 68 | $this->name = $name; |
69 | 69 | $this->value = $value; |
70 | 70 | $this->attributes = $attributes; |
71 | 71 | $default_flags = array( |
72 | 72 | 'creation' => time(), |
73 | 73 | 'last-access' => time(), |
74 | - 'persistent' => false, |
|
75 | - 'host-only' => true, |
|
74 | + 'persistent' => FALSE, |
|
75 | + 'host-only' => TRUE, |
|
76 | 76 | ); |
77 | 77 | $this->flags = array_merge($default_flags, $flags); |
78 | 78 | |
79 | 79 | $this->reference_time = time(); |
80 | - if ($reference_time !== null) { |
|
80 | + if ($reference_time !== NULL) { |
|
81 | 81 | $this->reference_time = $reference_time; |
82 | 82 | } |
83 | 83 | |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | return $expires < $this->reference_time; |
108 | 108 | } |
109 | 109 | |
110 | - return false; |
|
110 | + return FALSE; |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -118,11 +118,11 @@ discard block |
||
118 | 118 | */ |
119 | 119 | public function uri_matches(Requests_IRI $uri) { |
120 | 120 | if (!$this->domain_matches($uri->host)) { |
121 | - return false; |
|
121 | + return FALSE; |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | if (!$this->path_matches($uri->path)) { |
125 | - return false; |
|
125 | + return FALSE; |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | return empty($this->attributes['secure']) || $uri->scheme === 'https'; |
@@ -138,37 +138,37 @@ discard block |
||
138 | 138 | if (!isset($this->attributes['domain'])) { |
139 | 139 | // Cookies created manually; cookies created by Requests will set |
140 | 140 | // the domain to the requested domain |
141 | - return true; |
|
141 | + return TRUE; |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | $domain_string = $this->attributes['domain']; |
145 | 145 | if ($domain_string === $string) { |
146 | 146 | // The domain string and the string are identical. |
147 | - return true; |
|
147 | + return TRUE; |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | // If the cookie is marked as host-only and we don't have an exact |
151 | 151 | // match, reject the cookie |
152 | - if ($this->flags['host-only'] === true) { |
|
153 | - return false; |
|
152 | + if ($this->flags['host-only'] === TRUE) { |
|
153 | + return FALSE; |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | if (strlen($string) <= strlen($domain_string)) { |
157 | 157 | // For obvious reasons, the string cannot be a suffix if the domain |
158 | 158 | // is shorter than the domain string |
159 | - return false; |
|
159 | + return FALSE; |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | if (substr($string, -1 * strlen($domain_string)) !== $domain_string) { |
163 | 163 | // The domain string should be a suffix of the string. |
164 | - return false; |
|
164 | + return FALSE; |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | $prefix = substr($string, 0, strlen($string) - strlen($domain_string)); |
168 | 168 | if (substr($prefix, -1) !== '.') { |
169 | 169 | // The last character of the string that is not included in the |
170 | 170 | // domain string should be a %x2E (".") character. |
171 | - return false; |
|
171 | + return FALSE; |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | // The string should be a host name (i.e., not an IP address). |
@@ -192,32 +192,32 @@ discard block |
||
192 | 192 | if (!isset($this->attributes['path'])) { |
193 | 193 | // Cookies created manually; cookies created by Requests will set |
194 | 194 | // the path to the requested path |
195 | - return true; |
|
195 | + return TRUE; |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | $cookie_path = $this->attributes['path']; |
199 | 199 | |
200 | 200 | if ($cookie_path === $request_path) { |
201 | 201 | // The cookie-path and the request-path are identical. |
202 | - return true; |
|
202 | + return TRUE; |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | if (strlen($request_path) > strlen($cookie_path) && substr($request_path, 0, strlen($cookie_path)) === $cookie_path) { |
206 | 206 | if (substr($cookie_path, -1) === '/') { |
207 | 207 | // The cookie-path is a prefix of the request-path, and the last |
208 | 208 | // character of the cookie-path is %x2F ("/"). |
209 | - return true; |
|
209 | + return TRUE; |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | if (substr($request_path, strlen($cookie_path), 1) === '/') { |
213 | 213 | // The cookie-path is a prefix of the request-path, and the |
214 | 214 | // first character of the request-path that is not included in |
215 | 215 | // the cookie-path is a %x2F ("/") character. |
216 | - return true; |
|
216 | + return TRUE; |
|
217 | 217 | } |
218 | 218 | } |
219 | 219 | |
220 | - return false; |
|
220 | + return FALSE; |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | /** |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | foreach ($this->attributes as $key => $value) { |
230 | 230 | $orig_value = $value; |
231 | 231 | $value = $this->normalize_attribute($key, $value); |
232 | - if ($value === null) { |
|
232 | + if ($value === NULL) { |
|
233 | 233 | unset($this->attributes[$key]); |
234 | 234 | continue; |
235 | 235 | } |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | } |
240 | 240 | } |
241 | 241 | |
242 | - return true; |
|
242 | + return TRUE; |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | /** |
@@ -260,8 +260,8 @@ discard block |
||
260 | 260 | } |
261 | 261 | |
262 | 262 | $expiry_time = strtotime($value); |
263 | - if ($expiry_time === false) { |
|
264 | - return null; |
|
263 | + if ($expiry_time === FALSE) { |
|
264 | + return NULL; |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | return $expiry_time; |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | |
275 | 275 | // Check that we have a valid age |
276 | 276 | if (!preg_match('/^-?\d+$/', $value)) { |
277 | - return null; |
|
277 | + return NULL; |
|
278 | 278 | } |
279 | 279 | |
280 | 280 | $delta_seconds = (int) $value; |
@@ -379,14 +379,14 @@ discard block |
||
379 | 379 | * @param string Cookie header value (from a Set-Cookie header) |
380 | 380 | * @return Requests_Cookie Parsed cookie object |
381 | 381 | */ |
382 | - public static function parse($string, $name = '', $reference_time = null) { |
|
382 | + public static function parse($string, $name = '', $reference_time = NULL) { |
|
383 | 383 | $parts = explode(';', $string); |
384 | 384 | $kvparts = array_shift($parts); |
385 | 385 | |
386 | 386 | if (!empty($name)) { |
387 | 387 | $value = $string; |
388 | 388 | } |
389 | - elseif (strpos($kvparts, '=') === false) { |
|
389 | + elseif (strpos($kvparts, '=') === FALSE) { |
|
390 | 390 | // Some sites might only have a value without the equals separator. |
391 | 391 | // Deviate from RFC 6265 and pretend it was actually a blank name |
392 | 392 | // (`=foo`) |
@@ -406,9 +406,9 @@ discard block |
||
406 | 406 | |
407 | 407 | if (!empty($parts)) { |
408 | 408 | foreach ($parts as $part) { |
409 | - if (strpos($part, '=') === false) { |
|
409 | + if (strpos($part, '=') === FALSE) { |
|
410 | 410 | $part_key = $part; |
411 | - $part_value = true; |
|
411 | + $part_value = TRUE; |
|
412 | 412 | } |
413 | 413 | else { |
414 | 414 | list($part_key, $part_value) = explode('=', $part, 2); |
@@ -431,7 +431,7 @@ discard block |
||
431 | 431 | * @param int|null $time Reference time for expiration calculation |
432 | 432 | * @return array |
433 | 433 | */ |
434 | - public static function parse_from_headers(Requests_Response_Headers $headers, Requests_IRI $origin = null, $time = null) { |
|
434 | + public static function parse_from_headers(Requests_Response_Headers $headers, Requests_IRI $origin = NULL, $time = NULL) { |
|
435 | 435 | $cookie_headers = $headers->getValues('Set-Cookie'); |
436 | 436 | if (empty($cookie_headers)) { |
437 | 437 | return array(); |
@@ -444,10 +444,10 @@ discard block |
||
444 | 444 | // Default domain/path attributes |
445 | 445 | if (empty($parsed->attributes['domain']) && !empty($origin)) { |
446 | 446 | $parsed->attributes['domain'] = $origin->host; |
447 | - $parsed->flags['host-only'] = true; |
|
447 | + $parsed->flags['host-only'] = TRUE; |
|
448 | 448 | } |
449 | 449 | else { |
450 | - $parsed->flags['host-only'] = false; |
|
450 | + $parsed->flags['host-only'] = FALSE; |
|
451 | 451 | } |
452 | 452 | |
453 | 453 | $path_is_valid = (!empty($parsed->attributes['path']) && $parsed->attributes['path'][0] === '/'); |
@@ -29,6 +29,9 @@ |
||
29 | 29 | */ |
30 | 30 | protected $reason = 'Unknown'; |
31 | 31 | |
32 | + /** |
|
33 | + * @param string $message |
|
34 | + */ |
|
32 | 35 | public function __construct($message, $type, $data = null, $code = 0) { |
33 | 36 | if ($type !== null) { |
34 | 37 | $this->type = $type; |
@@ -30,15 +30,15 @@ |
||
30 | 30 | protected $reason = 'Unknown'; |
31 | 31 | |
32 | 32 | public function __construct($message, $type, $data = null, $code = 0) { |
33 | - if ($type !== null) { |
|
33 | + if($type !== null) { |
|
34 | 34 | $this->type = $type; |
35 | 35 | } |
36 | 36 | |
37 | - if ($code !== null) { |
|
37 | + if($code !== null) { |
|
38 | 38 | $this->code = $code; |
39 | 39 | } |
40 | 40 | |
41 | - if ($message !== null) { |
|
41 | + if($message !== null) { |
|
42 | 42 | $this->reason = $message; |
43 | 43 | } |
44 | 44 |
@@ -1,6 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -class Requests_Exception_Transport_cURL extends Requests_Exception_Transport { |
|
3 | +class Requests_Exception_Transport_cURL extends Requests_Exception_Transport |
|
4 | +{ |
|
4 | 5 | |
5 | 6 | const EASY = 'cURLEasy'; |
6 | 7 | const MULTI = 'cURLMulti'; |
@@ -29,16 +30,20 @@ discard block |
||
29 | 30 | */ |
30 | 31 | protected $reason = 'Unknown'; |
31 | 32 | |
32 | - public function __construct($message, $type, $data = null, $code = 0) { |
|
33 | - if ($type !== null) { |
|
33 | + public function __construct($message, $type, $data = null, $code = 0) |
|
34 | + { |
|
35 | + if ($type !== null) |
|
36 | + { |
|
34 | 37 | $this->type = $type; |
35 | 38 | } |
36 | 39 | |
37 | - if ($code !== null) { |
|
40 | + if ($code !== null) |
|
41 | + { |
|
38 | 42 | $this->code = $code; |
39 | 43 | } |
40 | 44 | |
41 | - if ($message !== null) { |
|
45 | + if ($message !== null) |
|
46 | + { |
|
42 | 47 | $this->reason = $message; |
43 | 48 | } |
44 | 49 | |
@@ -49,7 +54,8 @@ discard block |
||
49 | 54 | /** |
50 | 55 | * Get the error message |
51 | 56 | */ |
52 | - public function getReason() { |
|
57 | + public function getReason() |
|
58 | + { |
|
53 | 59 | return $this->reason; |
54 | 60 | } |
55 | 61 |
@@ -29,16 +29,16 @@ |
||
29 | 29 | */ |
30 | 30 | protected $reason = 'Unknown'; |
31 | 31 | |
32 | - public function __construct($message, $type, $data = null, $code = 0) { |
|
33 | - if ($type !== null) { |
|
32 | + public function __construct($message, $type, $data = NULL, $code = 0) { |
|
33 | + if ($type !== NULL) { |
|
34 | 34 | $this->type = $type; |
35 | 35 | } |
36 | 36 | |
37 | - if ($code !== null) { |
|
37 | + if ($code !== NULL) { |
|
38 | 38 | $this->code = $code; |
39 | 39 | } |
40 | 40 | |
41 | - if ($message !== null) { |
|
41 | + if ($message !== NULL) { |
|
42 | 42 | $this->reason = $message; |
43 | 43 | } |
44 | 44 |
@@ -19,6 +19,7 @@ |
||
19 | 19 | * @param string $hook Hook name |
20 | 20 | * @param callback $callback Function/method to call on event |
21 | 21 | * @param int $priority Priority number. <0 is executed earlier, >0 is executed later |
22 | + * @return void |
|
22 | 23 | */ |
23 | 24 | public function register($hook, $callback, $priority = 0); |
24 | 25 |
@@ -12,7 +12,8 @@ |
||
12 | 12 | * @package Requests |
13 | 13 | * @subpackage Utilities |
14 | 14 | */ |
15 | -interface Requests_Hooker { |
|
15 | +interface Requests_Hooker |
|
16 | +{ |
|
16 | 17 | /** |
17 | 18 | * Register a callback for a hook |
18 | 19 | * |
@@ -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 UpdateLocation extends AbstractRequest { |
5 | 5 | /** |
6 | - * @var Location |
|
7 | - */ |
|
8 | - public $location; |
|
9 | - /** |
|
10 | - * @return Location |
|
11 | - */ |
|
12 | - public function getLocation() |
|
13 | - { |
|
14 | - return $this->location; |
|
15 | - } |
|
16 | - /** |
|
17 | - * @param Location $location |
|
18 | - */ |
|
19 | - public function setLocation($location) |
|
20 | - { |
|
21 | - $this->location = $location; |
|
22 | - } |
|
6 | + * @var Location |
|
7 | + */ |
|
8 | + public $location; |
|
9 | + /** |
|
10 | + * @return Location |
|
11 | + */ |
|
12 | + public function getLocation() |
|
13 | + { |
|
14 | + return $this->location; |
|
15 | + } |
|
16 | + /** |
|
17 | + * @param Location $location |
|
18 | + */ |
|
19 | + public function setLocation($location) |
|
20 | + { |
|
21 | + $this->location = $location; |
|
22 | + } |
|
23 | 23 | |
24 | - function getApiEndPoint() |
|
25 | - { |
|
26 | - return '/v2/users/location'; |
|
27 | - } |
|
28 | - function getPayload() |
|
29 | - { |
|
30 | - return array( |
|
24 | + function getApiEndPoint() |
|
25 | + { |
|
26 | + return '/v2/users/location'; |
|
27 | + } |
|
28 | + function getPayload() |
|
29 | + { |
|
30 | + return array( |
|
31 | 31 | "location" => $this->getLocation()->toArray(), |
32 | - ); |
|
33 | - } |
|
34 | - function getMethod() |
|
35 | - { |
|
36 | - return 'PUT'; |
|
37 | - } |
|
32 | + ); |
|
33 | + } |
|
34 | + function getMethod() |
|
35 | + { |
|
36 | + return 'PUT'; |
|
37 | + } |
|
38 | 38 | } |
39 | 39 |
@@ -36,7 +36,7 @@ |
||
36 | 36 | { |
37 | 37 | $str = ''; |
38 | 38 | $max = mb_strlen($keyspace, '8bit') - 1; |
39 | - for ($i = 0; $i < $length; ++$i) { |
|
39 | + for($i = 0; $i < $length; ++$i) { |
|
40 | 40 | $str .= $keyspace[random_int(0, $max)]; |
41 | 41 | } |
42 | 42 | return $str; |
@@ -1,6 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -class CreateUser extends AbstractRequest { |
|
3 | +class CreateUser extends AbstractRequest |
|
4 | +{ |
|
4 | 5 | /** |
5 | 6 | * @var Location |
6 | 7 | */ |
@@ -25,7 +26,7 @@ discard block |
||
25 | 26 | return $this->deviceUid; |
26 | 27 | } |
27 | 28 | public function setDeviceUid($deviceUid) |
28 | - { |
|
29 | + { |
|
29 | 30 | $this->deviceUid = $deviceUid; |
30 | 31 | } |
31 | 32 | public function generateDeviceUid() |
@@ -36,7 +37,8 @@ discard block |
||
36 | 37 | { |
37 | 38 | $str = ''; |
38 | 39 | $max = mb_strlen($keyspace, '8bit') - 1; |
39 | - for ($i = 0; $i < $length; ++$i) { |
|
40 | + for ($i = 0; $i < $length; ++$i) |
|
41 | + { |
|
40 | 42 | $str .= $keyspace[random_int(0, $max)]; |
41 | 43 | } |
42 | 44 | return $str; |
@@ -33,6 +33,9 @@ |
||
33 | 33 | return $this->random_str(64, 'abcdef0123456789'); |
34 | 34 | } |
35 | 35 | |
36 | + /** |
|
37 | + * @param integer $length |
|
38 | + */ |
|
36 | 39 | private function random_str($length, $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') |
37 | 40 | { |
38 | 41 | $str = ''; |
@@ -1,53 +1,53 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | class CreateUser extends AbstractRequest { |
4 | - /** |
|
5 | - * @var Location |
|
6 | - */ |
|
7 | - private $location; |
|
8 | - private $deviceUid; |
|
9 | - /** |
|
10 | - * @return Location |
|
11 | - */ |
|
12 | - private function getLocation() |
|
13 | - { |
|
14 | - return $this->location; |
|
15 | - } |
|
16 | - /** |
|
17 | - * @param Location $location |
|
18 | - */ |
|
19 | - public function setLocation(Location $location) |
|
20 | - { |
|
21 | - $this->location = $location; |
|
22 | - } |
|
23 | - private function getDeviceUid() |
|
24 | - { |
|
4 | + /** |
|
5 | + * @var Location |
|
6 | + */ |
|
7 | + private $location; |
|
8 | + private $deviceUid; |
|
9 | + /** |
|
10 | + * @return Location |
|
11 | + */ |
|
12 | + private function getLocation() |
|
13 | + { |
|
14 | + return $this->location; |
|
15 | + } |
|
16 | + /** |
|
17 | + * @param Location $location |
|
18 | + */ |
|
19 | + public function setLocation(Location $location) |
|
20 | + { |
|
21 | + $this->location = $location; |
|
22 | + } |
|
23 | + private function getDeviceUid() |
|
24 | + { |
|
25 | 25 | return $this->deviceUid; |
26 | 26 | } |
27 | 27 | public function setDeviceUid($deviceUid) |
28 | - { |
|
28 | + { |
|
29 | 29 | $this->deviceUid = $deviceUid; |
30 | 30 | } |
31 | - private function generateDeviceUid() |
|
32 | - { |
|
33 | - return $this->random_str(64, 'abcdef0123456789'); |
|
34 | - } |
|
31 | + private function generateDeviceUid() |
|
32 | + { |
|
33 | + return $this->random_str(64, 'abcdef0123456789'); |
|
34 | + } |
|
35 | 35 | |
36 | - private function random_str($length, $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') |
|
37 | - { |
|
38 | - $str = ''; |
|
39 | - $max = mb_strlen($keyspace, '8bit') - 1; |
|
40 | - for ($i = 0; $i < $length; ++$i) { |
|
41 | - $str .= $keyspace[random_int(0, $max)]; |
|
42 | - } |
|
43 | - return $str; |
|
44 | - } |
|
45 | - public function getApiEndPoint() |
|
46 | - { |
|
47 | - return '/v2/users'; |
|
48 | - } |
|
49 | - public function getPayload() |
|
50 | - { |
|
36 | + private function random_str($length, $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') |
|
37 | + { |
|
38 | + $str = ''; |
|
39 | + $max = mb_strlen($keyspace, '8bit') - 1; |
|
40 | + for ($i = 0; $i < $length; ++$i) { |
|
41 | + $str .= $keyspace[random_int(0, $max)]; |
|
42 | + } |
|
43 | + return $str; |
|
44 | + } |
|
45 | + public function getApiEndPoint() |
|
46 | + { |
|
47 | + return '/v2/users'; |
|
48 | + } |
|
49 | + public function getPayload() |
|
50 | + { |
|
51 | 51 | if(!isset($this->deviceUid)) |
52 | 52 | { |
53 | 53 | $this->setDeviceUid($this->generateDeviceUid()); |
@@ -58,9 +58,9 @@ discard block |
||
58 | 58 | "client_id" => self::CLIENTID, |
59 | 59 | "device_uid" => $this->getDeviceUid(), |
60 | 60 | ); |
61 | - } |
|
62 | - public function getMethod() |
|
63 | - { |
|
64 | - return 'POST'; |
|
65 | - } |
|
61 | + } |
|
62 | + public function getMethod() |
|
63 | + { |
|
64 | + return 'POST'; |
|
65 | + } |
|
66 | 66 | } |
@@ -7,22 +7,22 @@ discard block |
||
7 | 7 | |
8 | 8 | public $url; |
9 | 9 | |
10 | - function setUrl ($url) |
|
10 | + function setUrl($url) |
|
11 | 11 | { |
12 | 12 | $this->url = $url; |
13 | 13 | } |
14 | 14 | |
15 | - function getUrl () |
|
15 | + function getUrl() |
|
16 | 16 | { |
17 | 17 | return $this->url; |
18 | 18 | } |
19 | 19 | |
20 | - function setLastPostId ($lastPostId) |
|
20 | + function setLastPostId($lastPostId) |
|
21 | 21 | { |
22 | 22 | $this->lastPostId = $lastPostId; |
23 | 23 | } |
24 | 24 | |
25 | - function getlastPostId () |
|
25 | + function getlastPostId() |
|
26 | 26 | { |
27 | 27 | return $this->lastPostId; |
28 | 28 | } |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | { |
32 | 32 | $apiEndPoint = $this->getUrl(); |
33 | 33 | //echo $GLOBALS['lastPostId']; |
34 | - if ($this->getLastPostId() != "") { |
|
34 | + if($this->getLastPostId() != "") { |
|
35 | 35 | $apiEndPoint = $this->getUrl() . '/location/?after=' . $this->getLastPostId(); |
36 | 36 | } |
37 | 37 | return $apiEndPoint; |
@@ -31,7 +31,8 @@ |
||
31 | 31 | { |
32 | 32 | $apiEndPoint = $this->getUrl(); |
33 | 33 | //echo $GLOBALS['lastPostId']; |
34 | - if ($this->getLastPostId() != "") { |
|
34 | + if ($this->getLastPostId() != "") |
|
35 | + { |
|
35 | 36 | $apiEndPoint = $this->getUrl() . '/location/?after=' . $this->getLastPostId(); |
36 | 37 | } |
37 | 38 | return $apiEndPoint; |
@@ -5,20 +5,20 @@ discard block |
||
5 | 5 | { |
6 | 6 | public $lastPostId; |
7 | 7 | |
8 | - public $url; |
|
8 | + public $url; |
|
9 | 9 | |
10 | - function setUrl ($url) |
|
11 | - { |
|
12 | - $this->url = $url; |
|
13 | - } |
|
10 | + function setUrl ($url) |
|
11 | + { |
|
12 | + $this->url = $url; |
|
13 | + } |
|
14 | 14 | |
15 | - function getUrl () |
|
16 | - { |
|
17 | - return $this->url; |
|
18 | - } |
|
15 | + function getUrl () |
|
16 | + { |
|
17 | + return $this->url; |
|
18 | + } |
|
19 | 19 | |
20 | - function setLastPostId ($lastPostId) |
|
21 | - { |
|
20 | + function setLastPostId ($lastPostId) |
|
21 | + { |
|
22 | 22 | $this->lastPostId = $lastPostId; |
23 | 23 | } |
24 | 24 | |
@@ -27,22 +27,22 @@ discard block |
||
27 | 27 | return $this->lastPostId; |
28 | 28 | } |
29 | 29 | |
30 | - function getApiEndPoint() |
|
31 | - { |
|
32 | - $apiEndPoint = $this->getUrl(); |
|
30 | + function getApiEndPoint() |
|
31 | + { |
|
32 | + $apiEndPoint = $this->getUrl(); |
|
33 | 33 | |
34 | - if ($this->getLastPostId() != "") { |
|
34 | + if ($this->getLastPostId() != "") { |
|
35 | 35 | $apiEndPoint = $this->getUrl() . '?after=' . $this->getLastPostId(); |
36 | 36 | } |
37 | - return $apiEndPoint; |
|
38 | - } |
|
39 | - function getPayload() |
|
40 | - { |
|
41 | - return array( |
|
42 | - ); |
|
43 | - } |
|
44 | - function getMethod() |
|
45 | - { |
|
46 | - return 'GET'; |
|
47 | - } |
|
37 | + return $apiEndPoint; |
|
38 | + } |
|
39 | + function getPayload() |
|
40 | + { |
|
41 | + return array( |
|
42 | + ); |
|
43 | + } |
|
44 | + function getMethod() |
|
45 | + { |
|
46 | + return 'GET'; |
|
47 | + } |
|
48 | 48 | } |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | $header = $this->getSignHeaders(); |
29 | 29 | $url = $this->getFullUrl(); |
30 | 30 | |
31 | - if ($this->getAccessToken()) { |
|
31 | + if($this->getAccessToken()) { |
|
32 | 32 | $header['Authorization'] = "Bearer " . $this->getAccessToken(); |
33 | 33 | } |
34 | 34 | //Comment out to debug the Request: |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | */ |
40 | 40 | |
41 | 41 | |
42 | - switch ($this->getMethod()) { |
|
42 | + switch($this->getMethod()) { |
|
43 | 43 | case 'POST': |
44 | 44 | $result = Requests::post($url, $header, $this->payLoad); |
45 | 45 | break; |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | $result = Requests::put($url, $header, $this->payLoad); |
51 | 51 | break; |
52 | 52 | } |
53 | - switch ($result->status_code) { |
|
53 | + switch($result->status_code) { |
|
54 | 54 | case 200: |
55 | 55 | $result = json_decode($result->body, true); |
56 | 56 | break; |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | throw new \Exception('Signing failed!'); |
68 | 68 | break; |
69 | 69 | default: |
70 | - throw new \Exception('Unknown Error: '.$result->status_code); |
|
70 | + throw new \Exception('Unknown Error: ' . $result->status_code); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | if($device_uid != "") |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | abstract class AbstractRequest |
4 | -{ |
|
4 | +{ |
|
5 | 5 | CONST CLIENTID = '81e8a76e-1e02-4d17-9ba0-8a7020261b26'; |
6 | 6 | CONST APIURL = 'https://api.go-tellm.com/api'; |
7 | 7 | const SECRET = "VwJHzYUbPjGiXWauoVNaHoCWsaacTmnkGwNtHhjy"; |
@@ -19,7 +19,8 @@ discard block |
||
19 | 19 | |
20 | 20 | $this->payLoad = $this->getPayload(); |
21 | 21 | $device_uid = ""; |
22 | - if(isset($this->payLoad["device_uid"])) { |
|
22 | + if(isset($this->payLoad["device_uid"])) |
|
23 | + { |
|
23 | 24 | $device_uid = $this->payLoad["device_uid"]; |
24 | 25 | } |
25 | 26 | |
@@ -28,7 +29,8 @@ discard block |
||
28 | 29 | $header = $this->getSignHeaders(); |
29 | 30 | $url = $this->getFullUrl(); |
30 | 31 | |
31 | - if ($this->getAccessToken()) { |
|
32 | + if ($this->getAccessToken()) |
|
33 | + { |
|
32 | 34 | $header['Authorization'] = "Bearer " . $this->getAccessToken(); |
33 | 35 | } |
34 | 36 | //Comment out to debug the Request: |
@@ -39,7 +41,8 @@ discard block |
||
39 | 41 | */ |
40 | 42 | |
41 | 43 | |
42 | - switch ($this->getMethod()) { |
|
44 | + switch ($this->getMethod()) |
|
45 | + { |
|
43 | 46 | case 'POST': |
44 | 47 | $result = Requests::post($url, $header, $this->payLoad); |
45 | 48 | break; |
@@ -50,7 +53,8 @@ discard block |
||
50 | 53 | $result = Requests::put($url, $header, $this->payLoad); |
51 | 54 | break; |
52 | 55 | } |
53 | - switch ($result->status_code) { |
|
56 | + switch ($result->status_code) |
|
57 | + { |
|
54 | 58 | case 200: |
55 | 59 | $result = json_decode($result->body, true); |
56 | 60 | break; |
@@ -90,10 +94,12 @@ discard block |
||
90 | 94 | public function getSignHeaders() |
91 | 95 | { |
92 | 96 | $payload_accessToken; |
93 | - if($this->getAccessToken() == null) { |
|
97 | + if($this->getAccessToken() == null) |
|
98 | + { |
|
94 | 99 | $payload_accessToken = ""; |
95 | 100 | } |
96 | - else { |
|
101 | + else |
|
102 | + { |
|
97 | 103 | $payload_accessToken = $this->getAccessToken(); |
98 | 104 | } |
99 | 105 |
@@ -2,8 +2,8 @@ discard block |
||
2 | 2 | |
3 | 3 | abstract class AbstractRequest |
4 | 4 | { |
5 | - CONST CLIENTID = '81e8a76e-1e02-4d17-9ba0-8a7020261b26'; |
|
6 | - CONST APIURL = 'https://api.go-tellm.com/api'; |
|
5 | + const CLIENTID = '81e8a76e-1e02-4d17-9ba0-8a7020261b26'; |
|
6 | + const APIURL = 'https://api.go-tellm.com/api'; |
|
7 | 7 | const SECRET = "VwJHzYUbPjGiXWauoVNaHoCWsaacTmnkGwNtHhjy"; |
8 | 8 | const USERAGENT = "Jodel/4.27.1 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )"; |
9 | 9 | const CLIENT_TYPE = 'android_4.27.1'; |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | /** |
12 | 12 | * @var string |
13 | 13 | */ |
14 | - private $accessToken = null; |
|
14 | + private $accessToken = NULL; |
|
15 | 15 | private $payLoad; |
16 | 16 | public function execute() |
17 | 17 | { |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | } |
53 | 53 | switch ($result->status_code) { |
54 | 54 | case 200: |
55 | - $result = json_decode($result->body, true); |
|
55 | + $result = json_decode($result->body, TRUE); |
|
56 | 56 | break; |
57 | 57 | case 204: |
58 | 58 | $result = "Success"; |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | */ |
90 | 90 | private function getSignHeaders() |
91 | 91 | { |
92 | - if($this->getAccessToken() == null) { |
|
92 | + if($this->getAccessToken() == NULL) { |
|
93 | 93 | $payload_accessToken = ""; |
94 | 94 | } |
95 | 95 | else { |
@@ -2,18 +2,18 @@ discard block |
||
2 | 2 | |
3 | 3 | abstract class AbstractRequest |
4 | 4 | { |
5 | - CONST CLIENTID = '81e8a76e-1e02-4d17-9ba0-8a7020261b26'; |
|
6 | - CONST APIURL = 'https://api.go-tellm.com/api'; |
|
7 | - const SECRET = "dIHNtHWOxFmoFouufSflpTKYjPmCIhWUCQHgbNzR"; |
|
8 | - const USERAGENT = "Jodel/4.28.1 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )"; |
|
9 | - const CLIENT_TYPE = 'android_4.29.1'; |
|
5 | + CONST CLIENTID = '81e8a76e-1e02-4d17-9ba0-8a7020261b26'; |
|
6 | + CONST APIURL = 'https://api.go-tellm.com/api'; |
|
7 | + const SECRET = "dIHNtHWOxFmoFouufSflpTKYjPmCIhWUCQHgbNzR"; |
|
8 | + const USERAGENT = "Jodel/4.28.1 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )"; |
|
9 | + const CLIENT_TYPE = 'android_4.29.1'; |
|
10 | 10 | |
11 | - private $accessToken = null; |
|
12 | - private $payLoad; |
|
13 | - public $expects = ""; |
|
11 | + private $accessToken = null; |
|
12 | + private $payLoad; |
|
13 | + public $expects = ""; |
|
14 | 14 | |
15 | - public function execute() |
|
16 | - { |
|
15 | + public function execute() |
|
16 | + { |
|
17 | 17 | $result = new \stdClass(); |
18 | 18 | |
19 | 19 | $this->payLoad = $this->getPayload(); |
@@ -23,71 +23,71 @@ discard block |
||
23 | 23 | } |
24 | 24 | |
25 | 25 | |
26 | - $this->payLoad = json_encode($this->payLoad); |
|
27 | - $header = $this->getSignHeaders(); |
|
28 | - $url = $this->getFullUrl(); |
|
26 | + $this->payLoad = json_encode($this->payLoad); |
|
27 | + $header = $this->getSignHeaders(); |
|
28 | + $url = $this->getFullUrl(); |
|
29 | 29 | |
30 | - if ($this->getAccessToken()) { |
|
31 | - $header['Authorization'] = "Bearer " . $this->getAccessToken(); |
|
32 | - } |
|
33 | - //Comment out to debug the Request: |
|
34 | - /* |
|
30 | + if ($this->getAccessToken()) { |
|
31 | + $header['Authorization'] = "Bearer " . $this->getAccessToken(); |
|
32 | + } |
|
33 | + //Comment out to debug the Request: |
|
34 | + /* |
|
35 | 35 | var_dump($url); |
36 | 36 | var_dump($header); |
37 | 37 | var_dump($this->payLoad); |
38 | 38 | */ |
39 | 39 | |
40 | 40 | |
41 | - switch ($this->getMethod()) { |
|
42 | - case 'POST': |
|
43 | - $result = Requests::post($url, $header, $this->payLoad); |
|
44 | - break; |
|
45 | - case 'GET': |
|
46 | - $result = Requests::get($url, $header); |
|
47 | - break; |
|
48 | - case 'PUT': |
|
49 | - $result = Requests::put($url, $header, $this->payLoad); |
|
50 | - break; |
|
51 | - } |
|
52 | - switch ($result->status_code) { |
|
53 | - case 200: |
|
54 | - $result = json_decode($result->body, true); |
|
55 | - break; |
|
56 | - case 204: |
|
57 | - $result = "Success"; |
|
58 | - break; |
|
59 | - case 401: |
|
41 | + switch ($this->getMethod()) { |
|
42 | + case 'POST': |
|
43 | + $result = Requests::post($url, $header, $this->payLoad); |
|
44 | + break; |
|
45 | + case 'GET': |
|
46 | + $result = Requests::get($url, $header); |
|
47 | + break; |
|
48 | + case 'PUT': |
|
49 | + $result = Requests::put($url, $header, $this->payLoad); |
|
50 | + break; |
|
51 | + } |
|
52 | + switch ($result->status_code) { |
|
53 | + case 200: |
|
54 | + $result = json_decode($result->body, true); |
|
55 | + break; |
|
56 | + case 204: |
|
57 | + $result = "Success"; |
|
58 | + break; |
|
59 | + case 401: |
|
60 | 60 | throw new \Exception('Unauthorized'); |
61 | - break; |
|
62 | - case 404: |
|
63 | - //echo "Es wurde bereits gevoted"; |
|
61 | + break; |
|
62 | + case 404: |
|
63 | + //echo "Es wurde bereits gevoted"; |
|
64 | 64 | case 477: |
65 | - //echo "Es wurde bereits gevoted"; |
|
66 | - //throw new \Exception('Signing failed!'); |
|
67 | - break; |
|
68 | - default: |
|
69 | - throw new \Exception('Unknown Error: '.$result->status_code); |
|
70 | - } |
|
65 | + //echo "Es wurde bereits gevoted"; |
|
66 | + //throw new \Exception('Signing failed!'); |
|
67 | + break; |
|
68 | + default: |
|
69 | + throw new \Exception('Unknown Error: '.$result->status_code); |
|
70 | + } |
|
71 | 71 | |
72 | - if($device_uid != "") |
|
73 | - { |
|
72 | + if($device_uid != "") |
|
73 | + { |
|
74 | 74 | $result[0] = $result; |
75 | 75 | $result[1] = $device_uid; |
76 | 76 | } |
77 | 77 | |
78 | - /* |
|
78 | + /* |
|
79 | 79 | var_dump($result); |
80 | 80 | */ |
81 | 81 | |
82 | - return $result; |
|
83 | - } |
|
84 | - abstract function getPayload(); |
|
85 | - /** |
|
86 | - * Gets Sign headers |
|
87 | - * @return array headers |
|
88 | - */ |
|
89 | - private function getSignHeaders() |
|
90 | - { |
|
82 | + return $result; |
|
83 | + } |
|
84 | + abstract function getPayload(); |
|
85 | + /** |
|
86 | + * Gets Sign headers |
|
87 | + * @return array headers |
|
88 | + */ |
|
89 | + private function getSignHeaders() |
|
90 | + { |
|
91 | 91 | if($this->getAccessToken() == null) { |
92 | 92 | $payload_accessToken = ""; |
93 | 93 | } |
@@ -96,54 +96,54 @@ discard block |
||
96 | 96 | } |
97 | 97 | |
98 | 98 | |
99 | - $headers = array( |
|
100 | - "Connection" => "keep-alive", |
|
101 | - "Accept-Encoding" => "gzip", |
|
102 | - "Content-Type" => "application/json; charset=UTF-8", |
|
103 | - "User-Agent" => self::USERAGENT |
|
104 | - ); |
|
105 | - $timestamp = new DateTime(); |
|
106 | - $timestamp = $timestamp->format(DateTime::ATOM); |
|
107 | - $timestamp = substr($timestamp, 0, -6); |
|
108 | - $timestamp .= "Z"; |
|
109 | - $urlParts = parse_url($this->getFullUrl()); |
|
110 | - $url2 = ""; |
|
111 | - $req = [$this->getMethod(), |
|
112 | - $urlParts['host'], |
|
113 | - "443", |
|
114 | - $urlParts['path'], |
|
115 | - $payload_accessToken, |
|
116 | - $timestamp, |
|
117 | - $url2, |
|
118 | - $this->payLoad]; |
|
119 | - $reqString = implode("%", $req); |
|
120 | - $secret = self::SECRET; |
|
121 | - $signature = hash_hmac('sha1', $reqString, $secret); |
|
122 | - $signature = strtoupper($signature); |
|
123 | - $headers['X-Authorization'] = 'HMAC ' . $signature; |
|
124 | - $headers['X-Client-Type'] = self::CLIENT_TYPE; |
|
125 | - $headers['X-Timestamp'] = $timestamp; |
|
126 | - $headers['X-Api-Version'] = '0.2'; |
|
127 | - return $headers; |
|
128 | - } |
|
129 | - private function getFullUrl() |
|
130 | - { |
|
131 | - return self::APIURL . $this->getApiEndPoint(); |
|
132 | - } |
|
133 | - abstract function getApiEndPoint(); |
|
134 | - abstract function getMethod(); |
|
135 | - /** |
|
136 | - * @return string |
|
137 | - */ |
|
138 | - private function getAccessToken() |
|
139 | - { |
|
140 | - return $this->accessToken; |
|
141 | - } |
|
142 | - /** |
|
143 | - * @param string $accessToken |
|
144 | - */ |
|
145 | - public function setAccessToken($accessToken) |
|
146 | - { |
|
147 | - $this->accessToken = $accessToken; |
|
148 | - } |
|
99 | + $headers = array( |
|
100 | + "Connection" => "keep-alive", |
|
101 | + "Accept-Encoding" => "gzip", |
|
102 | + "Content-Type" => "application/json; charset=UTF-8", |
|
103 | + "User-Agent" => self::USERAGENT |
|
104 | + ); |
|
105 | + $timestamp = new DateTime(); |
|
106 | + $timestamp = $timestamp->format(DateTime::ATOM); |
|
107 | + $timestamp = substr($timestamp, 0, -6); |
|
108 | + $timestamp .= "Z"; |
|
109 | + $urlParts = parse_url($this->getFullUrl()); |
|
110 | + $url2 = ""; |
|
111 | + $req = [$this->getMethod(), |
|
112 | + $urlParts['host'], |
|
113 | + "443", |
|
114 | + $urlParts['path'], |
|
115 | + $payload_accessToken, |
|
116 | + $timestamp, |
|
117 | + $url2, |
|
118 | + $this->payLoad]; |
|
119 | + $reqString = implode("%", $req); |
|
120 | + $secret = self::SECRET; |
|
121 | + $signature = hash_hmac('sha1', $reqString, $secret); |
|
122 | + $signature = strtoupper($signature); |
|
123 | + $headers['X-Authorization'] = 'HMAC ' . $signature; |
|
124 | + $headers['X-Client-Type'] = self::CLIENT_TYPE; |
|
125 | + $headers['X-Timestamp'] = $timestamp; |
|
126 | + $headers['X-Api-Version'] = '0.2'; |
|
127 | + return $headers; |
|
128 | + } |
|
129 | + private function getFullUrl() |
|
130 | + { |
|
131 | + return self::APIURL . $this->getApiEndPoint(); |
|
132 | + } |
|
133 | + abstract function getApiEndPoint(); |
|
134 | + abstract function getMethod(); |
|
135 | + /** |
|
136 | + * @return string |
|
137 | + */ |
|
138 | + private function getAccessToken() |
|
139 | + { |
|
140 | + return $this->accessToken; |
|
141 | + } |
|
142 | + /** |
|
143 | + * @param string $accessToken |
|
144 | + */ |
|
145 | + public function setAccessToken($accessToken) |
|
146 | + { |
|
147 | + $this->accessToken = $accessToken; |
|
148 | + } |
|
149 | 149 | } |
@@ -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 |