|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00026 require_once 'Zend/Service/DeveloperGarden/Client/Soap.php'; 00027 00031 require_once 'Zend/Service/DeveloperGarden/Credential.php'; 00032 00036 require_once 'Zend/Service/DeveloperGarden/SecurityTokenServer.php'; 00037 00046 abstract class Zend_Service_DeveloperGarden_Client_ClientAbstract 00047 { 00051 const ENV_PRODUCTION = 1; // Production Environment 00052 const ENV_SANDBOX = 2; // Sandbox Environment, limited access to the api 00053 const ENV_MOCK = 3; // Api calls are without any functionality 00054 00055 const PARTICIPANT_MUTE_OFF = 0; // removes mute from participant in a conference 00056 const PARTICIPANT_MUTE_ON = 1; // mute participant in a conference 00057 const PARTICIPANT_RECALL = 2; // recalls the participant in a conference 00058 00064 static protected $_consts = null; 00065 00071 protected $_options = array(); 00072 00078 protected $_serviceAuthId = 'https://odg.t-online.de'; 00079 00085 protected $_serviceEnvironment = Zend_Service_DeveloperGarden_Client_ClientAbstract::ENV_PRODUCTION; 00086 00092 protected $_wsdlFile = null; 00093 00099 protected $_wsdlFileLocal = null; 00100 00106 protected $_useLocalWsdl = true; 00107 00113 protected $_credential = null; 00114 00120 protected $_soapClient = null; 00121 00127 protected $_classMap = array(); 00128 00134 public function __construct(array $options = array()) 00135 { 00136 $this->_credential = new Zend_Service_DeveloperGarden_Credential(); 00137 00138 while (list($name, $value) = each($options)) { 00139 switch (ucfirst($name)) { 00140 case 'Username' : 00141 $this->_credential->setUsername($value); 00142 break; 00143 case 'Password' : 00144 $this->_credential->setPassword($value); 00145 break; 00146 case 'Realm' : 00147 $this->_credential->setRealm($value); 00148 break; 00149 case 'Environment' : 00150 $this->setEnvironment($value); 00151 } 00152 } 00153 00154 if (empty($this->_wsdlFile)) { 00155 require_once 'Zend/Service/DeveloperGarden/Exception.php'; 00156 throw new Zend_Service_DeveloperGarden_Exception('_wsdlFile not set for this service.'); 00157 } 00158 00159 if (!empty($this->_wsdlFileLocal)) { 00160 $this->_wsdlFileLocal = realpath(dirname(__FILE__) . '/../' . $this->_wsdlFileLocal); 00161 } 00162 00163 if (empty($this->_wsdlFileLocal) || $this->_wsdlFileLocal === false) { 00164 require_once 'Zend/Service/DeveloperGarden/Exception.php'; 00165 throw new Zend_Service_DeveloperGarden_Exception('_wsdlFileLocal not set for this service.'); 00166 } 00167 } 00168 00177 public function setOption($name, $value) 00178 { 00179 if (!is_string($name)) { 00180 require_once 'Zend/Service/DeveloperGarden/Client/Exception.php'; 00181 throw new Zend_Service_DeveloperGarden_Client_Exception('Incorrect option name: ' . $name); 00182 } 00183 $name = strtolower($name); 00184 if (array_key_exists($name, $this->_options)) { 00185 $this->_options[$name] = $value; 00186 } 00187 00188 return $this; 00189 } 00190 00197 public function getOption($name) 00198 { 00199 $name = strtolower($name); 00200 if (array_key_exists($name, $this->_options)) { 00201 return $this->_options[$name]; 00202 } 00203 00204 return null; 00205 } 00206 00215 final public function getSoapClient() 00216 { 00217 if ($this->_soapClient === null) { 00221 $this->_soapClient = new Zend_Service_DeveloperGarden_Client_Soap( 00222 $this->getWsdl(), 00223 $this->getClientOptions() 00224 ); 00225 $this->_soapClient->setCredential($this->_credential); 00226 $tokenService = new Zend_Service_DeveloperGarden_SecurityTokenServer( 00227 array( 00228 'username' => $this->_credential->getUsername(), 00229 'password' => $this->_credential->getPassword(), 00230 'environment' => $this->getEnvironment(), 00231 'realm' => $this->_credential->getRealm(), 00232 ) 00233 ); 00234 $this->_soapClient->setTokenService($tokenService); 00235 } 00236 00237 return $this->_soapClient; 00238 } 00239 00246 public function setEnvironment($environment) 00247 { 00248 self::checkEnvironment($environment); 00249 $this->_serviceEnvironment = $environment; 00250 return $this; 00251 } 00252 00258 public function getEnvironment() 00259 { 00260 return $this->_serviceEnvironment; 00261 } 00262 00268 public function getWsdl() 00269 { 00270 if ($this->_useLocalWsdl) { 00271 $retVal = $this->_wsdlFileLocal; 00272 } else { 00273 $retVal = $this->_wsdlFile; 00274 } 00275 00276 return $retVal; 00277 } 00278 00285 public function setUseLocalWsdl($use = true) 00286 { 00287 $this->_useLocalWsdl = (boolean) $use; 00288 return $this; 00289 } 00290 00297 public function setWsdl($wsdlFile = null) 00298 { 00299 if (empty($wsdlFile)) { 00300 require_once 'Zend/Service/DeveloperGarden/Exception.php'; 00301 throw new Zend_Service_DeveloperGarden_Exception('_wsdlFile not set for this service.'); 00302 } 00303 $this->_wsdlFile = $wsdlFile; 00304 return $this; 00305 } 00306 00313 public function setLocalWsdl($wsdlFile = null) 00314 { 00315 if (empty($wsdlFile)) { 00316 require_once 'Zend/Service/DeveloperGarden/Exception.php'; 00317 throw new Zend_Service_DeveloperGarden_Exception('_wsdlFileLocal not set for this service.'); 00318 } 00319 $this->_wsdlFileLocal = $wsdlFile; 00320 return $this; 00321 } 00322 00328 public function getClientOptions() 00329 { 00330 $options = array( 00331 'soap_version' => SOAP_1_1, 00332 ); 00333 if (!empty($this->_classMap)) { 00334 $options['classmap'] = $this->_classMap; 00335 } 00336 $wsdlCache = Zend_Service_DeveloperGarden_SecurityTokenServer_Cache::getWsdlCache(); 00337 if (!is_null($wsdlCache)) { 00338 $options['cache_wsdl'] = $wsdlCache; 00339 } 00340 return $options; 00341 } 00342 00348 public function getCredential() 00349 { 00350 return $this->_credential; 00351 } 00352 00357 static protected function _buildConstArray() 00358 { 00359 $r = new ReflectionClass(__CLASS__); 00360 foreach ($r->getConstants() as $k => $v) { 00361 $s = explode('_', $k, 2); 00362 if (!isset(self::$_consts[$s[0]])) { 00363 self::$_consts[$s[0]] = array(); 00364 } 00365 self::$_consts[$s[0]][$v] = $k; 00366 } 00367 } 00368 00374 static public function getParticipantActions() 00375 { 00376 if (empty(self::$_consts)) { 00377 self::_buildConstArray(); 00378 } 00379 return self::$_consts['PARTICIPANT']; 00380 } 00381 00390 static public function checkParticipantAction($action) 00391 { 00392 if (!array_key_exists($action, self::getParticipantActions())) { 00393 require_once 'Zend/Service/DeveloperGarden/Client/Exception.php'; 00394 throw new Zend_Service_DeveloperGarden_Client_Exception( 00395 'Wrong Participant Action ' . $action . ' supplied.' 00396 ); 00397 } 00398 } 00399 00405 static public function getEnvironments() 00406 { 00407 if (empty(self::$_consts)) { 00408 self::_buildConstArray(); 00409 } 00410 return self::$_consts['ENV']; 00411 } 00412 00421 static public function checkEnvironment($environment) 00422 { 00423 if (!array_key_exists($environment, self::getEnvironments())) { 00424 require_once 'Zend/Service/DeveloperGarden/Client/Exception.php'; 00425 throw new Zend_Service_DeveloperGarden_Client_Exception( 00426 'Wrong environment ' . $environment . ' supplied.' 00427 ); 00428 } 00429 } 00430 }