1 | <?php |
||
8 | class SugarAPI { |
||
9 | |||
10 | const API_URL = '/rest/v10/'; |
||
11 | |||
12 | /** |
||
13 | * Default Settings for SugarAPI Object. |
||
14 | * Includes Default Instance, and Default Authentication Ooptions |
||
15 | * Example: |
||
16 | * array( |
||
17 | * 'instance' => 'localhost', |
||
18 | * 'auth' => array( |
||
19 | * 'username' => 'admin', |
||
20 | * 'password' => 'password', |
||
21 | * 'client_id' => 'custom_client', |
||
22 | * 'client_secret' => 's3cr3t', |
||
23 | * 'platform' => 'custom_app' |
||
24 | * ) |
||
25 | * ); |
||
26 | * @var array |
||
27 | */ |
||
28 | protected static $_DEFAULTS = array(); |
||
29 | |||
30 | /** |
||
31 | * The configured instance |
||
32 | * @var |
||
33 | */ |
||
34 | protected $instance; |
||
35 | |||
36 | /** |
||
37 | * The configured Rest v10 URL |
||
38 | * @var |
||
39 | */ |
||
40 | protected $url; |
||
41 | |||
42 | /** |
||
43 | * The configured Authentication options |
||
44 | * @var array |
||
45 | */ |
||
46 | protected $authOptions = array( |
||
47 | 'username' => '', |
||
48 | 'password' => '', |
||
49 | 'client_id' => '', |
||
50 | 'client_secret' => '', |
||
51 | 'platform' => '' |
||
52 | ); |
||
53 | |||
54 | /** |
||
55 | * The authentication token, after successful login to SugarAPI |
||
56 | * @var |
||
57 | */ |
||
58 | protected $authToken; |
||
59 | |||
60 | /** |
||
61 | * The time in which Auth Token expires, and needs to be refreshed |
||
62 | * @var |
||
63 | */ |
||
64 | protected $authExpiration; |
||
65 | |||
66 | /** |
||
67 | * The list of registered EntryPoints |
||
68 | * @var array |
||
69 | */ |
||
70 | private $entryPoints = array(); |
||
71 | |||
72 | public function __construct($instance = '', array $authOptions = array()){ |
||
82 | |||
83 | /** |
||
84 | * Configure the static property $_DEFAULTS with settings from defaults.php |
||
85 | */ |
||
86 | protected function loadDefaults(){ |
||
100 | |||
101 | /** |
||
102 | * Configure the Authentication Options being used by SugarAPI Object |
||
103 | * @param array $options |
||
104 | */ |
||
105 | public function setAuthOptions(array $options){ |
||
112 | |||
113 | /** |
||
114 | * Register the defined EntryPoints in SDK, located in src/EntryPoint/registry.php file |
||
115 | * @throws SDKException |
||
116 | */ |
||
117 | protected function registerSDKEntryPoints(){ |
||
124 | |||
125 | /** |
||
126 | * Register an EntryPoint method on the SugarAPI object. |
||
127 | * Allows for loading custom EntryPoints, so long as custom EntryPoints are autoloaded accordingly |
||
128 | * @param $funcName - name of Method to be called on SugarAPI Object |
||
129 | * @param $className - full name of EntryPoint Class that will be utilized |
||
130 | * @throws SDKException |
||
131 | */ |
||
132 | public function registerEntryPoint($funcName, $className){ |
||
138 | |||
139 | /** |
||
140 | * Generates the EntryPoint objects based on the Method name that was called |
||
141 | * @param $name |
||
142 | * @param $params |
||
143 | * @return mixed |
||
144 | * @throws AuthenticationException |
||
145 | * @throws SDKException |
||
146 | */ |
||
147 | public function __call($name, $params){ |
||
167 | |||
168 | /** |
||
169 | * Login to the configured SugarCRM instance, and stored the Auth Token |
||
170 | * @throws AuthenticationException |
||
171 | */ |
||
172 | public function login(){ |
||
183 | |||
184 | /** |
||
185 | * Set the current AuthToken and Auth Expiration properties |
||
186 | * @param stdObject $token |
||
187 | */ |
||
188 | protected function setAuthToken($token){ |
||
192 | |||
193 | /** |
||
194 | * Refresh Auth Token to further API use |
||
195 | */ |
||
196 | public function refreshAuth(){ |
||
209 | |||
210 | /** |
||
211 | * Check if current access token is expired |
||
212 | * @return bool |
||
213 | */ |
||
214 | public function authExpired(){ |
||
217 | |||
218 | /** |
||
219 | * Force Logout of SugarAPI Object |
||
220 | */ |
||
221 | public function logout(){ |
||
230 | |||
231 | /** |
||
232 | * Configure the instance that the SugarAPI object will be communicating with |
||
233 | * @param $instance |
||
234 | */ |
||
235 | public function setInstance($instance){ |
||
245 | |||
246 | /** |
||
247 | * Get the configured Rest v10 URL |
||
248 | * @return mixed |
||
249 | */ |
||
250 | public function getURL(){ |
||
253 | |||
254 | /** |
||
255 | * Get the Authentication Token |
||
256 | * @return mixed |
||
257 | */ |
||
258 | public function getToken(){ |
||
261 | |||
262 | /** |
||
263 | * Get the configured Authentication Options |
||
264 | * @return array |
||
265 | */ |
||
266 | public function getAuthOptions(){ |
||
269 | } |
This check looks for calls to
isset(...)
orempty()
on variables that are yet undefined. These calls will always produce the same result and can be removed.This is most likely caused by the renaming of a variable or the removal of a function/method parameter.