[ZF-10089] Zend_Log
[zend/radio.git] / library / Zend / XmlRpc / Server / System.php
blobd49d0fc3e72b8ad6bacc4a2323b58527f83ad42a
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 Server
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$
23 /**
24 * XML-RPC system.* methods
26 * @category Zend
27 * @package Zend_XmlRpc
28 * @subpackage Server
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
32 class Zend_XmlRpc_Server_System
34 /**
35 * @var Zend_XmlRpc_Server
37 protected $_server;
39 /**
40 * Constructor
42 * @param Zend_XmlRpc_Server $server
43 * @return void
45 public function __construct(Zend_XmlRpc_Server $server)
47 $this->_server = $server;
50 /**
51 * List all available XMLRPC methods
53 * Returns an array of methods.
55 * @return array
57 public function listMethods()
59 $table = $this->_server->getDispatchTable()->getMethods();
60 return array_keys($table);
63 /**
64 * Display help message for an XMLRPC method
66 * @param string $method
67 * @return string
69 public function methodHelp($method)
71 $table = $this->_server->getDispatchTable();
72 if (!$table->hasMethod($method)) {
73 require_once 'Zend/XmlRpc/Server/Exception.php';
74 throw new Zend_XmlRpc_Server_Exception('Method "' . $method . '" does not exist', 640);
77 return $table->getMethod($method)->getMethodHelp();
80 /**
81 * Return a method signature
83 * @param string $method
84 * @return array
86 public function methodSignature($method)
88 $table = $this->_server->getDispatchTable();
89 if (!$table->hasMethod($method)) {
90 require_once 'Zend/XmlRpc/Server/Exception.php';
91 throw new Zend_XmlRpc_Server_Exception('Method "' . $method . '" does not exist', 640);
93 $method = $table->getMethod($method)->toArray();
94 return $method['prototypes'];
97 /**
98 * Multicall - boxcar feature of XML-RPC for calling multiple methods
99 * in a single request.
101 * Expects a an array of structs representing method calls, each element
102 * having the keys:
103 * - methodName
104 * - params
106 * Returns an array of responses, one for each method called, with the value
107 * returned by the method. If an error occurs for a given method, returns a
108 * struct with a fault response.
110 * @see http://www.xmlrpc.com/discuss/msgReader$1208
111 * @param array $methods
112 * @return array
114 public function multicall($methods)
116 $responses = array();
117 foreach ($methods as $method) {
118 $fault = false;
119 if (!is_array($method)) {
120 $fault = $this->_server->fault('system.multicall expects each method to be a struct', 601);
121 } elseif (!isset($method['methodName'])) {
122 $fault = $this->_server->fault('Missing methodName: ' . var_export($methods, 1), 602);
123 } elseif (!isset($method['params'])) {
124 $fault = $this->_server->fault('Missing params', 603);
125 } elseif (!is_array($method['params'])) {
126 $fault = $this->_server->fault('Params must be an array', 604);
127 } else {
128 if ('system.multicall' == $method['methodName']) {
129 // don't allow recursive calls to multicall
130 $fault = $this->_server->fault('Recursive system.multicall forbidden', 605);
134 if (!$fault) {
135 try {
136 $request = new Zend_XmlRpc_Request();
137 $request->setMethod($method['methodName']);
138 $request->setParams($method['params']);
139 $response = $this->_server->handle($request);
140 if ($response instanceof Zend_XmlRpc_Fault
141 || $response->isFault()
143 $fault = $response;
144 } else {
145 $responses[] = $response->getReturnValue();
147 } catch (Exception $e) {
148 $fault = $this->_server->fault($e);
152 if ($fault) {
153 $responses[] = array(
154 'faultCode' => $fault->getCode(),
155 'faultString' => $fault->getMessage()
160 return $responses;