@@ -133,6 +133,7 @@ |
||
| 133 | 133 | |
| 134 | 134 | /** |
| 135 | 135 | * @inheritdoc |
| 136 | + * @param string $body |
|
| 136 | 137 | */ |
| 137 | 138 | public function setBody($body) { |
| 138 | 139 | $this->body = $body; |
@@ -90,7 +90,7 @@ |
||
| 90 | 90 | /** |
| 91 | 91 | * Always make sure to destroy Curl Resource |
| 92 | 92 | */ |
| 93 | - public function __destruct() { |
|
| 93 | + public function __destruct(){ |
|
| 94 | 94 | if ($this->status!==self::STATUS_CLOSED){ |
| 95 | 95 | curl_close($this->CurlRequest); |
| 96 | 96 | } |
@@ -4,7 +4,7 @@ |
||
| 4 | 4 | |
| 5 | 5 | class EntryPointException extends SDKException { |
| 6 | 6 | |
| 7 | - public function __construct($message) { |
|
| 7 | + public function __construct($message){ |
|
| 8 | 8 | parent::__construct($message); |
| 9 | 9 | } |
| 10 | 10 | |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | * @param $EntryPoint - EPInterface Class Name |
| 32 | 32 | * @return $this |
| 33 | 33 | */ |
| 34 | - public function registerEntryPoint($function,$EntryPoint); |
|
| 34 | + public function registerEntryPoint($function, $EntryPoint); |
|
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | 37 | * Login to the configured SugarCRM server |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | * @param $client_id |
| 58 | 58 | * @return boolean |
| 59 | 59 | */ |
| 60 | - public static function storeToken($token,$client_id); |
|
| 60 | + public static function storeToken($token, $client_id); |
|
| 61 | 61 | |
| 62 | 62 | /** |
| 63 | 63 | * Get an SDK Clients authentication Token from Storage |
@@ -15,10 +15,10 @@ discard block |
||
| 15 | 15 | * @return string |
| 16 | 16 | */ |
| 17 | 17 | public static function configureAPIURL($instance){ |
| 18 | - if (strpos($instance,"http")===FALSE){ |
|
| 18 | + if (strpos($instance, "http")===FALSE){ |
|
| 19 | 19 | $instance = "http://".$instance; |
| 20 | 20 | } |
| 21 | - if (strpos($instance,"rest/v10")!==FALSE){ |
|
| 21 | + if (strpos($instance, "rest/v10")!==FALSE){ |
|
| 22 | 22 | $instance = str_replace("rest/v10", "", $instance); |
| 23 | 23 | } |
| 24 | 24 | return rtrim($instance, "/").self::API_URL; |
@@ -39,8 +39,8 @@ discard block |
||
| 39 | 39 | public static function getSDKEntryPointRegistry(){ |
| 40 | 40 | $entryPoints = array(); |
| 41 | 41 | require __DIR__.DIRECTORY_SEPARATOR.'registry.php'; |
| 42 | - foreach ($entryPoints as $funcName => $className) { |
|
| 43 | - $className = "SugarAPI\\SDK\\EntryPoint\\" . $className; |
|
| 42 | + foreach ($entryPoints as $funcName => $className){ |
|
| 43 | + $className = "SugarAPI\\SDK\\EntryPoint\\".$className; |
|
| 44 | 44 | $entryPoints[$funcName] = $className; |
| 45 | 45 | } |
| 46 | 46 | return $entryPoints; |
@@ -8,14 +8,14 @@ |
||
| 8 | 8 | |
| 9 | 9 | abstract class AbstractPostFileEntryPoint extends AbstractEntryPoint { |
| 10 | 10 | |
| 11 | - public function __construct($url, array $options = array()) { |
|
| 11 | + public function __construct($url, array $options = array()){ |
|
| 12 | 12 | $this->setRequest(new POSTFile()); |
| 13 | 13 | parent::__construct($url, $options); |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | - public function execute($data = null) { |
|
| 16 | + public function execute($data = null){ |
|
| 17 | 17 | parent::execute($data); |
| 18 | - $this->setResponse(new JSON($this->Request->getResponse(),$this->Request->getCurlObject())); |
|
| 18 | + $this->setResponse(new JSON($this->Request->getResponse(), $this->Request->getCurlObject())); |
|
| 19 | 19 | return $this; |
| 20 | 20 | } |
| 21 | 21 | |
@@ -8,14 +8,14 @@ |
||
| 8 | 8 | |
| 9 | 9 | abstract class AbstractPostFileEntryPoint extends AbstractEntryPoint { |
| 10 | 10 | |
| 11 | - public function __construct($url, array $options = array()) { |
|
| 11 | + public function __construct($url, array $options = array()){ |
|
| 12 | 12 | $this->setRequest(new POSTFile()); |
| 13 | 13 | parent::__construct($url, $options); |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | - public function execute($data = null) { |
|
| 16 | + public function execute($data = null){ |
|
| 17 | 17 | parent::execute($data); |
| 18 | - $this->setResponse(new JSON($this->Request->getResponse(),$this->Request->getCurlObject())); |
|
| 18 | + $this->setResponse(new JSON($this->Request->getResponse(), $this->Request->getCurlObject())); |
|
| 19 | 19 | return $this; |
| 20 | 20 | } |
| 21 | 21 | |
@@ -8,14 +8,14 @@ |
||
| 8 | 8 | |
| 9 | 9 | abstract class AbstractPostFileEntryPoint extends AbstractEntryPoint { |
| 10 | 10 | |
| 11 | - public function __construct($url, array $options = array()) { |
|
| 11 | + public function __construct($url, array $options = array()){ |
|
| 12 | 12 | $this->setRequest(new POSTFile()); |
| 13 | 13 | parent::__construct($url, $options); |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | - public function execute($data = null) { |
|
| 16 | + public function execute($data = null){ |
|
| 17 | 17 | parent::execute($data); |
| 18 | - $this->setResponse(new JSON($this->Request->getResponse(),$this->Request->getCurlObject())); |
|
| 18 | + $this->setResponse(new JSON($this->Request->getResponse(), $this->Request->getCurlObject())); |
|
| 19 | 19 | return $this; |
| 20 | 20 | } |
| 21 | 21 | |
@@ -151,7 +151,7 @@ |
||
| 151 | 151 | /** |
| 152 | 152 | * @param $funcName |
| 153 | 153 | * @param $className |
| 154 | - * @return bool |
|
| 154 | + * @return AbstractClient |
|
| 155 | 155 | * @throws EntryPointException |
| 156 | 156 | */ |
| 157 | 157 | public function registerEntryPoint($funcName, $className){ |
@@ -60,9 +60,9 @@ discard block |
||
| 60 | 60 | */ |
| 61 | 61 | protected $entryPoints = array(); |
| 62 | 62 | |
| 63 | - public function __construct($server = '',array $credentials = array()){ |
|
| 63 | + public function __construct($server = '', array $credentials = array()){ |
|
| 64 | 64 | $server = (empty($server)?$this->server:$server); |
| 65 | - if (!empty($server)) { |
|
| 65 | + if (!empty($server)){ |
|
| 66 | 66 | $this->setServer($server); |
| 67 | 67 | } |
| 68 | 68 | $credentials = (empty($credentials)?$this->credentials:$credentials); |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | * @inheritdoc |
| 77 | 77 | * @param string $server |
| 78 | 78 | */ |
| 79 | - public function setServer($server) { |
|
| 79 | + public function setServer($server){ |
|
| 80 | 80 | $this->server = $server; |
| 81 | 81 | $this->apiURL = Helpers::configureAPIURL($this->server); |
| 82 | 82 | return $this; |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | /** |
| 86 | 86 | * @inheritdoc |
| 87 | 87 | */ |
| 88 | - public function getAPIUrl() { |
|
| 88 | + public function getAPIUrl(){ |
|
| 89 | 89 | return $this->apiURL; |
| 90 | 90 | } |
| 91 | 91 | |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | /** |
| 129 | 129 | * @inheritdoc |
| 130 | 130 | */ |
| 131 | - public function getServer() { |
|
| 131 | + public function getServer(){ |
|
| 132 | 132 | return $this->server; |
| 133 | 133 | } |
| 134 | 134 | |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | * @inheritdoc |
| 137 | 137 | */ |
| 138 | 138 | public function authenticated(){ |
| 139 | - return time() < $this->expiration; |
|
| 139 | + return time()<$this->expiration; |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | /** |
@@ -158,10 +158,10 @@ discard block |
||
| 158 | 158 | */ |
| 159 | 159 | public function registerEntryPoint($funcName, $className){ |
| 160 | 160 | $implements = class_implements($className); |
| 161 | - if (is_array($implements) && in_array('SugarAPI\SDK\EntryPoint\Interfaces\EPInterface',$implements)){ |
|
| 161 | + if (is_array($implements) && in_array('SugarAPI\SDK\EntryPoint\Interfaces\EPInterface', $implements)){ |
|
| 162 | 162 | $this->entryPoints[$funcName] = $className; |
| 163 | 163 | }else{ |
| 164 | - throw new EntryPointException($className,'Class must extend SugarAPI\SDK\EntryPoint\Interfaces\EPInterface'); |
|
| 164 | + throw new EntryPointException($className, 'Class must extend SugarAPI\SDK\EntryPoint\Interfaces\EPInterface'); |
|
| 165 | 165 | } |
| 166 | 166 | return $this; |
| 167 | 167 | } |
@@ -179,13 +179,13 @@ discard block |
||
| 179 | 179 | $EntryPoint = new $Class($this->apiURL, $params); |
| 180 | 180 | |
| 181 | 181 | if ($EntryPoint->authRequired()){ |
| 182 | - if (isset($this->token) && $this->authenticated()) { |
|
| 182 | + if (isset($this->token) && $this->authenticated()){ |
|
| 183 | 183 | $EntryPoint->setAuth($this->getToken()->access_token); |
| 184 | 184 | } |
| 185 | 185 | } |
| 186 | 186 | return $EntryPoint; |
| 187 | 187 | }else{ |
| 188 | - throw new EntryPointException($name,'Unregistered EntryPoint'); |
|
| 188 | + throw new EntryPointException($name, 'Unregistered EntryPoint'); |
|
| 189 | 189 | } |
| 190 | 190 | } |
| 191 | 191 | |
@@ -193,13 +193,13 @@ discard block |
||
| 193 | 193 | * @inheritdoc |
| 194 | 194 | * @throws AuthenticationException - When Login request fails |
| 195 | 195 | */ |
| 196 | - public function login() { |
|
| 196 | + public function login(){ |
|
| 197 | 197 | $EP = new OAuth2Token($this->apiURL); |
| 198 | 198 | $response = $EP->execute($this->credentials)->getResponse(); |
| 199 | 199 | if ($response->getStatus()=='200'){ |
| 200 | 200 | $this->setToken($response->getBody(FALSE)); |
| 201 | - static::storeToken($this->token,$this->credentials['client_id']); |
|
| 202 | - } else { |
|
| 201 | + static::storeToken($this->token, $this->credentials['client_id']); |
|
| 202 | + }else{ |
|
| 203 | 203 | $error = $response->getBody(); |
| 204 | 204 | throw new AuthenticationException("Login Response [".$error['error']."] ".$error['error_message']); |
| 205 | 205 | } |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | $response = $EP->execute($refreshOptions)->getResponse(); |
| 221 | 221 | if ($response->getStatus()=='200'){ |
| 222 | 222 | $this->setToken($response->getBody(FALSE)); |
| 223 | - static::storeToken($this->token,$this->credentials['client_id']); |
|
| 223 | + static::storeToken($this->token, $this->credentials['client_id']); |
|
| 224 | 224 | }else{ |
| 225 | 225 | $error = $response->getBody(); |
| 226 | 226 | throw new AuthenticationException("Refresh Response [".$error['error']."] ".$error['error_message']); |
@@ -251,7 +251,7 @@ discard block |
||
| 251 | 251 | * @inheritdoc |
| 252 | 252 | * @param \stdClass $token |
| 253 | 253 | */ |
| 254 | - public static function storeToken($token, $client_id) { |
|
| 254 | + public static function storeToken($token, $client_id){ |
|
| 255 | 255 | static::$_STORED_TOKENS[$client_id] = $token; |
| 256 | 256 | return TRUE; |
| 257 | 257 | } |
@@ -259,14 +259,14 @@ discard block |
||
| 259 | 259 | /** |
| 260 | 260 | * @inheritdoc |
| 261 | 261 | */ |
| 262 | - public static function getStoredToken($client_id) { |
|
| 262 | + public static function getStoredToken($client_id){ |
|
| 263 | 263 | return (isset(static::$_STORED_TOKENS[$client_id])?static::$_STORED_TOKENS[$client_id]:NULL); |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | /** |
| 267 | 267 | * @inheritdoc |
| 268 | 268 | */ |
| 269 | - public static function removeStoredToken($client_id) { |
|
| 269 | + public static function removeStoredToken($client_id){ |
|
| 270 | 270 | unset(static::$_STORED_TOKENS[$client_id]); |
| 271 | 271 | return TRUE; |
| 272 | 272 | } |
@@ -9,14 +9,14 @@ |
||
| 9 | 9 | |
| 10 | 10 | abstract class AbstractDeleteEntryPoint extends AbstractEntryPoint { |
| 11 | 11 | |
| 12 | - public function __construct($url, array $options = array()) { |
|
| 12 | + public function __construct($url, array $options = array()){ |
|
| 13 | 13 | $this->setRequest(new DELETE()); |
| 14 | 14 | parent::__construct($url, $options); |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | - public function execute($data = NULL) { |
|
| 17 | + public function execute($data = NULL){ |
|
| 18 | 18 | parent::execute($data); |
| 19 | - $this->setResponse(new JSON($this->Request->getResponse(),$this->Request->getCurlObject())); |
|
| 19 | + $this->setResponse(new JSON($this->Request->getResponse(), $this->Request->getCurlObject())); |
|
| 20 | 20 | return $this; |
| 21 | 21 | } |
| 22 | 22 | |