fix calendar css, take 2. (#213)
[openemr.git] / interface / modules / zend_modules / library / Zend / XmlRpc / Client / ServerIntrospection.php
blobd1d2c2a43bf2a34b01544250e01ade4ec8371232
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
10 namespace Zend\XmlRpc\Client;
12 use Zend\XmlRpc\Client as XMLRPCClient;
14 /**
15 * Wraps the XML-RPC system.* introspection methods
17 class ServerIntrospection
19 /**
20 * @var \Zend\XmlRpc\Client\ServerProxy
22 private $system = null;
24 /**
25 * @param \Zend\XmlRpc\Client $client
27 public function __construct(XMLRPCClient $client)
29 $this->system = $client->getProxy('system');
32 /**
33 * Returns the signature for each method on the server,
34 * autodetecting whether system.multicall() is supported and
35 * using it if so.
37 * @return array
39 public function getSignatureForEachMethod()
41 $methods = $this->listMethods();
43 try {
44 $signatures = $this->getSignatureForEachMethodByMulticall($methods);
45 } catch (Exception\FaultException $e) {
46 // degrade to looping
49 if (empty($signatures)) {
50 $signatures = $this->getSignatureForEachMethodByLooping($methods);
53 return $signatures;
56 /**
57 * Attempt to get the method signatures in one request via system.multicall().
58 * This is a boxcar feature of XML-RPC and is found on fewer servers. However,
59 * can significantly improve performance if present.
61 * @param array $methods
62 * @throws Exception\IntrospectException
63 * @return array array(array(return, param, param, param...))
65 public function getSignatureForEachMethodByMulticall($methods = null)
67 if ($methods === null) {
68 $methods = $this->listMethods();
71 $multicallParams = array();
72 foreach ($methods as $method) {
73 $multicallParams[] = array('methodName' => 'system.methodSignature',
74 'params' => array($method));
77 $serverSignatures = $this->system->multicall($multicallParams);
79 if (! is_array($serverSignatures)) {
80 $type = gettype($serverSignatures);
81 $error = "Multicall return is malformed. Expected array, got $type";
82 throw new Exception\IntrospectException($error);
85 if (count($serverSignatures) != count($methods)) {
86 $error = 'Bad number of signatures received from multicall';
87 throw new Exception\IntrospectException($error);
90 // Create a new signatures array with the methods name as keys and the signature as value
91 $signatures = array();
92 foreach ($serverSignatures as $i => $signature) {
93 $signatures[$methods[$i]] = $signature;
96 return $signatures;
99 /**
100 * Get the method signatures for every method by
101 * successively calling system.methodSignature
103 * @param array $methods
104 * @return array
106 public function getSignatureForEachMethodByLooping($methods = null)
108 if ($methods === null) {
109 $methods = $this->listMethods();
112 $signatures = array();
113 foreach ($methods as $method) {
114 $signatures[$method] = $this->getMethodSignature($method);
117 return $signatures;
121 * Call system.methodSignature() for the given method
123 * @param array $method
124 * @throws Exception\IntrospectException
125 * @return array array(array(return, param, param, param...))
127 public function getMethodSignature($method)
129 $signature = $this->system->methodSignature($method);
130 if (!is_array($signature)) {
131 $error = 'Invalid signature for method "' . $method . '"';
132 throw new Exception\IntrospectException($error);
134 return $signature;
138 * Call system.listMethods()
140 * @return array array(method, method, method...)
142 public function listMethods()
144 return $this->system->listMethods();