@@ -3,19 +3,19 @@ |
||
| 3 | 3 | |
| 4 | 4 | class Upvote extends AbstractRequest { |
| 5 | 5 | |
| 6 | - function getApiEndPoint() |
|
| 7 | - { |
|
| 8 | - return '/v2/posts/' . $_GET['postID'] . '/upvote'; |
|
| 9 | - } |
|
| 10 | - function getPayload() |
|
| 11 | - { |
|
| 12 | - return array( |
|
| 6 | + function getApiEndPoint() |
|
| 7 | + { |
|
| 8 | + return '/v2/posts/' . $_GET['postID'] . '/upvote'; |
|
| 9 | + } |
|
| 10 | + function getPayload() |
|
| 11 | + { |
|
| 12 | + return array( |
|
| 13 | 13 | "reason_code" => -1, |
| 14 | - ); |
|
| 15 | - } |
|
| 16 | - function getMethod() |
|
| 17 | - { |
|
| 18 | - return 'PUT'; |
|
| 19 | - } |
|
| 14 | + ); |
|
| 15 | + } |
|
| 16 | + function getMethod() |
|
| 17 | + { |
|
| 18 | + return 'PUT'; |
|
| 19 | + } |
|
| 20 | 20 | } |
| 21 | 21 | |
@@ -1,7 +1,8 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | |
| 4 | -class Upvote extends AbstractRequest { |
|
| 4 | +class Upvote extends AbstractRequest |
|
| 5 | +{ |
|
| 5 | 6 | |
| 6 | 7 | function getApiEndPoint() |
| 7 | 8 | { |
@@ -2,19 +2,19 @@ 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 = "VwJHzYUbPjGiXWauoVNaHoCWsaacTmnkGwNtHhjy"; |
|
| 8 | - const USERAGENT = "Jodel/4.27.1 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )"; |
|
| 9 | - const CLIENT_TYPE = 'android_4.27.1'; |
|
| 5 | + CONST CLIENTID = '81e8a76e-1e02-4d17-9ba0-8a7020261b26'; |
|
| 6 | + CONST APIURL = 'https://api.go-tellm.com/api'; |
|
| 7 | + const SECRET = "VwJHzYUbPjGiXWauoVNaHoCWsaacTmnkGwNtHhjy"; |
|
| 8 | + const USERAGENT = "Jodel/4.27.1 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )"; |
|
| 9 | + const CLIENT_TYPE = 'android_4.27.1'; |
|
| 10 | 10 | |
| 11 | - /** |
|
| 12 | - * @var string |
|
| 13 | - */ |
|
| 14 | - public $accessToken = null; |
|
| 15 | - private $payLoad; |
|
| 16 | - public function execute() |
|
| 17 | - { |
|
| 11 | + /** |
|
| 12 | + * @var string |
|
| 13 | + */ |
|
| 14 | + public $accessToken = null; |
|
| 15 | + private $payLoad; |
|
| 16 | + public function execute() |
|
| 17 | + { |
|
| 18 | 18 | $result = new \stdClass(); |
| 19 | 19 | |
| 20 | 20 | $this->payLoad = $this->getPayload(); |
@@ -24,71 +24,71 @@ discard block |
||
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | |
| 27 | - $this->payLoad = json_encode($this->payLoad); |
|
| 28 | - $header = $this->getSignHeaders(); |
|
| 29 | - $url = $this->getFullUrl(); |
|
| 27 | + $this->payLoad = json_encode($this->payLoad); |
|
| 28 | + $header = $this->getSignHeaders(); |
|
| 29 | + $url = $this->getFullUrl(); |
|
| 30 | 30 | |
| 31 | - if ($this->getAccessToken()) { |
|
| 32 | - $header['Authorization'] = "Bearer " . $this->getAccessToken(); |
|
| 33 | - } |
|
| 34 | - //Comment out to debug the Request: |
|
| 35 | - /* |
|
| 31 | + if ($this->getAccessToken()) { |
|
| 32 | + $header['Authorization'] = "Bearer " . $this->getAccessToken(); |
|
| 33 | + } |
|
| 34 | + //Comment out to debug the Request: |
|
| 35 | + /* |
|
| 36 | 36 | var_dump($url); |
| 37 | 37 | var_dump($header); |
| 38 | 38 | var_dump($this->payLoad); |
| 39 | 39 | */ |
| 40 | 40 | |
| 41 | 41 | |
| 42 | - switch ($this->getMethod()) { |
|
| 43 | - case 'POST': |
|
| 44 | - $result = Requests::post($url, $header, $this->payLoad); |
|
| 45 | - break; |
|
| 46 | - case 'GET': |
|
| 47 | - $result = Requests::get($url, $header); |
|
| 48 | - break; |
|
| 49 | - case 'PUT': |
|
| 50 | - $result = Requests::put($url, $header, $this->payLoad); |
|
| 51 | - break; |
|
| 52 | - } |
|
| 53 | - switch ($result->status_code) { |
|
| 54 | - case 200: |
|
| 55 | - $result = json_decode($result->body, true); |
|
| 56 | - break; |
|
| 57 | - case 204: |
|
| 58 | - $result = "Success"; |
|
| 59 | - break; |
|
| 60 | - case 401: |
|
| 42 | + switch ($this->getMethod()) { |
|
| 43 | + case 'POST': |
|
| 44 | + $result = Requests::post($url, $header, $this->payLoad); |
|
| 45 | + break; |
|
| 46 | + case 'GET': |
|
| 47 | + $result = Requests::get($url, $header); |
|
| 48 | + break; |
|
| 49 | + case 'PUT': |
|
| 50 | + $result = Requests::put($url, $header, $this->payLoad); |
|
| 51 | + break; |
|
| 52 | + } |
|
| 53 | + switch ($result->status_code) { |
|
| 54 | + case 200: |
|
| 55 | + $result = json_decode($result->body, true); |
|
| 56 | + break; |
|
| 57 | + case 204: |
|
| 58 | + $result = "Success"; |
|
| 59 | + break; |
|
| 60 | + case 401: |
|
| 61 | 61 | throw new \Exception('Unauthorized'); |
| 62 | - break; |
|
| 63 | - case 404: |
|
| 64 | - echo "Es wurde bereits gevoted"; |
|
| 62 | + break; |
|
| 63 | + case 404: |
|
| 64 | + echo "Es wurde bereits gevoted"; |
|
| 65 | 65 | case 477: |
| 66 | - echo "Es wurde bereits gevoted"; |
|
| 67 | - throw new \Exception('Signing failed!'); |
|
| 68 | - break; |
|
| 69 | - default: |
|
| 70 | - throw new \Exception('Unknown Error: '.$result->status_code); |
|
| 71 | - } |
|
| 66 | + echo "Es wurde bereits gevoted"; |
|
| 67 | + throw new \Exception('Signing failed!'); |
|
| 68 | + break; |
|
| 69 | + default: |
|
| 70 | + throw new \Exception('Unknown Error: '.$result->status_code); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - if($device_uid != "") |
|
| 74 | - { |
|
| 73 | + if($device_uid != "") |
|
| 74 | + { |
|
| 75 | 75 | $result[0] = $result; |
| 76 | 76 | $result[1] = $device_uid; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - /* |
|
| 79 | + /* |
|
| 80 | 80 | var_dump($result); |
| 81 | 81 | */ |
| 82 | 82 | |
| 83 | - return $result; |
|
| 84 | - } |
|
| 85 | - abstract function getPayload(); |
|
| 86 | - /** |
|
| 87 | - * Gets Sign headers |
|
| 88 | - * @return array headers |
|
| 89 | - */ |
|
| 90 | - public function getSignHeaders() |
|
| 91 | - { |
|
| 83 | + return $result; |
|
| 84 | + } |
|
| 85 | + abstract function getPayload(); |
|
| 86 | + /** |
|
| 87 | + * Gets Sign headers |
|
| 88 | + * @return array headers |
|
| 89 | + */ |
|
| 90 | + public function getSignHeaders() |
|
| 91 | + { |
|
| 92 | 92 | $payload_accessToken; |
| 93 | 93 | if($this->getAccessToken() == null) { |
| 94 | 94 | $payload_accessToken = ""; |
@@ -98,54 +98,54 @@ discard block |
||
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | |
| 101 | - $headers = array( |
|
| 102 | - "Connection" => "keep-alive", |
|
| 103 | - "Accept-Encoding" => "gzip", |
|
| 104 | - "Content-Type" => "application/json; charset=UTF-8", |
|
| 105 | - "User-Agent" => self::USERAGENT |
|
| 106 | - ); |
|
| 107 | - $timestamp = new DateTime(); |
|
| 108 | - $timestamp = $timestamp->format(DateTime::ATOM); |
|
| 109 | - $timestamp = substr($timestamp, 0, -6); |
|
| 110 | - $timestamp .= "Z"; |
|
| 111 | - $urlParts = parse_url($this->getFullUrl()); |
|
| 112 | - $url2 = ""; |
|
| 113 | - $req = [$this->getMethod(), |
|
| 114 | - $urlParts['host'], |
|
| 115 | - "443", |
|
| 116 | - $urlParts['path'], |
|
| 117 | - $payload_accessToken, |
|
| 118 | - $timestamp, |
|
| 119 | - $url2, |
|
| 120 | - $this->payLoad]; |
|
| 121 | - $reqString = implode("%", $req); |
|
| 122 | - $secret = self::SECRET; |
|
| 123 | - $signature = hash_hmac('sha1', $reqString, $secret); |
|
| 124 | - $signature = strtoupper($signature); |
|
| 125 | - $headers['X-Authorization'] = 'HMAC ' . $signature; |
|
| 126 | - $headers['X-Client-Type'] = self::CLIENT_TYPE; |
|
| 127 | - $headers['X-Timestamp'] = $timestamp; |
|
| 128 | - $headers['X-Api-Version'] = '0.2'; |
|
| 129 | - return $headers; |
|
| 130 | - } |
|
| 131 | - public function getFullUrl() |
|
| 132 | - { |
|
| 133 | - return self::APIURL . $this->getApiEndPoint(); |
|
| 134 | - } |
|
| 135 | - abstract function getApiEndPoint(); |
|
| 136 | - abstract function getMethod(); |
|
| 137 | - /** |
|
| 138 | - * @return string |
|
| 139 | - */ |
|
| 140 | - public function getAccessToken() |
|
| 141 | - { |
|
| 142 | - return $this->accessToken; |
|
| 143 | - } |
|
| 144 | - /** |
|
| 145 | - * @param string $accessToken |
|
| 146 | - */ |
|
| 147 | - public function setAccessToken(string $accessToken) |
|
| 148 | - { |
|
| 149 | - $this->accessToken = $accessToken; |
|
| 150 | - } |
|
| 101 | + $headers = array( |
|
| 102 | + "Connection" => "keep-alive", |
|
| 103 | + "Accept-Encoding" => "gzip", |
|
| 104 | + "Content-Type" => "application/json; charset=UTF-8", |
|
| 105 | + "User-Agent" => self::USERAGENT |
|
| 106 | + ); |
|
| 107 | + $timestamp = new DateTime(); |
|
| 108 | + $timestamp = $timestamp->format(DateTime::ATOM); |
|
| 109 | + $timestamp = substr($timestamp, 0, -6); |
|
| 110 | + $timestamp .= "Z"; |
|
| 111 | + $urlParts = parse_url($this->getFullUrl()); |
|
| 112 | + $url2 = ""; |
|
| 113 | + $req = [$this->getMethod(), |
|
| 114 | + $urlParts['host'], |
|
| 115 | + "443", |
|
| 116 | + $urlParts['path'], |
|
| 117 | + $payload_accessToken, |
|
| 118 | + $timestamp, |
|
| 119 | + $url2, |
|
| 120 | + $this->payLoad]; |
|
| 121 | + $reqString = implode("%", $req); |
|
| 122 | + $secret = self::SECRET; |
|
| 123 | + $signature = hash_hmac('sha1', $reqString, $secret); |
|
| 124 | + $signature = strtoupper($signature); |
|
| 125 | + $headers['X-Authorization'] = 'HMAC ' . $signature; |
|
| 126 | + $headers['X-Client-Type'] = self::CLIENT_TYPE; |
|
| 127 | + $headers['X-Timestamp'] = $timestamp; |
|
| 128 | + $headers['X-Api-Version'] = '0.2'; |
|
| 129 | + return $headers; |
|
| 130 | + } |
|
| 131 | + public function getFullUrl() |
|
| 132 | + { |
|
| 133 | + return self::APIURL . $this->getApiEndPoint(); |
|
| 134 | + } |
|
| 135 | + abstract function getApiEndPoint(); |
|
| 136 | + abstract function getMethod(); |
|
| 137 | + /** |
|
| 138 | + * @return string |
|
| 139 | + */ |
|
| 140 | + public function getAccessToken() |
|
| 141 | + { |
|
| 142 | + return $this->accessToken; |
|
| 143 | + } |
|
| 144 | + /** |
|
| 145 | + * @param string $accessToken |
|
| 146 | + */ |
|
| 147 | + public function setAccessToken(string $accessToken) |
|
| 148 | + { |
|
| 149 | + $this->accessToken = $accessToken; |
|
| 150 | + } |
|
| 151 | 151 | } |
@@ -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 | - public $accessToken = null; |
|
| 14 | + public $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"; |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | public function getSignHeaders() |
| 91 | 91 | { |
| 92 | 92 | $payload_accessToken; |
| 93 | - if($this->getAccessToken() == null) { |
|
| 93 | + if($this->getAccessToken() == NULL) { |
|
| 94 | 94 | $payload_accessToken = ""; |
| 95 | 95 | } |
| 96 | 96 | else { |
@@ -31,5 +31,5 @@ |
||
| 31 | 31 | * @see Requests_Hooks::register |
| 32 | 32 | * @param Requests_Hooks $hooks Hook system |
| 33 | 33 | */ |
| 34 | - public function register(Requests_Hooks &$hooks); |
|
| 34 | + public function register(Requests_Hooks&$hooks); |
|
| 35 | 35 | } |
| 36 | 36 | \ No newline at end of file |
@@ -30,6 +30,7 @@ |
||
| 30 | 30 | * |
| 31 | 31 | * @see Requests_Hooks::register |
| 32 | 32 | * @param Requests_Hooks $hooks Hook system |
| 33 | + * @return void |
|
| 33 | 34 | */ |
| 34 | 35 | public function register(Requests_Hooks &$hooks); |
| 35 | 36 | } |
| 36 | 37 | \ No newline at end of file |
@@ -20,7 +20,8 @@ |
||
| 20 | 20 | * @subpackage Proxy |
| 21 | 21 | * @since 1.6 |
| 22 | 22 | */ |
| 23 | -interface Requests_Proxy { |
|
| 23 | +interface Requests_Proxy |
|
| 24 | +{ |
|
| 24 | 25 | /** |
| 25 | 26 | * Register hooks as needed |
| 26 | 27 | * |
@@ -3,18 +3,18 @@ |
||
| 3 | 3 | |
| 4 | 4 | class GetPostDetails extends AbstractRequest { |
| 5 | 5 | |
| 6 | - function getApiEndPoint() |
|
| 7 | - { |
|
| 8 | - return '/v2/posts/' . $_GET['postID']; |
|
| 9 | - } |
|
| 10 | - function getPayload() |
|
| 11 | - { |
|
| 12 | - return array( |
|
| 13 | - ); |
|
| 14 | - } |
|
| 15 | - function getMethod() |
|
| 16 | - { |
|
| 17 | - return 'GET'; |
|
| 18 | - } |
|
| 6 | + function getApiEndPoint() |
|
| 7 | + { |
|
| 8 | + return '/v2/posts/' . $_GET['postID']; |
|
| 9 | + } |
|
| 10 | + function getPayload() |
|
| 11 | + { |
|
| 12 | + return array( |
|
| 13 | + ); |
|
| 14 | + } |
|
| 15 | + function getMethod() |
|
| 16 | + { |
|
| 17 | + return 'GET'; |
|
| 18 | + } |
|
| 19 | 19 | } |
| 20 | 20 | |
@@ -1,7 +1,8 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | |
| 4 | -class GetPostDetails extends AbstractRequest { |
|
| 4 | +class GetPostDetails extends AbstractRequest |
|
| 5 | +{ |
|
| 5 | 6 | |
| 6 | 7 | function getApiEndPoint() |
| 7 | 8 | { |
@@ -3,18 +3,18 @@ |
||
| 3 | 3 | |
| 4 | 4 | class Downvote extends AbstractRequest { |
| 5 | 5 | |
| 6 | - function getApiEndPoint() |
|
| 7 | - { |
|
| 8 | - return '/v2/posts/' . $_GET['postID'] . '/downvote'; |
|
| 9 | - } |
|
| 10 | - function getPayload() |
|
| 11 | - { |
|
| 12 | - return array( |
|
| 13 | - ); |
|
| 14 | - } |
|
| 15 | - function getMethod() |
|
| 16 | - { |
|
| 17 | - return 'PUT'; |
|
| 18 | - } |
|
| 6 | + function getApiEndPoint() |
|
| 7 | + { |
|
| 8 | + return '/v2/posts/' . $_GET['postID'] . '/downvote'; |
|
| 9 | + } |
|
| 10 | + function getPayload() |
|
| 11 | + { |
|
| 12 | + return array( |
|
| 13 | + ); |
|
| 14 | + } |
|
| 15 | + function getMethod() |
|
| 16 | + { |
|
| 17 | + return 'PUT'; |
|
| 18 | + } |
|
| 19 | 19 | } |
| 20 | 20 | |
@@ -1,7 +1,8 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | |
| 4 | -class Downvote extends AbstractRequest { |
|
| 4 | +class Downvote extends AbstractRequest |
|
| 5 | +{ |
|
| 5 | 6 | |
| 6 | 7 | function getApiEndPoint() |
| 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(): Location |
|
| 13 | - { |
|
| 14 | - return $this->location; |
|
| 15 | - } |
|
| 16 | - /** |
|
| 17 | - * @param Location $location |
|
| 18 | - */ |
|
| 19 | - public function setLocation(Location $location) |
|
| 20 | - { |
|
| 21 | - $this->location = $location; |
|
| 22 | - } |
|
| 6 | + * @var Location |
|
| 7 | + */ |
|
| 8 | + public $location; |
|
| 9 | + /** |
|
| 10 | + * @return Location |
|
| 11 | + */ |
|
| 12 | + public function getLocation(): Location |
|
| 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 | 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 | |
@@ -1,7 +1,8 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | |
| 4 | -class UpdateLocation extends AbstractRequest { |
|
| 4 | +class UpdateLocation extends AbstractRequest |
|
| 5 | +{ |
|
| 5 | 6 | /** |
| 6 | 7 | * @var Location |
| 7 | 8 | */ |
@@ -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(): string |
|
| 12 | - { |
|
| 13 | - return $this->cityName; |
|
| 14 | - } |
|
| 15 | - |
|
| 16 | - public function setCityName(string $cityName) |
|
| 17 | - { |
|
| 18 | - $this->cityName = $cityName; |
|
| 19 | - } |
|
| 20 | - |
|
| 21 | - public function getLat(): string |
|
| 22 | - { |
|
| 23 | - return $this->lat; |
|
| 24 | - } |
|
| 25 | - |
|
| 26 | - public function setLat(string $lat) |
|
| 27 | - { |
|
| 28 | - $this->lat = $lat; |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - public function getLng(): string |
|
| 32 | - { |
|
| 33 | - return $this->lng; |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - public function setLng(string $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(): string |
|
| 12 | + { |
|
| 13 | + return $this->cityName; |
|
| 14 | + } |
|
| 15 | + |
|
| 16 | + public function setCityName(string $cityName) |
|
| 17 | + { |
|
| 18 | + $this->cityName = $cityName; |
|
| 19 | + } |
|
| 20 | + |
|
| 21 | + public function getLat(): string |
|
| 22 | + { |
|
| 23 | + return $this->lat; |
|
| 24 | + } |
|
| 25 | + |
|
| 26 | + public function setLat(string $lat) |
|
| 27 | + { |
|
| 28 | + $this->lat = $lat; |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + public function getLng(): string |
|
| 32 | + { |
|
| 33 | + return $this->lng; |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + public function setLng(string $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 | } |
@@ -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', |
@@ -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 | |