Merge file:///media/external_data/workspace/web/sport-group
[sport-group.git] / library / Zend / XmlRpc / Client / ServerIntrospection.php
blobf339df27dba920576ba8629b1c8651e274470a76
1 <?php
2 /**
3 * Zend Framework
5 * LICENSE
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 license@zend.com so we can send you a copy immediately.
15 * @category Zend
16 * @package Zend_XmlRpc
17 * @subpackage Client
18 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license http://framework.zend.com/license/new-bsd New BSD License
20 * @version $Id: ServerIntrospection.php 16971 2009-07-22 18:05:45Z mikaelkael $
23 /**
24 * Wraps the XML-RPC system.* introspection methods
26 * @category Zend
27 * @package Zend_XmlRpc
28 * @subpackage Client
29 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
30 * @license http://framework.zend.com/license/new-bsd New BSD License
32 class Zend_XmlRpc_Client_ServerIntrospection
34 /**
35 * @var Zend_XmlRpc_Client_ServerProxy
37 private $_system = null;
40 /**
41 * @param Zend_XmlRpc_Client $client
43 public function __construct(Zend_XmlRpc_Client $client)
45 $this->_system = $client->getProxy('system');
48 /**
49 * Returns the signature for each method on the server,
50 * autodetecting whether system.multicall() is supported and
51 * using it if so.
53 * @return array
55 public function getSignatureForEachMethod()
57 $methods = $this->listMethods();
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
66 if (empty($signatures)) {
67 $signatures = $this->getSignatureForEachMethodByLooping($methods);
70 return $signatures;
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.
78 * @param array $methods
79 * @return array array(array(return, param, param, param...))
81 public function getSignatureForEachMethodByMulticall($methods = null)
83 if ($methods === null) {
84 $methods = $this->listMethods();
87 $multicallParams = array();
88 foreach ($methods as $method) {
89 $multicallParams[] = array('methodName' => 'system.methodSignature',
90 'params' => array($method));
93 $serverSignatures = $this->_system->multicall($multicallParams);
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);
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);
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;
114 return $signatures;
118 * Get the method signatures for every method by
119 * successively calling system.methodSignature
121 * @param array $methods
122 * @return array
124 public function getSignatureForEachMethodByLooping($methods = null)
126 if ($methods === null) {
127 $methods = $this->listMethods();
130 $signatures = array();
131 foreach ($methods as $method) {
132 $signatures[$method] = $this->getMethodSignature($method);
135 return $signatures;
139 * Call system.methodSignature() for the given method
141 * @param array $method
142 * @return array array(array(return, param, param, param...))
144 public function getMethodSignature($method)
146 $signature = $this->_system->methodSignature($method);
147 return $signature;
151 * Call system.listMethods()
153 * @param array $method
154 * @return array array(method, method, method...)
156 public function listMethods()
158 return $this->_system->listMethods();