|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00032 class Zend_XmlRpc_Client_ServerIntrospection 00033 { 00037 private $_system = null; 00038 00039 00043 public function __construct(Zend_XmlRpc_Client $client) 00044 { 00045 $this->_system = $client->getProxy('system'); 00046 } 00047 00055 public function getSignatureForEachMethod() 00056 { 00057 $methods = $this->listMethods(); 00058 00059 require_once 'Zend/XmlRpc/Client/FaultException.php'; 00060 try { 00061 $signatures = $this->getSignatureForEachMethodByMulticall($methods); 00062 } catch (Zend_XmlRpc_Client_FaultException $e) { 00063 // degrade to looping 00064 } 00065 00066 if (empty($signatures)) { 00067 $signatures = $this->getSignatureForEachMethodByLooping($methods); 00068 } 00069 00070 return $signatures; 00071 } 00072 00081 public function getSignatureForEachMethodByMulticall($methods = null) 00082 { 00083 if ($methods === null) { 00084 $methods = $this->listMethods(); 00085 } 00086 00087 $multicallParams = array(); 00088 foreach ($methods as $method) { 00089 $multicallParams[] = array('methodName' => 'system.methodSignature', 00090 'params' => array($method)); 00091 } 00092 00093 $serverSignatures = $this->_system->multicall($multicallParams); 00094 00095 if (! is_array($serverSignatures)) { 00096 $type = gettype($serverSignatures); 00097 $error = "Multicall return is malformed. Expected array, got $type"; 00098 require_once 'Zend/XmlRpc/Client/IntrospectException.php'; 00099 throw new Zend_XmlRpc_Client_IntrospectException($error); 00100 } 00101 00102 if (count($serverSignatures) != count($methods)) { 00103 $error = 'Bad number of signatures received from multicall'; 00104 require_once 'Zend/XmlRpc/Client/IntrospectException.php'; 00105 throw new Zend_XmlRpc_Client_IntrospectException($error); 00106 } 00107 00108 // Create a new signatures array with the methods name as keys and the signature as value 00109 $signatures = array(); 00110 foreach ($serverSignatures as $i => $signature) { 00111 $signatures[$methods[$i]] = $signature; 00112 } 00113 00114 return $signatures; 00115 } 00116 00124 public function getSignatureForEachMethodByLooping($methods = null) 00125 { 00126 if ($methods === null) { 00127 $methods = $this->listMethods(); 00128 } 00129 00130 $signatures = array(); 00131 foreach ($methods as $method) { 00132 $signatures[$method] = $this->getMethodSignature($method); 00133 } 00134 00135 return $signatures; 00136 } 00137 00144 public function getMethodSignature($method) 00145 { 00146 $signature = $this->_system->methodSignature($method); 00147 if (!is_array($signature)) { 00148 $error = 'Invalid signature for method "' . $method . '"'; 00149 require_once 'Zend/XmlRpc/Client/IntrospectException.php'; 00150 throw new Zend_XmlRpc_Client_IntrospectException($error); 00151 } 00152 return $signature; 00153 } 00154 00161 public function listMethods() 00162 { 00163 return $this->_system->listMethods(); 00164 } 00165 00166 }