2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
19 * XML-RPC web service implementation classes and methods.
21 * @package webservice_xmlrpc
22 * @copyright 2009 Petr Skodak
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 require_once("$CFG->dirroot/webservice/lib.php");
27 require_once 'Zend/XmlRpc/Server.php';
30 * The Zend XMLRPC server but with a fault that return debuginfo
32 * @package webservice_xmlrpc
33 * @copyright 2011 Jerome Mouneyrac
34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37 class moodle_zend_xmlrpc_server
extends Zend_XmlRpc_Server
{
40 * Raise an xmlrpc server fault
42 * Moodle note: the difference with the Zend server is that we throw a plain PHP Exception
43 * with the debuginfo integrated to the exception message when DEBUG >= NORMAL
45 * @param string|Exception $fault
47 * @return Zend_XmlRpc_Server_Fault
49 public function fault($fault = null, $code = 404)
51 //intercept any exceptions with debug info and transform it in Moodle exception
52 if ($fault instanceof Exception
) {
53 //add the debuginfo to the exception message if debuginfo must be returned
54 if (debugging() and isset($fault->debuginfo
)) {
55 $fault = new Exception($fault->getMessage() . ' | DEBUG INFO: ' . $fault->debuginfo
, 0);
59 return parent
::fault($fault, $code);
64 * XML-RPC service server implementation.
66 * @package webservice_xmlrpc
67 * @copyright 2009 Petr Skodak
68 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
71 class webservice_xmlrpc_server
extends webservice_zend_server
{
76 * @param string $authmethod authentication method of the web service (WEBSERVICE_AUTHMETHOD_PERMANENT_TOKEN, ...)
78 public function __construct($authmethod) {
79 require_once 'Zend/XmlRpc/Server.php';
80 parent
::__construct($authmethod, 'moodle_zend_xmlrpc_server');
81 $this->wsname
= 'xmlrpc';
85 * Set up zend service class
87 protected function init_zend_server() {
88 parent
::init_zend_server();
89 // this exception indicates request failed
90 Zend_XmlRpc_Server_Fault
::attachFaultException('moodle_exception');
91 //when DEBUG >= NORMAL then the thrown exceptions are "casted" into a plain PHP Exception class
92 //in order to display the $debuginfo (see moodle_zend_xmlrpc_server class - MDL-29435)
94 Zend_XmlRpc_Server_Fault
::attachFaultException('Exception');
101 * XML-RPC test client class
103 * @package webservice_xmlrpc
104 * @copyright 2009 Petr Skodak
105 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
108 class webservice_xmlrpc_test_client
implements webservice_test_client_interface
{
110 * Execute test client WS request
111 * @param string $serverurl server url (including token parameter or username/password parameters)
112 * @param string $function function name
113 * @param array $params parameters of the called function
116 public function simpletest($serverurl, $function, $params) {
117 //zend expects 0 based array with numeric indexes
118 $params = array_values($params);
120 require_once 'Zend/XmlRpc/Client.php';
121 $client = new Zend_XmlRpc_Client($serverurl);
122 return $client->call($function, $params);