@@ -11,7 +11,7 @@ |
||
11 | 11 | |
12 | 12 | abstract class AbstractPutEntryPoint extends AbstractEntryPoint { |
13 | 13 | |
14 | - public function __construct($url, array $options = array()) { |
|
14 | + public function __construct($url, array $options = array()){ |
|
15 | 15 | $this->setRequest(new PUT()); |
16 | 16 | $this->setResponse(new JSON($this->Request->getCurlObject())); |
17 | 17 | parent::__construct($url, $options); |
@@ -11,7 +11,7 @@ |
||
11 | 11 | |
12 | 12 | abstract class AbstractPutEntryPoint extends AbstractEntryPoint { |
13 | 13 | |
14 | - public function __construct($url, array $options = array()) { |
|
14 | + public function __construct($url, array $options = array()){ |
|
15 | 15 | $this->setRequest(new PUT()); |
16 | 16 | $this->setResponse(new JSON($this->Request->getCurlObject())); |
17 | 17 | parent::__construct($url, $options); |
@@ -11,7 +11,7 @@ |
||
11 | 11 | |
12 | 12 | abstract class AbstractPutEntryPoint extends AbstractEntryPoint { |
13 | 13 | |
14 | - public function __construct($url, array $options = array()) { |
|
14 | + public function __construct($url, array $options = array()){ |
|
15 | 15 | $this->setRequest(new PUT()); |
16 | 16 | $this->setResponse(new JSON($this->Request->getCurlObject())); |
17 | 17 | parent::__construct($url, $options); |
@@ -11,7 +11,7 @@ |
||
11 | 11 | |
12 | 12 | abstract class AbstractPutEntryPoint extends AbstractEntryPoint { |
13 | 13 | |
14 | - public function __construct($url, array $options = array()) { |
|
14 | + public function __construct($url, array $options = array()){ |
|
15 | 15 | $this->setRequest(new PUT()); |
16 | 16 | $this->setResponse(new JSON($this->Request->getCurlObject())); |
17 | 17 | parent::__construct($url, $options); |
@@ -11,7 +11,7 @@ |
||
11 | 11 | |
12 | 12 | abstract class AbstractPutEntryPoint extends AbstractEntryPoint { |
13 | 13 | |
14 | - public function __construct($url, array $options = array()) { |
|
14 | + public function __construct($url, array $options = array()){ |
|
15 | 15 | $this->setRequest(new PUT()); |
16 | 16 | $this->setResponse(new JSON($this->Request->getCurlObject())); |
17 | 17 | parent::__construct($url, $options); |
@@ -11,7 +11,7 @@ |
||
11 | 11 | |
12 | 12 | abstract class AbstractPutEntryPoint extends AbstractEntryPoint { |
13 | 13 | |
14 | - public function __construct($url, array $options = array()) { |
|
14 | + public function __construct($url, array $options = array()){ |
|
15 | 15 | $this->setRequest(new PUT()); |
16 | 16 | $this->setResponse(new JSON($this->Request->getCurlObject())); |
17 | 17 | parent::__construct($url, $options); |
@@ -9,7 +9,7 @@ |
||
9 | 9 | |
10 | 10 | protected $default_message = 'Unknown SDK Exception occurred.'; |
11 | 11 | |
12 | - public function __construct($message = '') { |
|
12 | + public function __construct($message = ''){ |
|
13 | 13 | if (empty($message)){ |
14 | 14 | $message = $this->default_message; |
15 | 15 | } |
@@ -9,7 +9,7 @@ |
||
9 | 9 | |
10 | 10 | protected $default_message = 'Unknown SDK Exception occurred.'; |
11 | 11 | |
12 | - public function __construct($message = '') { |
|
12 | + public function __construct($message = ''){ |
|
13 | 13 | if (empty($message)){ |
14 | 14 | $message = $this->default_message; |
15 | 15 | } |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | */ |
89 | 89 | protected $entryPoints = array(); |
90 | 90 | |
91 | - public function __construct($server = '',array $credentials = array()){ |
|
91 | + public function __construct($server = '', array $credentials = array()){ |
|
92 | 92 | $server = (empty($server)?$this->server:$server); |
93 | 93 | $this->setServer($server); |
94 | 94 | $credentials = (empty($credentials)?$this->credentials:$credentials); |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | * @inheritdoc |
101 | 101 | * @param string $server |
102 | 102 | */ |
103 | - public function setServer($server) { |
|
103 | + public function setServer($server){ |
|
104 | 104 | $this->server = $server; |
105 | 105 | $this->apiURL = Helpers::configureAPIURL($this->server); |
106 | 106 | return $this; |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | /** |
110 | 110 | * @inheritdoc |
111 | 111 | */ |
112 | - public function getAPIUrl() { |
|
112 | + public function getAPIUrl(){ |
|
113 | 113 | return $this->apiURL; |
114 | 114 | } |
115 | 115 | |
@@ -119,9 +119,9 @@ discard block |
||
119 | 119 | */ |
120 | 120 | public function setCredentials(array $credentials){ |
121 | 121 | $this->credentials = $credentials; |
122 | - if (isset($this->credentials['client_id'])) { |
|
122 | + if (isset($this->credentials['client_id'])){ |
|
123 | 123 | $token = static::getStoredToken($this->credentials['client_id']); |
124 | - if (!empty($token)) { |
|
124 | + if (!empty($token)){ |
|
125 | 125 | $this->setToken($token); |
126 | 126 | } |
127 | 127 | } |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | /** |
155 | 155 | * @inheritdoc |
156 | 156 | */ |
157 | - public function getServer() { |
|
157 | + public function getServer(){ |
|
158 | 158 | return $this->server; |
159 | 159 | } |
160 | 160 | |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | * @inheritdoc |
163 | 163 | */ |
164 | 164 | public function authenticated(){ |
165 | - return time() < $this->expiration; |
|
165 | + return time()<$this->expiration; |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
@@ -184,10 +184,10 @@ discard block |
||
184 | 184 | */ |
185 | 185 | public function registerEntryPoint($funcName, $className){ |
186 | 186 | $implements = class_implements($className); |
187 | - if (is_array($implements) && in_array('SugarAPI\SDK\EntryPoint\Interfaces\EPInterface',$implements)){ |
|
187 | + if (is_array($implements) && in_array('SugarAPI\SDK\EntryPoint\Interfaces\EPInterface', $implements)){ |
|
188 | 188 | $this->entryPoints[$funcName] = $className; |
189 | 189 | }else{ |
190 | - throw new EntryPointException($className,'Class must extend SugarAPI\SDK\EntryPoint\Interfaces\EPInterface'); |
|
190 | + throw new EntryPointException($className, 'Class must extend SugarAPI\SDK\EntryPoint\Interfaces\EPInterface'); |
|
191 | 191 | } |
192 | 192 | return $this; |
193 | 193 | } |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | } |
210 | 210 | return $EntryPoint; |
211 | 211 | }else{ |
212 | - throw new EntryPointException($name,'Unregistered EntryPoint'); |
|
212 | + throw new EntryPointException($name, 'Unregistered EntryPoint'); |
|
213 | 213 | } |
214 | 214 | } |
215 | 215 | |
@@ -217,16 +217,16 @@ discard block |
||
217 | 217 | * @inheritdoc |
218 | 218 | * @throws AuthenticationException - When Login request fails |
219 | 219 | */ |
220 | - public function login() { |
|
221 | - if (!empty($this->credentials)) { |
|
220 | + public function login(){ |
|
221 | + if (!empty($this->credentials)){ |
|
222 | 222 | $response = $this->oauth2Token()->execute($this->credentials)->getResponse(); |
223 | - if ($response->getStatus() == '200') { |
|
223 | + if ($response->getStatus()=='200'){ |
|
224 | 224 | $this->setToken($response->getBody(FALSE)); |
225 | 225 | static::storeToken($this->token, $this->credentials['client_id']); |
226 | 226 | return TRUE; |
227 | - } else { |
|
227 | + }else{ |
|
228 | 228 | $error = $response->getBody(); |
229 | - throw new AuthenticationException("Login Response [" . $error['error'] . "] " . $error['error_message']); |
|
229 | + throw new AuthenticationException("Login Response [".$error['error']."] ".$error['error_message']); |
|
230 | 230 | } |
231 | 231 | } |
232 | 232 | return FALSE; |
@@ -237,22 +237,22 @@ discard block |
||
237 | 237 | * @throws AuthenticationException - When Refresh Request fails |
238 | 238 | */ |
239 | 239 | public function refreshToken(){ |
240 | - if (isset($this->credentials['client_id'])&& |
|
241 | - isset($this->credentials['client_secret'])&& |
|
242 | - isset($this->token)) { |
|
240 | + if (isset($this->credentials['client_id']) && |
|
241 | + isset($this->credentials['client_secret']) && |
|
242 | + isset($this->token)){ |
|
243 | 243 | $refreshOptions = array( |
244 | 244 | 'client_id' => $this->credentials['client_id'], |
245 | 245 | 'client_secret' => $this->credentials['client_secret'], |
246 | 246 | 'refresh_token' => $this->token->refresh_token |
247 | 247 | ); |
248 | 248 | $response = $this->oauth2Refresh()->execute($refreshOptions)->getResponse(); |
249 | - if ($response->getStatus() == '200') { |
|
249 | + if ($response->getStatus()=='200'){ |
|
250 | 250 | $this->setToken($response->getBody(FALSE)); |
251 | 251 | static::storeToken($this->token, $this->credentials['client_id']); |
252 | 252 | return TRUE; |
253 | - } else { |
|
253 | + }else{ |
|
254 | 254 | $error = $response->getBody(); |
255 | - throw new AuthenticationException("Refresh Response [" . $error['error'] . "] " . $error['error_message']); |
|
255 | + throw new AuthenticationException("Refresh Response [".$error['error']."] ".$error['error_message']); |
|
256 | 256 | } |
257 | 257 | } |
258 | 258 | return FALSE; |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | * @inheritdoc |
282 | 282 | * @param \stdClass $token |
283 | 283 | */ |
284 | - public static function storeToken($token, $client_id) { |
|
284 | + public static function storeToken($token, $client_id){ |
|
285 | 285 | static::$_STORED_TOKENS[$client_id] = $token; |
286 | 286 | return TRUE; |
287 | 287 | } |
@@ -289,14 +289,14 @@ discard block |
||
289 | 289 | /** |
290 | 290 | * @inheritdoc |
291 | 291 | */ |
292 | - public static function getStoredToken($client_id) { |
|
292 | + public static function getStoredToken($client_id){ |
|
293 | 293 | return (isset(static::$_STORED_TOKENS[$client_id])?static::$_STORED_TOKENS[$client_id]:NULL); |
294 | 294 | } |
295 | 295 | |
296 | 296 | /** |
297 | 297 | * @inheritdoc |
298 | 298 | */ |
299 | - public static function removeStoredToken($client_id) { |
|
299 | + public static function removeStoredToken($client_id){ |
|
300 | 300 | unset(static::$_STORED_TOKENS[$client_id]); |
301 | 301 | return TRUE; |
302 | 302 | } |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | * @inheritdoc |
101 | 101 | * @param string $server |
102 | 102 | */ |
103 | - public function setServer($server) { |
|
103 | + public function setServer($server){ |
|
104 | 104 | $this->server = $server; |
105 | 105 | $this->apiURL = Helpers::configureAPIURL($this->server); |
106 | 106 | return $this; |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | /** |
110 | 110 | * @inheritdoc |
111 | 111 | */ |
112 | - public function getAPIUrl() { |
|
112 | + public function getAPIUrl(){ |
|
113 | 113 | return $this->apiURL; |
114 | 114 | } |
115 | 115 | |
@@ -119,9 +119,9 @@ discard block |
||
119 | 119 | */ |
120 | 120 | public function setCredentials(array $credentials){ |
121 | 121 | $this->credentials = $credentials; |
122 | - if (isset($this->credentials['client_id'])) { |
|
122 | + if (isset($this->credentials['client_id'])){ |
|
123 | 123 | $token = static::getStoredToken($this->credentials['client_id']); |
124 | - if (!empty($token)) { |
|
124 | + if (!empty($token)){ |
|
125 | 125 | $this->setToken($token); |
126 | 126 | } |
127 | 127 | } |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | /** |
155 | 155 | * @inheritdoc |
156 | 156 | */ |
157 | - public function getServer() { |
|
157 | + public function getServer(){ |
|
158 | 158 | return $this->server; |
159 | 159 | } |
160 | 160 | |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | $implements = class_implements($className); |
187 | 187 | if (is_array($implements) && in_array('SugarAPI\SDK\EntryPoint\Interfaces\EPInterface',$implements)){ |
188 | 188 | $this->entryPoints[$funcName] = $className; |
189 | - }else{ |
|
189 | + } else{ |
|
190 | 190 | throw new EntryPointException($className,'Class must extend SugarAPI\SDK\EntryPoint\Interfaces\EPInterface'); |
191 | 191 | } |
192 | 192 | return $this; |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | $EntryPoint->setAuth($this->token->access_token); |
209 | 209 | } |
210 | 210 | return $EntryPoint; |
211 | - }else{ |
|
211 | + } else{ |
|
212 | 212 | throw new EntryPointException($name,'Unregistered EntryPoint'); |
213 | 213 | } |
214 | 214 | } |
@@ -217,14 +217,14 @@ discard block |
||
217 | 217 | * @inheritdoc |
218 | 218 | * @throws AuthenticationException - When Login request fails |
219 | 219 | */ |
220 | - public function login() { |
|
221 | - if (!empty($this->credentials)) { |
|
220 | + public function login(){ |
|
221 | + if (!empty($this->credentials)){ |
|
222 | 222 | $response = $this->oauth2Token()->execute($this->credentials)->getResponse(); |
223 | - if ($response->getStatus() == '200') { |
|
223 | + if ($response->getStatus() == '200'){ |
|
224 | 224 | $this->setToken($response->getBody(FALSE)); |
225 | 225 | static::storeToken($this->token, $this->credentials['client_id']); |
226 | 226 | return TRUE; |
227 | - } else { |
|
227 | + } else{ |
|
228 | 228 | $error = $response->getBody(); |
229 | 229 | throw new AuthenticationException("Login Response [" . $error['error'] . "] " . $error['error_message']); |
230 | 230 | } |
@@ -239,18 +239,18 @@ discard block |
||
239 | 239 | public function refreshToken(){ |
240 | 240 | if (isset($this->credentials['client_id'])&& |
241 | 241 | isset($this->credentials['client_secret'])&& |
242 | - isset($this->token)) { |
|
242 | + isset($this->token)){ |
|
243 | 243 | $refreshOptions = array( |
244 | 244 | 'client_id' => $this->credentials['client_id'], |
245 | 245 | 'client_secret' => $this->credentials['client_secret'], |
246 | 246 | 'refresh_token' => $this->token->refresh_token |
247 | 247 | ); |
248 | 248 | $response = $this->oauth2Refresh()->execute($refreshOptions)->getResponse(); |
249 | - if ($response->getStatus() == '200') { |
|
249 | + if ($response->getStatus() == '200'){ |
|
250 | 250 | $this->setToken($response->getBody(FALSE)); |
251 | 251 | static::storeToken($this->token, $this->credentials['client_id']); |
252 | 252 | return TRUE; |
253 | - } else { |
|
253 | + } else{ |
|
254 | 254 | $error = $response->getBody(); |
255 | 255 | throw new AuthenticationException("Refresh Response [" . $error['error'] . "] " . $error['error_message']); |
256 | 256 | } |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | unset($this->token); |
270 | 270 | static::removeStoredToken($this->credentials['client_id']); |
271 | 271 | return TRUE; |
272 | - }else{ |
|
272 | + } else{ |
|
273 | 273 | $error = $response->getBody(); |
274 | 274 | throw new AuthenticationException("Logout Response [".$error['error']."] ".$error['message']); |
275 | 275 | } |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | * @inheritdoc |
282 | 282 | * @param \stdClass $token |
283 | 283 | */ |
284 | - public static function storeToken($token, $client_id) { |
|
284 | + public static function storeToken($token, $client_id){ |
|
285 | 285 | static::$_STORED_TOKENS[$client_id] = $token; |
286 | 286 | return TRUE; |
287 | 287 | } |
@@ -289,14 +289,14 @@ discard block |
||
289 | 289 | /** |
290 | 290 | * @inheritdoc |
291 | 291 | */ |
292 | - public static function getStoredToken($client_id) { |
|
292 | + public static function getStoredToken($client_id){ |
|
293 | 293 | return (isset(static::$_STORED_TOKENS[$client_id])?static::$_STORED_TOKENS[$client_id]:NULL); |
294 | 294 | } |
295 | 295 | |
296 | 296 | /** |
297 | 297 | * @inheritdoc |
298 | 298 | */ |
299 | - public static function removeStoredToken($client_id) { |
|
299 | + public static function removeStoredToken($client_id){ |
|
300 | 300 | unset(static::$_STORED_TOKENS[$client_id]); |
301 | 301 | return TRUE; |
302 | 302 | } |
@@ -125,6 +125,7 @@ discard block |
||
125 | 125 | |
126 | 126 | /** |
127 | 127 | * @inheritdoc |
128 | + * @param string $name |
|
128 | 129 | */ |
129 | 130 | public function addHeader($name, $value){ |
130 | 131 | $token = $name.": ".$value; |
@@ -158,6 +159,7 @@ discard block |
||
158 | 159 | |
159 | 160 | /** |
160 | 161 | * @inheritdoc |
162 | + * @param string $body |
|
161 | 163 | */ |
162 | 164 | public function setBody($body){ |
163 | 165 | $this->body = $body; |
@@ -226,10 +226,10 @@ |
||
226 | 226 | */ |
227 | 227 | protected function configureType(){ |
228 | 228 | switch ($this->type) { |
229 | - case 'POST': |
|
229 | + case 'POST': |
|
230 | 230 | $this->setOption(CURLOPT_POST, TRUE); |
231 | 231 | break; |
232 | - case 'DELETE': |
|
232 | + case 'DELETE': |
|
233 | 233 | case 'PUT': |
234 | 234 | $this->setOption(CURLOPT_CUSTOMREQUEST, $this->type); |
235 | 235 | break; |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | /** |
102 | 102 | * Always make sure to destroy Curl Resource |
103 | 103 | */ |
104 | - public function __destruct() { |
|
104 | + public function __destruct(){ |
|
105 | 105 | if ($this->status!==self::STATUS_CLOSED){ |
106 | 106 | curl_close($this->CurlRequest); |
107 | 107 | } |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | foreach ($array as $key => $value){ |
141 | 141 | if (is_numeric($key)){ |
142 | 142 | $this->headers[] = $value; |
143 | - }else { |
|
143 | + }else{ |
|
144 | 144 | $this->addHeader($key, $value); |
145 | 145 | } |
146 | 146 | } |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | /** |
192 | 192 | * @inheritdoc |
193 | 193 | */ |
194 | - public function getOptions() { |
|
194 | + public function getOptions(){ |
|
195 | 195 | return $this->options; |
196 | 196 | } |
197 | 197 | |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | * Configure the Curl Options based on Request Type |
226 | 226 | */ |
227 | 227 | protected function configureType(){ |
228 | - switch ($this->type) { |
|
228 | + switch ($this->type){ |
|
229 | 229 | case 'POST': |
230 | 230 | $this->setOption(CURLOPT_POST, TRUE); |
231 | 231 | break; |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | /** |
102 | 102 | * Always make sure to destroy Curl Resource |
103 | 103 | */ |
104 | - public function __destruct() { |
|
104 | + public function __destruct(){ |
|
105 | 105 | if ($this->status!==self::STATUS_CLOSED){ |
106 | 106 | curl_close($this->CurlRequest); |
107 | 107 | } |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | foreach ($array as $key => $value){ |
141 | 141 | if (is_numeric($key)){ |
142 | 142 | $this->headers[] = $value; |
143 | - }else { |
|
143 | + } else{ |
|
144 | 144 | $this->addHeader($key, $value); |
145 | 145 | } |
146 | 146 | } |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | /** |
192 | 192 | * @inheritdoc |
193 | 193 | */ |
194 | - public function getOptions() { |
|
194 | + public function getOptions(){ |
|
195 | 195 | return $this->options; |
196 | 196 | } |
197 | 197 | |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | * Configure the Curl Options based on Request Type |
226 | 226 | */ |
227 | 227 | protected function configureType(){ |
228 | - switch ($this->type) { |
|
228 | + switch ($this->type){ |
|
229 | 229 | case 'POST': |
230 | 230 | $this->setOption(CURLOPT_POST, TRUE); |
231 | 231 | break; |
@@ -45,14 +45,14 @@ discard block |
||
45 | 45 | */ |
46 | 46 | protected $info; |
47 | 47 | |
48 | - public function __construct($curlRequest,$curlResponse = NULL){ |
|
48 | + public function __construct($curlRequest, $curlResponse = NULL){ |
|
49 | 49 | $this->CurlRequest = $curlRequest; |
50 | 50 | if ($curlResponse!==NULL){ |
51 | 51 | $this->setCurlResponse($curlResponse); |
52 | 52 | } |
53 | 53 | } |
54 | 54 | |
55 | - public function setCurlResponse($curlResponse) { |
|
55 | + public function setCurlResponse($curlResponse){ |
|
56 | 56 | $this->extractInfo(); |
57 | 57 | if (!$this->error){ |
58 | 58 | $this->extractResponse($curlResponse); |
@@ -66,9 +66,9 @@ discard block |
||
66 | 66 | protected function extractInfo(){ |
67 | 67 | $this->info = curl_getinfo($this->CurlRequest); |
68 | 68 | $this->status = $this->info['http_code']; |
69 | - if (curl_errno($this->CurlRequest)!== CURLE_OK){ |
|
69 | + if (curl_errno($this->CurlRequest)!==CURLE_OK){ |
|
70 | 70 | $this->error = curl_error($this->CurlRequest); |
71 | - }else { |
|
71 | + }else{ |
|
72 | 72 | $this->error = FALSE; |
73 | 73 | } |
74 | 74 | } |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | } |
53 | 53 | } |
54 | 54 | |
55 | - public function setCurlResponse($curlResponse) { |
|
55 | + public function setCurlResponse($curlResponse){ |
|
56 | 56 | $this->extractInfo(); |
57 | 57 | if (!$this->error){ |
58 | 58 | $this->extractResponse($curlResponse); |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | $this->status = $this->info['http_code']; |
69 | 69 | if (curl_errno($this->CurlRequest)!== CURLE_OK){ |
70 | 70 | $this->error = curl_error($this->CurlRequest); |
71 | - }else { |
|
71 | + } else{ |
|
72 | 72 | $this->error = FALSE; |
73 | 73 | } |
74 | 74 | } |