13 * to license@zend.com so we can send you a copy immediately. |
13 * to license@zend.com so we can send you a copy immediately. |
14 * |
14 * |
15 * @category Zend |
15 * @category Zend |
16 * @package Zend_Service |
16 * @package Zend_Service |
17 * @subpackage LiveDocx |
17 * @subpackage LiveDocx |
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
18 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
20 * @version $Id: LiveDocx.php 23022 2010-10-05 15:30:55Z jonathan_maron $ |
20 * @version $Id: LiveDocx.php 25024 2012-07-30 15:08:15Z rob $ |
21 */ |
21 */ |
22 |
22 |
23 /** |
23 /** |
24 * @category Zend |
24 * @category Zend |
25 * @package Zend_Service |
25 * @package Zend_Service |
26 * @subpackage LiveDocx |
26 * @subpackage LiveDocx |
27 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
27 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
28 * @license http://framework.zend.com/license/new-bsd New BSD License |
28 * @license http://framework.zend.com/license/new-bsd New BSD License |
29 * @since LiveDocx 1.0 |
29 * @since LiveDocx 1.0 |
30 */ |
30 */ |
31 class Zend_Service_LiveDocx |
31 class Zend_Service_LiveDocx |
32 { |
32 { |
40 * SOAP client used to connect to LiveDocx service |
40 * SOAP client used to connect to LiveDocx service |
41 * @var Zend_Soap_Client |
41 * @var Zend_Soap_Client |
42 * @since LiveDocx 1.0 |
42 * @since LiveDocx 1.0 |
43 */ |
43 */ |
44 protected $_soapClient; |
44 protected $_soapClient; |
45 |
45 |
46 /** |
46 /** |
47 * WSDL of LiveDocx web service |
47 * WSDL of LiveDocx web service |
48 * @var string |
48 * @var string |
49 * @since LiveDocx 1.0 |
49 * @since LiveDocx 1.0 |
50 */ |
50 */ |
51 protected $_wsdl; |
51 protected $_wsdl; |
52 |
52 |
53 /** |
53 /** |
54 * Array of credentials (username and password) to log into backend server |
54 * Array of credentials (username and password) to log into backend server |
55 * @var array |
55 * @var array |
56 * @since LiveDocx 1.2 |
56 * @since LiveDocx 1.2 |
57 */ |
57 */ |
58 protected $_credentials; |
58 protected $_credentials; |
59 |
59 |
60 /** |
60 /** |
61 * Set to true, when session is logged into backend server |
61 * Set to true, when session is logged into backend server |
62 * @var boolean |
62 * @var boolean |
63 * @since LiveDocx 1.2 |
63 * @since LiveDocx 1.2 |
64 */ |
64 */ |
65 protected $_loggedIn; |
65 protected $_loggedIn; |
66 |
66 |
67 /** |
67 /** |
68 * Constructor |
68 * Constructor |
69 * |
69 * |
70 * Optionally, pass an array of options (or Zend_Config object). |
70 * Optionally, pass an array of options (or Zend_Config object). |
71 * |
71 * |
72 * If an option with the key 'soapClient' is provided, that value will be |
72 * If an option with the key 'soapClient' is provided, that value will be |
73 * used to set the internal SOAP client used to connect to the LiveDocx |
73 * used to set the internal SOAP client used to connect to the LiveDocx |
74 * service. |
74 * service. |
75 * |
75 * |
76 * Use 'soapClient' in the case that you have a dedicated or (locally |
76 * Use 'soapClient' in the case that you have a dedicated or (locally |
77 * installed) licensed LiveDocx server. For example: |
77 * installed) licensed LiveDocx server. For example: |
78 * |
78 * |
79 * {code} |
79 * {code} |
80 * $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge( |
80 * $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge( |
83 * 'password' => 'myPassword', |
83 * 'password' => 'myPassword', |
84 * 'soapClient' => new Zend_Soap_Client('https://api.example.com/path/mailmerge.asmx?WSDL') |
84 * 'soapClient' => new Zend_Soap_Client('https://api.example.com/path/mailmerge.asmx?WSDL') |
85 * ) |
85 * ) |
86 * ); |
86 * ); |
87 * {code} |
87 * {code} |
88 * |
88 * |
89 * Replace the URI of the WSDL in the constructor of Zend_Soap_Client with |
89 * Replace the URI of the WSDL in the constructor of Zend_Soap_Client with |
90 * that of your dedicated or licensed LiveDocx server. |
90 * that of your dedicated or licensed LiveDocx server. |
91 * |
91 * |
92 * If you are using the public LiveDocx server, simply pass 'username' and |
92 * If you are using the public LiveDocx server, simply pass 'username' and |
93 * 'password'. For example: |
93 * 'password'. For example: |
98 * 'username' => 'myUsername', |
98 * 'username' => 'myUsername', |
99 * 'password' => 'myPassword' |
99 * 'password' => 'myPassword' |
100 * ) |
100 * ) |
101 * ); |
101 * ); |
102 * {code} |
102 * {code} |
103 * |
103 * |
104 * If you prefer to not pass the username and password through the |
104 * If you prefer to not pass the username and password through the |
105 * constructor, you can also call the following methods: |
105 * constructor, you can also call the following methods: |
106 * |
106 * |
107 * {code} |
107 * {code} |
108 * $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge(); |
108 * $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge(); |
109 * |
109 * |
110 * $phpLiveDocx->setUsername('myUsername') |
110 * $phpLiveDocx->setUsername('myUsername') |
111 * ->setPassword('myPassword'); |
111 * ->setPassword('myPassword'); |
112 * {/code} |
112 * {/code} |
113 * |
113 * |
114 * Or, if you want to specify your own SoapClient: |
114 * Or, if you want to specify your own SoapClient: |
115 * |
115 * |
116 * {code} |
116 * {code} |
117 * $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge(); |
117 * $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge(); |
118 * |
118 * |
119 * $phpLiveDocx->setUsername('myUsername') |
119 * $phpLiveDocx->setUsername('myUsername') |
120 * ->setPassword('myPassword'); |
120 * ->setPassword('myPassword'); |
121 * |
121 * |
122 * $phpLiveDocx->setSoapClient( |
122 * $phpLiveDocx->setSoapClient( |
123 * new Zend_Soap_Client('https://api.example.com/path/mailmerge.asmx?WSDL') |
123 * new Zend_Soap_Client('https://api.example.com/path/mailmerge.asmx?WSDL') |
124 * ); |
124 * ); |
125 * {/code} |
125 * {/code} |
126 * |
126 * |
127 * @param array|Zend_Config $options |
127 * @param array|Zend_Config $options |
128 * @return void |
128 * @return void |
129 * @throws Zend_Service_LiveDocx_Exception |
129 * @throws Zend_Service_LiveDocx_Exception |
130 * @since LiveDocx 1.0 |
130 * @since LiveDocx 1.0 |
131 */ |
131 */ |
132 public function __construct($options = null) |
132 public function __construct($options = null) |
133 { |
133 { |
134 $this->_credentials = array(); |
134 $this->_credentials = array(); |
135 $this->_loggedIn = false; |
135 $this->_loggedIn = false; |
136 |
136 |
137 if ($options instanceof Zend_Config) { |
137 if ($options instanceof Zend_Config) { |
138 $options = $options->toArray(); |
138 $options = $options->toArray(); |
139 } |
139 } |
140 |
140 |
141 if (is_array($options)) { |
141 if (is_array($options)) { |
142 $this->setOptions($options); |
142 $this->setOptions($options); |
143 } |
143 } |
144 } |
144 } |
145 |
145 |
146 /** |
146 /** |
147 * Set options |
147 * Set options |
148 * One or more of username, password, soapClient |
148 * One or more of username, password, soapClient |
149 * |
149 * |
150 * @param $options |
150 * @param array $options |
151 * @return Zend_Service_LiveDocx |
151 * @return Zend_Service_LiveDocx |
152 * @since LiveDocx 1.2 |
152 * @since LiveDocx 1.2 |
153 */ |
153 */ |
154 public function setOptions(array $options) |
154 public function setOptions(array $options) |
155 { |
155 { |
157 $method = 'set' . $key; |
157 $method = 'set' . $key; |
158 if (method_exists($this, $method)) { |
158 if (method_exists($this, $method)) { |
159 $this->$method($value); |
159 $this->$method($value); |
160 } |
160 } |
161 } |
161 } |
162 |
162 |
163 return $this; |
163 return $this; |
164 } |
164 } |
165 |
165 |
166 /** |
166 /** |
167 * Clean up and log out of LiveDocx service |
167 * Clean up and log out of LiveDocx service |
168 * |
168 * |
169 * @return boolean |
169 * @return boolean |
170 * @since LiveDocx 1.0 |
170 * @since LiveDocx 1.0 |
171 */ |
171 */ |
172 public function __destruct() |
172 public function __destruct() |
173 { |
173 { |
174 return $this->logOut(); |
174 return $this->logOut(); |
175 } |
175 } |
176 |
176 |
177 /** |
177 /** |
178 * Init Soap client - connect to SOAP service |
178 * Init Soap client - connect to SOAP service |
179 * |
179 * |
180 * @param string $endpoint |
180 * @param string $endpoint |
181 * @throws Zend_Service_LiveDocx_Exception |
181 * @throws Zend_Service_LiveDocx_Exception |
185 protected function _initSoapClient($endpoint) |
185 protected function _initSoapClient($endpoint) |
186 { |
186 { |
187 try { |
187 try { |
188 require_once 'Zend/Soap/Client.php'; |
188 require_once 'Zend/Soap/Client.php'; |
189 $this->_soapClient = new Zend_Soap_Client(); |
189 $this->_soapClient = new Zend_Soap_Client(); |
190 $this->_soapClient->setWsdl($endpoint); |
190 $this->_soapClient->setWsdl($endpoint); |
191 } catch (Zend_Soap_Client_Exception $e) { |
191 } catch (Zend_Soap_Client_Exception $e) { |
192 require_once 'Zend/Service/LiveDocx/Exception.php'; |
192 require_once 'Zend/Service/LiveDocx/Exception.php'; |
193 throw new Zend_Service_LiveDocx_Exception('Cannot connect to LiveDocx service at ' . $endpoint, 0, $e); |
193 throw new Zend_Service_LiveDocx_Exception('Cannot connect to LiveDocx service at ' . $endpoint, 0, $e); |
194 } |
194 } |
195 } |
195 } |
196 |
196 |
197 /** |
197 /** |
198 * Get SOAP client |
198 * Get SOAP client |
199 * |
199 * |
200 * @return Zend_Soap_Client |
200 * @return Zend_Soap_Client |
201 * @since LiveDocx 1.2 |
201 * @since LiveDocx 1.2 |
202 */ |
202 */ |
203 public function getSoapClient() |
203 public function getSoapClient() |
204 { |
204 { |
205 return $this->_soapClient; |
205 return $this->_soapClient; |
206 } |
206 } |
207 |
207 |
208 /** |
208 /** |
209 * Set SOAP client |
209 * Set SOAP client |
210 * |
210 * |
211 * @param Zend_Soap_Client $soapClient |
211 * @param Zend_Soap_Client $soapClient |
212 * @return Zend_Service_LiveDocx |
212 * @return Zend_Service_LiveDocx |
235 require_once 'Zend/Service/LiveDocx/Exception.php'; |
235 require_once 'Zend/Service/LiveDocx/Exception.php'; |
236 throw new Zend_Service_LiveDocx_Exception( |
236 throw new Zend_Service_LiveDocx_Exception( |
237 'Username has not been set. To set username specify the options array in the constructor or call setUsername($username) after instantiation' |
237 'Username has not been set. To set username specify the options array in the constructor or call setUsername($username) after instantiation' |
238 ); |
238 ); |
239 } |
239 } |
240 |
240 |
241 if (null === $this->getPassword()) { |
241 if (null === $this->getPassword()) { |
242 require_once 'Zend/Service/LiveDocx/Exception.php'; |
242 require_once 'Zend/Service/LiveDocx/Exception.php'; |
243 throw new Zend_Service_LiveDocx_Exception( |
243 throw new Zend_Service_LiveDocx_Exception( |
244 'Password has not been set. To set password specify the options array in the constructor or call setPassword($password) after instantiation' |
244 'Password has not been set. To set password specify the options array in the constructor or call setPassword($password) after instantiation' |
245 ); |
245 ); |
246 } |
246 } |
247 |
247 |
248 if (null === $this->getSoapClient()) { |
248 if (null === $this->getSoapClient()) { |
249 $this->_initSoapClient($this->_wsdl); |
249 $this->_initSoapClient($this->_wsdl); |
250 } |
250 } |
251 |
251 |
252 try { |
252 try { |
253 $this->getSoapClient()->LogIn(array( |
253 $this->getSoapClient()->LogIn(array( |
254 'username' => $this->getUsername(), |
254 'username' => $this->getUsername(), |
255 'password' => $this->getPassword(), |
255 'password' => $this->getPassword(), |
256 )); |
256 )); |
282 } catch (Exception $e) { |
282 } catch (Exception $e) { |
283 require_once 'Zend/Service/LiveDocx/Exception.php'; |
283 require_once 'Zend/Service/LiveDocx/Exception.php'; |
284 throw new Zend_Service_LiveDocx_Exception( |
284 throw new Zend_Service_LiveDocx_Exception( |
285 'Cannot log out of LiveDocx service', 0, $e |
285 'Cannot log out of LiveDocx service', 0, $e |
286 ); |
286 ); |
287 } |
287 } |
288 } |
288 } |
289 |
289 |
290 return $this->_loggedIn; |
290 return $this->_loggedIn; |
291 } |
291 } |
292 |
292 |
293 /** |
293 /** |
294 * Return true, if session is currently logged into the backend server |
294 * Return true, if session is currently logged into the backend server |
295 * |
295 * |
296 * @return boolean |
296 * @return boolean |
297 * @since LiveDocx 1.2 |
297 * @since LiveDocx 1.2 |
298 */ |
298 */ |
299 public function isLoggedIn() |
299 public function isLoggedIn() |
300 { |
300 { |
301 return $this->_loggedIn; |
301 return $this->_loggedIn; |
302 } |
302 } |
303 |
303 |
304 /** |
304 /** |
305 * Set username |
305 * Set username |
306 * |
306 * |
307 * @return Zend_Service_LiveDocx |
307 * @return Zend_Service_LiveDocx |
308 * @since LiveDocx 1.0 |
308 * @since LiveDocx 1.0 |
309 */ |
309 */ |
310 public function setUsername($username) |
310 public function setUsername($username) |
311 { |
311 { |
312 $this->_credentials['username'] = $username; |
312 $this->_credentials['username'] = $username; |
313 return $this; |
313 return $this; |
314 } |
314 } |
315 |
315 |
316 /** |
316 /** |
317 * Set password |
317 * Set password |
318 * |
318 * |
319 * @return Zend_Service_LiveDocx |
319 * @return Zend_Service_LiveDocx |
320 * @since LiveDocx 1.0 |
320 * @since LiveDocx 1.0 |
321 */ |
321 */ |
322 public function setPassword($password) |
322 public function setPassword($password) |
323 { |
323 { |
324 $this->_credentials['password'] = $password; |
324 $this->_credentials['password'] = $password; |
325 return $this; |
325 return $this; |
326 } |
326 } |
327 |
327 |
328 /** |
328 /** |
329 * Set WSDL of LiveDocx web service |
329 * Set WSDL of LiveDocx web service |
330 * |
330 * |
331 * @return Zend_Service_LiveDocx |
331 * @return Zend_Service_LiveDocx |
332 * @since LiveDocx 1.0 |
332 * @since LiveDocx 1.0 |
333 */ |
333 */ |
334 public function setWsdl($wsdl) |
334 public function setWsdl($wsdl) |
335 { |
335 { |
336 $this->_wsdl = $wsdl; |
336 $this->_wsdl = $wsdl; |
337 return $this; |
337 return $this; |
338 } |
338 } |
339 |
339 |
340 /** |
340 /** |
341 * Return current username |
341 * Return current username |
342 * |
342 * |
343 * @return string|null |
343 * @return string|null |
344 * @since LiveDocx 1.0 |
344 * @since LiveDocx 1.0 |
345 */ |
345 */ |
346 public function getUsername() |
346 public function getUsername() |
347 { |
347 { |
348 if (isset($this->_credentials['username'])) { |
348 if (isset($this->_credentials['username'])) { |
349 return $this->_credentials['username']; |
349 return $this->_credentials['username']; |
350 } |
350 } |
351 |
351 |
352 return null; |
352 return null; |
353 } |
353 } |
354 |
354 |
355 /** |
355 /** |
356 * Return current password |
356 * Return current password |
357 * |
357 * |
358 * @return string|null |
358 * @return string|null |
359 * @since LiveDocx 1.0 |
359 * @since LiveDocx 1.0 |
360 */ |
360 */ |
361 public function getPassword() |
361 public function getPassword() |
362 { |
362 { |
363 if (isset($this->_credentials['password'])) { |
363 if (isset($this->_credentials['password'])) { |
364 return $this->_credentials['password']; |
364 return $this->_credentials['password']; |
365 } |
365 } |
366 |
366 |
367 return null; |
367 return null; |
368 } |
368 } |
369 |
369 |
370 /** |
370 /** |
371 * Return WSDL of LiveDocx web service |
371 * Return WSDL of LiveDocx web service |
372 * |
372 * |
373 * @return Zend_Service_LiveDocx |
373 * @return Zend_Service_LiveDocx |
374 * @since LiveDocx 1.0 |
374 * @since LiveDocx 1.0 |
375 */ |
375 */ |
376 public function getWsdl() |
376 public function getWsdl() |
377 { |
377 { |
378 return $this->_wsdl; |
378 return $this->_wsdl; |
379 } |
379 } |
380 |
380 |
381 /** |
381 /** |
382 * Return the document format (extension) of a filename |
382 * Return the document format (extension) of a filename |
383 * |
383 * |
384 * @param string $filename |
384 * @param string $filename |
387 */ |
387 */ |
388 public function getFormat($filename) |
388 public function getFormat($filename) |
389 { |
389 { |
390 return strtolower(substr(strrchr($filename, '.'), 1)); |
390 return strtolower(substr(strrchr($filename, '.'), 1)); |
391 } |
391 } |
392 |
392 |
393 /** |
393 /** |
394 * Return the current API version |
394 * Return the current API version |
395 * |
395 * |
396 * @return string |
396 * @return string |
397 * @since LiveDocx 1.0 |
397 * @since LiveDocx 1.0 |
398 */ |
398 */ |
399 public function getVersion() |
399 public function getVersion() |
400 { |
400 { |
401 return self::VERSION; |
401 return self::VERSION; |
402 } |
402 } |
403 |
403 |
404 /** |
404 /** |
405 * Compare the current API version with another version |
405 * Compare the current API version with another version |
406 * |
406 * |
407 * @param string $version (STRING NOT FLOAT) |
407 * @param string $version (STRING NOT FLOAT) |
408 * @return int -1 (version is less than API version), 0 (versions are equal), or 1 (version is greater than API version) |
408 * @return int -1 (version is less than API version), 0 (versions are equal), or 1 (version is greater than API version) |