@@ -25,6 +25,9 @@ discard block |
||
25 | 25 | $this->apiPrefix = $apiPrefix; |
26 | 26 | } |
27 | 27 | |
28 | + /** |
|
29 | + * @param string $url |
|
30 | + */ |
|
28 | 31 | public function performGetRequest($url) |
29 | 32 | { |
30 | 33 | $curlUrl = $this->consulBaseUrl . $this->apiPrefix . $url; |
@@ -35,6 +38,9 @@ discard block |
||
35 | 38 | return $returnData; |
36 | 39 | } |
37 | 40 | |
41 | + /** |
|
42 | + * @param string $url |
|
43 | + */ |
|
38 | 44 | public function performPutRequest($url, $payload = null) |
39 | 45 | { |
40 | 46 | $curlUrl = $this->consulBaseUrl . $this->apiPrefix . $url; |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | |
28 | 28 | public function performGetRequest($url) |
29 | 29 | { |
30 | - $curlUrl = $this->consulBaseUrl . $this->apiPrefix . $url; |
|
30 | + $curlUrl = $this->consulBaseUrl.$this->apiPrefix.$url; |
|
31 | 31 | $ch = curl_init($curlUrl); |
32 | 32 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
33 | 33 | $result = curl_exec($ch); |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | |
38 | 38 | public function performPutRequest($url, $payload = null) |
39 | 39 | { |
40 | - $curlUrl = $this->consulBaseUrl . $this->apiPrefix . $url; |
|
40 | + $curlUrl = $this->consulBaseUrl.$this->apiPrefix.$url; |
|
41 | 41 | $ch = curl_init($curlUrl); |
42 | 42 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); |
43 | 43 | curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | curl_setopt($ch, CURLOPT_HTTPHEADER, |
50 | 50 | array( |
51 | 51 | 'Content-Type: application/json', |
52 | - 'Content-Length: ' . strlen($payload)) |
|
52 | + 'Content-Length: '.strlen($payload)) |
|
53 | 53 | ); |
54 | 54 | $result = curl_exec($ch); |
55 | 55 | $returnData = json_decode($result, true); |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | { |
56 | 56 | $this->curl = $curl; |
57 | 57 | $this->kvPrefix = $kvPrefix; |
58 | - $this->sessionTTL = (int)$sessionTTL; |
|
58 | + $this->sessionTTL = (int) $sessionTTL; |
|
59 | 59 | //If we cannot connect to Consul on start, we have a problem. |
60 | 60 | $this->createSession(); |
61 | 61 | $this->lastSuccessfullCheck = time(); |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | public function heartbeat() |
93 | 93 | { |
94 | 94 | //If we have last successfull check recently new, we don't have to do anything |
95 | - if ($this->lastSuccessfullCheck && time() - $this->lastSuccessfullCheck < $this->sessionTTL / 2 ) { |
|
95 | + if ($this->lastSuccessfullCheck && time()-$this->lastSuccessfullCheck < $this->sessionTTL / 2) { |
|
96 | 96 | return false; |
97 | 97 | } |
98 | 98 | //If session reneval succeedes, update last successfull check. |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | } catch (RuntimeException $e) { |
110 | 110 | //We could not create new session. We can work for some time in 'detached' mode, |
111 | 111 | //but if our TTL time runs out, we have to throw an exception. |
112 | - if (!$this->lastSuccessfullCheck || time() - $this->lastSuccessfullCheck >= $this->sessionTTL) { |
|
112 | + if (!$this->lastSuccessfullCheck || time()-$this->lastSuccessfullCheck >= $this->sessionTTL) { |
|
113 | 113 | throw $e; |
114 | 114 | } |
115 | 115 | return false; |
@@ -178,12 +178,12 @@ discard block |
||
178 | 178 | |
179 | 179 | private function createSession() |
180 | 180 | { |
181 | - $url ='/session/create'; |
|
181 | + $url = '/session/create'; |
|
182 | 182 | //We create new session with given TTL and with lock delay equal to half of TTL. |
183 | 183 | $payload = array( |
184 | 184 | 'TTL' => $this->sessionTTL.'s', |
185 | 185 | "Behavior" => "delete", |
186 | - 'LockDelay' => floor($this->sessionTTL/2).'s', |
|
186 | + 'LockDelay' => floor($this->sessionTTL / 2).'s', |
|
187 | 187 | ); |
188 | 188 | $returnData = $this->curl->performPutRequest($url, json_encode($payload)); |
189 | 189 | if (empty($returnData['ID'])) { |
@@ -147,8 +147,7 @@ |
||
147 | 147 | continue; |
148 | 148 | } elseif ($currentValue['Key'] == $this->sessionId) { |
149 | 149 | return base64_decode($currentValue['Value']); |
150 | - } |
|
151 | - else { |
|
150 | + } else { |
|
152 | 151 | $usedIds[] = base64_decode($currentValue['Value']); |
153 | 152 | } |
154 | 153 | } |