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
10 namespace Zend\XmlRpc\Server
;
13 * XML-RPC system.* methods
18 * @var \Zend\XmlRpc\Server
25 * @param \Zend\XmlRpc\Server $server
27 public function __construct(\Zend\XmlRpc\Server
$server)
29 $this->server
= $server;
33 * List all available XMLRPC methods
35 * Returns an array of methods.
39 public function listMethods()
41 $table = $this->server
->getDispatchTable()->getMethods();
42 return array_keys($table);
46 * Display help message for an XMLRPC method
48 * @param string $method
49 * @throws Exception\InvalidArgumentException
52 public function methodHelp($method)
54 $table = $this->server
->getDispatchTable();
55 if (!$table->hasMethod($method)) {
56 throw new Exception\
InvalidArgumentException('Method "' . $method . '" does not exist', 640);
59 return $table->getMethod($method)->getMethodHelp();
63 * Return a method signature
65 * @param string $method
66 * @throws Exception\InvalidArgumentException
69 public function methodSignature($method)
71 $table = $this->server
->getDispatchTable();
72 if (!$table->hasMethod($method)) {
73 throw new Exception\
InvalidArgumentException('Method "' . $method . '" does not exist', 640);
75 $method = $table->getMethod($method)->toArray();
76 return $method['prototypes'];
80 * Multicall - boxcar feature of XML-RPC for calling multiple methods
81 * in a single request.
83 * Expects an array of structs representing method calls, each element
88 * Returns an array of responses, one for each method called, with the value
89 * returned by the method. If an error occurs for a given method, returns a
90 * struct with a fault response.
92 * @see http://www.xmlrpc.com/discuss/msgReader$1208
93 * @param array $methods
96 public function multicall($methods)
99 foreach ($methods as $method) {
101 if (!is_array($method)) {
102 $fault = $this->server
->fault('system.multicall expects each method to be a struct', 601);
103 } elseif (!isset($method['methodName'])) {
104 $fault = $this->server
->fault('Missing methodName: ' . var_export($methods, 1), 602);
105 } elseif (!isset($method['params'])) {
106 $fault = $this->server
->fault('Missing params', 603);
107 } elseif (!is_array($method['params'])) {
108 $fault = $this->server
->fault('Params must be an array', 604);
110 if ('system.multicall' == $method['methodName']) {
111 // don't allow recursive calls to multicall
112 $fault = $this->server
->fault('Recursive system.multicall forbidden', 605);
118 $request = new \Zend\XmlRpc\
Request();
119 $request->setMethod($method['methodName']);
120 $request->setParams($method['params']);
121 $response = $this->server
->handle($request);
122 if ($response instanceof \Zend\XmlRpc\Fault
123 ||
$response->isFault()
127 $responses[] = $response->getReturnValue();
129 } catch (\Exception
$e) {
130 $fault = $this->server
->fault($e);
135 $responses[] = array(
136 'faultCode' => $fault->getCode(),
137 'faultString' => $fault->getMessage()