[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Zend Framework 4 * 5 * LICENSE 6 * 7 * This source file is subject to the new BSD license that is bundled 8 * with this package in the file LICENSE.txt. 9 * It is also available through the world-wide-web at this URL: 10 * http://framework.zend.com/license/new-bsd 11 * If you did not receive a copy of the license and are unable to 12 * obtain it through the world-wide-web, please send an email 13 * to [email protected] so we can send you a copy immediately. 14 * 15 * @category Zend 16 * @package Zend_XmlRpc 17 * @subpackage Client 18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) 19 * @license http://framework.zend.com/license/new-bsd New BSD License 20 * @version $Id$ 21 */ 22 23 /** 24 * Wraps the XML-RPC system.* introspection methods 25 * 26 * @category Zend 27 * @package Zend_XmlRpc 28 * @subpackage Client 29 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) 30 * @license http://framework.zend.com/license/new-bsd New BSD License 31 */ 32 class Zend_XmlRpc_Client_ServerIntrospection 33 { 34 /** 35 * @var Zend_XmlRpc_Client_ServerProxy 36 */ 37 private $_system = null; 38 39 40 /** 41 * @param Zend_XmlRpc_Client $client 42 */ 43 public function __construct(Zend_XmlRpc_Client $client) 44 { 45 $this->_system = $client->getProxy('system'); 46 } 47 48 /** 49 * Returns the signature for each method on the server, 50 * autodetecting whether system.multicall() is supported and 51 * using it if so. 52 * 53 * @return array 54 */ 55 public function getSignatureForEachMethod() 56 { 57 $methods = $this->listMethods(); 58 59 require_once 'Zend/XmlRpc/Client/FaultException.php'; 60 try { 61 $signatures = $this->getSignatureForEachMethodByMulticall($methods); 62 } catch (Zend_XmlRpc_Client_FaultException $e) { 63 // degrade to looping 64 } 65 66 if (empty($signatures)) { 67 $signatures = $this->getSignatureForEachMethodByLooping($methods); 68 } 69 70 return $signatures; 71 } 72 73 /** 74 * Attempt to get the method signatures in one request via system.multicall(). 75 * This is a boxcar feature of XML-RPC and is found on fewer servers. However, 76 * can significantly improve performance if present. 77 * 78 * @param array $methods 79 * @return array array(array(return, param, param, param...)) 80 */ 81 public function getSignatureForEachMethodByMulticall($methods = null) 82 { 83 if ($methods === null) { 84 $methods = $this->listMethods(); 85 } 86 87 $multicallParams = array(); 88 foreach ($methods as $method) { 89 $multicallParams[] = array('methodName' => 'system.methodSignature', 90 'params' => array($method)); 91 } 92 93 $serverSignatures = $this->_system->multicall($multicallParams); 94 95 if (! is_array($serverSignatures)) { 96 $type = gettype($serverSignatures); 97 $error = "Multicall return is malformed. Expected array, got $type"; 98 require_once 'Zend/XmlRpc/Client/IntrospectException.php'; 99 throw new Zend_XmlRpc_Client_IntrospectException($error); 100 } 101 102 if (count($serverSignatures) != count($methods)) { 103 $error = 'Bad number of signatures received from multicall'; 104 require_once 'Zend/XmlRpc/Client/IntrospectException.php'; 105 throw new Zend_XmlRpc_Client_IntrospectException($error); 106 } 107 108 // Create a new signatures array with the methods name as keys and the signature as value 109 $signatures = array(); 110 foreach ($serverSignatures as $i => $signature) { 111 $signatures[$methods[$i]] = $signature; 112 } 113 114 return $signatures; 115 } 116 117 /** 118 * Get the method signatures for every method by 119 * successively calling system.methodSignature 120 * 121 * @param array $methods 122 * @return array 123 */ 124 public function getSignatureForEachMethodByLooping($methods = null) 125 { 126 if ($methods === null) { 127 $methods = $this->listMethods(); 128 } 129 130 $signatures = array(); 131 foreach ($methods as $method) { 132 $signatures[$method] = $this->getMethodSignature($method); 133 } 134 135 return $signatures; 136 } 137 138 /** 139 * Call system.methodSignature() for the given method 140 * 141 * @param array $method 142 * @return array array(array(return, param, param, param...)) 143 */ 144 public function getMethodSignature($method) 145 { 146 $signature = $this->_system->methodSignature($method); 147 if (!is_array($signature)) { 148 $error = 'Invalid signature for method "' . $method . '"'; 149 require_once 'Zend/XmlRpc/Client/IntrospectException.php'; 150 throw new Zend_XmlRpc_Client_IntrospectException($error); 151 } 152 return $signature; 153 } 154 155 /** 156 * Call system.listMethods() 157 * 158 * @param array $method 159 * @return array array(method, method, method...) 160 */ 161 public function listMethods() 162 { 163 return $this->_system->listMethods(); 164 } 165 166 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |