File indexing completed on 2025-05-25 05:30:00
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_XmlRpc 0017 * @subpackage Client 0018 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0019 * @license http://framework.zend.com/license/new-bsd New BSD License 0020 * @version $Id$ 0021 */ 0022 0023 /** 0024 * Wraps the XML-RPC system.* introspection methods 0025 * 0026 * @category Zend 0027 * @package Zend_XmlRpc 0028 * @subpackage Client 0029 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0030 * @license http://framework.zend.com/license/new-bsd New BSD License 0031 */ 0032 class Zend_XmlRpc_Client_ServerIntrospection 0033 { 0034 /** 0035 * @var Zend_XmlRpc_Client_ServerProxy 0036 */ 0037 private $_system = null; 0038 0039 0040 /** 0041 * @param Zend_XmlRpc_Client $client 0042 */ 0043 public function __construct(Zend_XmlRpc_Client $client) 0044 { 0045 $this->_system = $client->getProxy('system'); 0046 } 0047 0048 /** 0049 * Returns the signature for each method on the server, 0050 * autodetecting whether system.multicall() is supported and 0051 * using it if so. 0052 * 0053 * @return array 0054 */ 0055 public function getSignatureForEachMethod() 0056 { 0057 $methods = $this->listMethods(); 0058 0059 // require_once 'Zend/XmlRpc/Client/FaultException.php'; 0060 try { 0061 $signatures = $this->getSignatureForEachMethodByMulticall($methods); 0062 } catch (Zend_XmlRpc_Client_FaultException $e) { 0063 // degrade to looping 0064 } 0065 0066 if (empty($signatures)) { 0067 $signatures = $this->getSignatureForEachMethodByLooping($methods); 0068 } 0069 0070 return $signatures; 0071 } 0072 0073 /** 0074 * Attempt to get the method signatures in one request via system.multicall(). 0075 * This is a boxcar feature of XML-RPC and is found on fewer servers. However, 0076 * can significantly improve performance if present. 0077 * 0078 * @param array $methods 0079 * @return array array(array(return, param, param, param...)) 0080 */ 0081 public function getSignatureForEachMethodByMulticall($methods = null) 0082 { 0083 if ($methods === null) { 0084 $methods = $this->listMethods(); 0085 } 0086 0087 $multicallParams = array(); 0088 foreach ($methods as $method) { 0089 $multicallParams[] = array('methodName' => 'system.methodSignature', 0090 'params' => array($method)); 0091 } 0092 0093 $serverSignatures = $this->_system->multicall($multicallParams); 0094 0095 if (! is_array($serverSignatures)) { 0096 $type = gettype($serverSignatures); 0097 $error = "Multicall return is malformed. Expected array, got $type"; 0098 // require_once 'Zend/XmlRpc/Client/IntrospectException.php'; 0099 throw new Zend_XmlRpc_Client_IntrospectException($error); 0100 } 0101 0102 if (count($serverSignatures) != count($methods)) { 0103 $error = 'Bad number of signatures received from multicall'; 0104 // require_once 'Zend/XmlRpc/Client/IntrospectException.php'; 0105 throw new Zend_XmlRpc_Client_IntrospectException($error); 0106 } 0107 0108 // Create a new signatures array with the methods name as keys and the signature as value 0109 $signatures = array(); 0110 foreach ($serverSignatures as $i => $signature) { 0111 $signatures[$methods[$i]] = $signature; 0112 } 0113 0114 return $signatures; 0115 } 0116 0117 /** 0118 * Get the method signatures for every method by 0119 * successively calling system.methodSignature 0120 * 0121 * @param array $methods 0122 * @return array 0123 */ 0124 public function getSignatureForEachMethodByLooping($methods = null) 0125 { 0126 if ($methods === null) { 0127 $methods = $this->listMethods(); 0128 } 0129 0130 $signatures = array(); 0131 foreach ($methods as $method) { 0132 $signatures[$method] = $this->getMethodSignature($method); 0133 } 0134 0135 return $signatures; 0136 } 0137 0138 /** 0139 * Call system.methodSignature() for the given method 0140 * 0141 * @param array $method 0142 * @return array array(array(return, param, param, param...)) 0143 */ 0144 public function getMethodSignature($method) 0145 { 0146 $signature = $this->_system->methodSignature($method); 0147 if (!is_array($signature)) { 0148 $error = 'Invalid signature for method "' . $method . '"'; 0149 // require_once 'Zend/XmlRpc/Client/IntrospectException.php'; 0150 throw new Zend_XmlRpc_Client_IntrospectException($error); 0151 } 0152 return $signature; 0153 } 0154 0155 /** 0156 * Call system.listMethods() 0157 * 0158 * @param array $method 0159 * @return array array(method, method, method...) 0160 */ 0161 public function listMethods() 0162 { 0163 return $this->_system->listMethods(); 0164 } 0165 0166 }