@@ -7,11 +7,17 @@ |
||
7 | 7 | protected $defaultMessage = 'Unknown SugarAPI SDK Exception Occurred.'; |
8 | 8 | protected $failureCodes = array(); |
9 | 9 | |
10 | + /** |
|
11 | + * @param string $code |
|
12 | + */ |
|
10 | 13 | public function __construct($code) { |
11 | 14 | $message = $this->convertCode($code); |
12 | 15 | parent::__construct($message); |
13 | 16 | } |
14 | 17 | |
18 | + /** |
|
19 | + * @return string|null |
|
20 | + */ |
|
15 | 21 | protected function convertCode($code,$string=''){ |
16 | 22 | if (array_key_exists($code,$this->failureCodes)){ |
17 | 23 | return $this->failureCodes[$code]; |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | namespace SugarAPI\SDK\Exception\Abstracts; |
4 | 4 | |
5 | -abstract class AbstractException extends \Exception{ |
|
5 | +abstract class AbstractException extends \Exception { |
|
6 | 6 | |
7 | 7 | protected $defaultMessage = 'Unknown SugarAPI SDK Exception Occurred.'; |
8 | 8 | protected $failureCodes = array(); |
@@ -12,15 +12,15 @@ discard block |
||
12 | 12 | parent::__construct($message); |
13 | 13 | } |
14 | 14 | |
15 | - protected function convertCode($code,$string=''){ |
|
16 | - if (array_key_exists($code,$this->failureCodes)){ |
|
15 | + protected function convertCode($code, $string = '') { |
|
16 | + if (array_key_exists($code, $this->failureCodes)) { |
|
17 | 17 | return $this->failureCodes[$code]; |
18 | - }else{ |
|
18 | + }else { |
|
19 | 19 | return $this->defaultMessage; |
20 | 20 | } |
21 | 21 | } |
22 | 22 | |
23 | - public function __toString(){ |
|
23 | + public function __toString() { |
|
24 | 24 | return "SugarAPI SDK Exception [".$this->code." - ".$this->message."] occurred on ".$this->line." in ".$this->file; |
25 | 25 | } |
26 | 26 |
@@ -15,7 +15,7 @@ |
||
15 | 15 | protected function convertCode($code,$string=''){ |
16 | 16 | if (array_key_exists($code,$this->failureCodes)){ |
17 | 17 | return $this->failureCodes[$code]; |
18 | - }else{ |
|
18 | + } else{ |
|
19 | 19 | return $this->defaultMessage; |
20 | 20 | } |
21 | 21 | } |
@@ -166,7 +166,7 @@ |
||
166 | 166 | * @inheritdoc |
167 | 167 | */ |
168 | 168 | public function getResponse(){ |
169 | - return $this->CurlResponse; |
|
169 | + return $this->CurlResponse; |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | /** |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | |
5 | 5 | use SugarAPI\SDK\Request\Interfaces\RequestInterface; |
6 | 6 | |
7 | -abstract class AbstractRequest implements RequestInterface{ |
|
7 | +abstract class AbstractRequest implements RequestInterface { |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * The HTTP Request Type |
@@ -67,14 +67,14 @@ discard block |
||
67 | 67 | */ |
68 | 68 | protected $type; |
69 | 69 | |
70 | - public function __construct($url = null){ |
|
70 | + public function __construct($url = null) { |
|
71 | 71 | $this->start(); |
72 | - if (!empty($url)){ |
|
72 | + if (!empty($url)) { |
|
73 | 73 | $this->setURL($url); |
74 | 74 | } |
75 | 75 | $this->setType(); |
76 | - foreach(static::$_DEFAULT_OPTIONS as $option => $value){ |
|
77 | - $this->setOption($option,$value); |
|
76 | + foreach (static::$_DEFAULT_OPTIONS as $option => $value) { |
|
77 | + $this->setOption($option, $value); |
|
78 | 78 | } |
79 | 79 | } |
80 | 80 | |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | */ |
84 | 84 | public function setURL($url) { |
85 | 85 | $this->url = $url; |
86 | - $this->setOption(CURLOPT_URL,$this->url); |
|
86 | + $this->setOption(CURLOPT_URL, $this->url); |
|
87 | 87 | return $this; |
88 | 88 | } |
89 | 89 | |
@@ -165,22 +165,22 @@ discard block |
||
165 | 165 | /** |
166 | 166 | * @inheritdoc |
167 | 167 | */ |
168 | - public function getResponse(){ |
|
168 | + public function getResponse() { |
|
169 | 169 | return $this->CurlResponse; |
170 | 170 | } |
171 | 171 | |
172 | 172 | /** |
173 | 173 | * Set the Type on the Request |
174 | 174 | */ |
175 | - protected function setType(){ |
|
175 | + protected function setType() { |
|
176 | 176 | $this->type = static::$_TYPE; |
177 | 177 | } |
178 | 178 | |
179 | 179 | /** |
180 | 180 | * @inheritdoc |
181 | 181 | */ |
182 | - public function reset(){ |
|
183 | - if (is_object($this->CurlRequest)){ |
|
182 | + public function reset() { |
|
183 | + if (is_object($this->CurlRequest)) { |
|
184 | 184 | $this->close(); |
185 | 185 | } |
186 | 186 | $this->start(); |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | /** |
199 | 199 | * @inheritdoc |
200 | 200 | */ |
201 | - public function close(){ |
|
201 | + public function close() { |
|
202 | 202 | curl_close($this->CurlRequest); |
203 | 203 | unset($this->CurlRequest); |
204 | 204 | return $this; |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | |
5 | 5 | use SugarAPI\SDK\Request\Abstracts\AbstractRequest; |
6 | 6 | |
7 | -class POST extends AbstractRequest{ |
|
7 | +class POST extends AbstractRequest { |
|
8 | 8 | |
9 | 9 | protected static $_TYPE = 'POST'; |
10 | 10 | |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | * |
14 | 14 | * Set the Curl POST Option to True |
15 | 15 | */ |
16 | - protected function setType(){ |
|
16 | + protected function setType() { |
|
17 | 17 | parent::setType(); |
18 | 18 | $this->setOption(CURLOPT_POST, 1); |
19 | 19 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | |
5 | 5 | use SugarAPI\SDK\Request\Abstracts\AbstractRequest; |
6 | 6 | |
7 | -class DELETE extends AbstractRequest{ |
|
7 | +class DELETE extends AbstractRequest { |
|
8 | 8 | |
9 | 9 | protected static $_TYPE = 'DELETE'; |
10 | 10 | |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | * |
14 | 14 | * Set the Curl Custom Request Option to DELETE |
15 | 15 | */ |
16 | - protected function setType(){ |
|
16 | + protected function setType() { |
|
17 | 17 | parent::setType(); |
18 | 18 | $this->setOption(CURLOPT_CUSTOMREQUEST, "DELETE"); |
19 | 19 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | |
5 | 5 | use SugarAPI\SDK\Request\Abstracts\AbstractRequest; |
6 | 6 | |
7 | -class PUT extends AbstractRequest{ |
|
7 | +class PUT extends AbstractRequest { |
|
8 | 8 | |
9 | 9 | protected static $_TYPE = 'PUT'; |
10 | 10 | |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | * |
14 | 14 | * Set the Curl Custom Request Option to PUT |
15 | 15 | */ |
16 | - protected function setType(){ |
|
16 | + protected function setType() { |
|
17 | 17 | parent::setType(); |
18 | 18 | $this->setOption(CURLOPT_CUSTOMREQUEST, "PUT"); |
19 | 19 | } |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * @param $value - Header Value |
24 | 24 | * @return SugarAPI\SDK\Request Object |
25 | 25 | */ |
26 | - public function addHeader($name,$value); |
|
26 | + public function addHeader($name, $value); |
|
27 | 27 | |
28 | 28 | /** |
29 | 29 | * Sets the Headers on the Curl Request object, called during Sending. Appends to Request Headers property |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | * @param $value - Curl Option Value |
51 | 51 | * @return SugarAPI\SDK\Request Object |
52 | 52 | */ |
53 | - public function setOption($option,$value); |
|
53 | + public function setOption($option, $value); |
|
54 | 54 | |
55 | 55 | /** |
56 | 56 | * Set the URL on the Request Object |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | |
5 | 5 | use SugarAPI\SDK\Request\Abstracts\AbstractRequest; |
6 | 6 | |
7 | -class GET extends AbstractRequest{ |
|
7 | +class GET extends AbstractRequest { |
|
8 | 8 | |
9 | 9 | protected static $_TYPE = 'GET'; |
10 | 10 | |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | * |
14 | 14 | * Convert Body to Query String |
15 | 15 | */ |
16 | - public function setBody($body){ |
|
16 | + public function setBody($body) { |
|
17 | 17 | $this->body = http_build_query($body); |
18 | 18 | } |
19 | 19 | |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | * |
23 | 23 | * Configure the URL with Body since Payload is sent via Query String |
24 | 24 | */ |
25 | - public function send(){ |
|
25 | + public function send() { |
|
26 | 26 | $this->setURL($this->url."?".$this->body); |
27 | 27 | return parent::send(); |
28 | 28 | } |
@@ -28,93 +28,93 @@ |
||
28 | 28 | |
29 | 29 | private $entryPoints = array(); |
30 | 30 | |
31 | - public function __construct($instance='',array $authOptions = array()){ |
|
31 | + public function __construct($instance = '', array $authOptions = array()) { |
|
32 | 32 | $this->loadDefaults(); |
33 | - if (!empty($instance)){ |
|
33 | + if (!empty($instance)) { |
|
34 | 34 | $this->setInstance($instance); |
35 | 35 | } |
36 | - if (!empty($authOptions)){ |
|
36 | + if (!empty($authOptions)) { |
|
37 | 37 | $this->configureAuth($authOptions); |
38 | 38 | } |
39 | 39 | $this->registerEntryPoints(); |
40 | 40 | } |
41 | 41 | |
42 | - protected function loadDefaults(){ |
|
43 | - include __DIR__ .DIRECTORY_SEPARATOR.'defaults.php'; |
|
42 | + protected function loadDefaults() { |
|
43 | + include __DIR__.DIRECTORY_SEPARATOR.'defaults.php'; |
|
44 | 44 | if (isset($defaults)) { |
45 | 45 | static::$_DEFAULTS = $defaults; |
46 | - if (isset($defaults['instance'])){ |
|
46 | + if (isset($defaults['instance'])) { |
|
47 | 47 | $this->setInstance($defaults['instance']); |
48 | 48 | } |
49 | - if (isset($defaults['auth']) && is_array($defaults['auth'])){ |
|
49 | + if (isset($defaults['auth']) && is_array($defaults['auth'])) { |
|
50 | 50 | $this->configureAuth($defaults['auth']); |
51 | 51 | } |
52 | 52 | } |
53 | 53 | } |
54 | 54 | |
55 | - public function configureAuth(array $options){ |
|
56 | - foreach($this->authOptions as $key => $value){ |
|
57 | - if (isset($options[$key])){ |
|
55 | + public function configureAuth(array $options) { |
|
56 | + foreach ($this->authOptions as $key => $value) { |
|
57 | + if (isset($options[$key])) { |
|
58 | 58 | $this->authOptions[$key] = $options[$key]; |
59 | 59 | } |
60 | 60 | } |
61 | 61 | } |
62 | 62 | |
63 | - protected function registerEntryPoints(){ |
|
64 | - require __DIR__ .DIRECTORY_SEPARATOR.'EntryPoint' .DIRECTORY_SEPARATOR.'registry.php'; |
|
65 | - if (isset($entryPoints)){ |
|
63 | + protected function registerEntryPoints() { |
|
64 | + require __DIR__.DIRECTORY_SEPARATOR.'EntryPoint'.DIRECTORY_SEPARATOR.'registry.php'; |
|
65 | + if (isset($entryPoints)) { |
|
66 | 66 | $this->entryPoints = $entryPoints; |
67 | - }else{ |
|
67 | + }else { |
|
68 | 68 | throw new InitializationFailure('no_ep_registry'); |
69 | 69 | } |
70 | 70 | } |
71 | 71 | |
72 | - public function __call($name,$params){ |
|
73 | - if (array_key_exists($name,$this->entryPoints)){ |
|
72 | + public function __call($name, $params) { |
|
73 | + if (array_key_exists($name, $this->entryPoints)) { |
|
74 | 74 | $className = "SugarAPI\\SDK\\EntryPoint\\".$this->entryPoints[$name]; |
75 | - $EntryPoint = new $className($this->url,$params); |
|
75 | + $EntryPoint = new $className($this->url, $params); |
|
76 | 76 | |
77 | - if ($EntryPoint->authRequired()){ |
|
77 | + if ($EntryPoint->authRequired()) { |
|
78 | 78 | if (isset($this->authToken)) { |
79 | 79 | $EntryPoint->getRequest()->addHeader('OAuth-Token', $this->authToken->access_token); |
80 | - }else{ |
|
80 | + }else { |
|
81 | 81 | throw new AuthenticationError('no_auth'); |
82 | 82 | } |
83 | 83 | } |
84 | 84 | return $EntryPoint; |
85 | - }else{ |
|
85 | + }else { |
|
86 | 86 | throw new InvalidEntryPoint('invalid_ep'); |
87 | 87 | } |
88 | 88 | } |
89 | - public function login(){ |
|
90 | - if (empty($this->authOptions['username']) || empty($this->authOptions['password'])){ |
|
89 | + public function login() { |
|
90 | + if (empty($this->authOptions['username']) || empty($this->authOptions['password'])) { |
|
91 | 91 | throw new AuthenticationError('missing_user_pass'); |
92 | 92 | } |
93 | 93 | $EP = $this->accessToken(); |
94 | 94 | $response = $EP->data($this->authOptions)->execute()->getResponse(); |
95 | - if ($response->getStatus()=='200'){ |
|
95 | + if ($response->getStatus()=='200') { |
|
96 | 96 | $this->authToken = $response->getBody(); |
97 | - }else{ |
|
97 | + }else { |
|
98 | 98 | throw new AuthenticationError('failed_auth'); |
99 | 99 | } |
100 | 100 | } |
101 | - public function setInstance($instance){ |
|
102 | - if (strpos("https",$instance)!==FALSE){ |
|
101 | + public function setInstance($instance) { |
|
102 | + if (strpos("https", $instance)!==FALSE) { |
|
103 | 103 | $this->secure = TRUE; |
104 | 104 | } |
105 | - if (strpos("http",$instance)===FALSE){ |
|
105 | + if (strpos("http", $instance)===FALSE) { |
|
106 | 106 | $instance = "http://".$instance; |
107 | 107 | } |
108 | - if (strpos("rest/v10",$instance)!==FALSE){ |
|
109 | - $instance = str_replace("rest/v10","",$instance); |
|
108 | + if (strpos("rest/v10", $instance)!==FALSE) { |
|
109 | + $instance = str_replace("rest/v10", "", $instance); |
|
110 | 110 | } |
111 | 111 | $this->instance = $instance; |
112 | - $this->url = rtrim($this->instance,"/").self::API_URL; |
|
112 | + $this->url = rtrim($this->instance, "/").self::API_URL; |
|
113 | 113 | } |
114 | - public function getURL(){ |
|
114 | + public function getURL() { |
|
115 | 115 | return $this->url; |
116 | 116 | } |
117 | - public function getToken(){ |
|
117 | + public function getToken() { |
|
118 | 118 | return $this->authToken; |
119 | 119 | } |
120 | 120 | } |
121 | 121 | \ No newline at end of file |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | require __DIR__ .DIRECTORY_SEPARATOR.'EntryPoint' .DIRECTORY_SEPARATOR.'registry.php'; |
65 | 65 | if (isset($entryPoints)){ |
66 | 66 | $this->entryPoints = $entryPoints; |
67 | - }else{ |
|
67 | + } else{ |
|
68 | 68 | throw new InitializationFailure('no_ep_registry'); |
69 | 69 | } |
70 | 70 | } |
@@ -77,12 +77,12 @@ discard block |
||
77 | 77 | if ($EntryPoint->authRequired()){ |
78 | 78 | if (isset($this->authToken)) { |
79 | 79 | $EntryPoint->getRequest()->addHeader('OAuth-Token', $this->authToken->access_token); |
80 | - }else{ |
|
80 | + } else{ |
|
81 | 81 | throw new AuthenticationError('no_auth'); |
82 | 82 | } |
83 | 83 | } |
84 | 84 | return $EntryPoint; |
85 | - }else{ |
|
85 | + } else{ |
|
86 | 86 | throw new InvalidEntryPoint('invalid_ep'); |
87 | 87 | } |
88 | 88 | } |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | $response = $EP->data($this->authOptions)->execute()->getResponse(); |
95 | 95 | if ($response->getStatus()=='200'){ |
96 | 96 | $this->authToken = $response->getBody(); |
97 | - }else{ |
|
97 | + } else{ |
|
98 | 98 | throw new AuthenticationError('failed_auth'); |
99 | 99 | } |
100 | 100 | } |
@@ -4,26 +4,26 @@ discard block |
||
4 | 4 | |
5 | 5 | use SugarAPI\SDK\Response\Interfaces\ResponseInterface; |
6 | 6 | |
7 | -abstract class AbstractResponse implements ResponseInterface{ |
|
7 | +abstract class AbstractResponse implements ResponseInterface { |
|
8 | 8 | |
9 | 9 | protected $headers; |
10 | 10 | protected $body; |
11 | 11 | protected $status; |
12 | 12 | |
13 | - public function __construct($curlResponse,$curlRequest){ |
|
14 | - $header_size = curl_getinfo($curlRequest,CURLINFO_HEADER_SIZE); |
|
13 | + public function __construct($curlResponse, $curlRequest) { |
|
14 | + $header_size = curl_getinfo($curlRequest, CURLINFO_HEADER_SIZE); |
|
15 | 15 | $this->headers = substr($curlResponse, 0, $header_size); |
16 | 16 | $this->body = json_decode(substr($curlResponse, $header_size)); |
17 | - $this->status = curl_getinfo($curlRequest,CURLINFO_HTTP_CODE); |
|
17 | + $this->status = curl_getinfo($curlRequest, CURLINFO_HTTP_CODE); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | /** |
21 | 21 | * @inheritdoc |
22 | 22 | */ |
23 | - public function json($pretty = false){ |
|
24 | - if ($pretty){ |
|
25 | - return json_encode($this->body,JSON_PRETTY_PRINT); |
|
26 | - }else{ |
|
23 | + public function json($pretty = false) { |
|
24 | + if ($pretty) { |
|
25 | + return json_encode($this->body, JSON_PRETTY_PRINT); |
|
26 | + }else { |
|
27 | 27 | return json_encode($this->body); |
28 | 28 | } |
29 | 29 | } |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | /** |
32 | 32 | * @inheritdoc |
33 | 33 | */ |
34 | - public function getStatus(){ |
|
34 | + public function getStatus() { |
|
35 | 35 | return $this->status; |
36 | 36 | } |
37 | 37 |
@@ -15,7 +15,7 @@ |
||
15 | 15 | protected function convertCode($code,$string=''){ |
16 | 16 | if (array_key_exists($code,$this->failureCodes)){ |
17 | 17 | return $this->failureCodes[$code]; |
18 | - }else{ |
|
18 | + } else{ |
|
19 | 19 | return $this->defaultMessage; |
20 | 20 | } |
21 | 21 | } |