1 | <?php |
||
44 | class Session |
||
45 | { |
||
46 | // HTTP Client instance |
||
47 | protected $httpClient = null; |
||
48 | |||
49 | // Service URL to which client connects to |
||
50 | protected $vtigerUrl = null; |
||
51 | protected $wsBaseURL = null; |
||
52 | |||
53 | // Webservice login validity |
||
54 | private $serviceServerTime = null; |
||
55 | private $serviceExpireTime = null; |
||
56 | private $serviceToken = null; |
||
57 | |||
58 | // Vtiger CRM and WebServices API version |
||
59 | private $apiVersion = false; |
||
60 | private $vtigerVersion = false; |
||
61 | |||
62 | // Webservice user credentials |
||
63 | private $userName = null; |
||
64 | private $accessKey = null; |
||
65 | |||
66 | // Webservice login credentials |
||
67 | private $userID = null; |
||
68 | private $sessionName = null; |
||
69 | |||
70 | /** |
||
71 | * Class constructor |
||
72 | * @param string $vtigerUrl The URL of the remote WebServices server |
||
73 | * @param string [$wsBaseURL = 'webservice.php'] WebServices base URL appended to vTiger root URL |
||
74 | */ |
||
75 | public function __construct($vtigerUrl, $wsBaseURL = 'webservice.php') |
||
85 | |||
86 | /** |
||
87 | * Login to the server using username and VTiger access key token |
||
88 | * @access public |
||
89 | * @param string $username VTiger user name |
||
90 | * @param string $accessKey VTiger access key token (visible on user profile/settings page) |
||
91 | * @return boolean Returns true if login operation has been successful |
||
92 | */ |
||
93 | public function login($username, $accessKey) |
||
125 | |||
126 | /** |
||
127 | * Allows you to login using username and password instead of access key (works on some VTige forks) |
||
128 | * @access public |
||
129 | * @param string $username VTiger user name |
||
130 | * @param string $password VTiger password (used to access CRM using the standard login page) |
||
131 | * @param string $accessKey This parameter will be filled with user's VTiger access key |
||
132 | * @return boolean Returns true if login operation has been successful |
||
133 | */ |
||
134 | public function loginPassword($username, $password, &$accessKey = null) |
||
158 | |||
159 | /** |
||
160 | * Checks and performs a login operation if requried and repeats login if needed |
||
161 | * @access private |
||
162 | */ |
||
163 | public function checkLogin() |
||
170 | |||
171 | /** |
||
172 | * Gets a challenge token from the server and stores for future requests |
||
173 | * @access private |
||
174 | * @param string $username VTiger user name |
||
175 | * @return booleanReturns false in case of failure |
||
176 | */ |
||
177 | private function passChallenge($username) |
||
195 | |||
196 | /** |
||
197 | * Sends HTTP request to VTiger web service API endpoint |
||
198 | * @access private |
||
199 | * @param array $requestData HTTP request data |
||
200 | * @param string $method HTTP request method (GET, POST etc) |
||
201 | * @return array Returns request result object (null in case of failure) |
||
202 | */ |
||
203 | public function sendHttpRequest(array $requestData, $method = 'POST') |
||
243 | |||
244 | /** |
||
245 | * Cleans and fixes vTiger URL |
||
246 | * @access private |
||
247 | * @static |
||
248 | * @param string Base URL of vTiger CRM |
||
249 | * @return boolean Returns cleaned and fixed vTiger URL |
||
250 | */ |
||
251 | private static function fixVtigerBaseUrl($baseUrl) |
||
261 | |||
262 | /** |
||
263 | * Check if server response contains an error, therefore the requested operation has failed |
||
264 | * @access private |
||
265 | * @static |
||
266 | * @param array $jsonResult Server response object to check for errors |
||
267 | * @return boolean True if response object contains an error |
||
268 | */ |
||
269 | private static function checkForError(array $jsonResult) |
||
286 | } |
||
287 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: