[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 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. 8 // 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. 13 // 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/>. 16 17 18 /** 19 * XML-RPC web service implementation classes and methods. 20 * 21 * @package webservice_xmlrpc 22 * @copyright 2009 Petr Skodak 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 require_once("$CFG->dirroot/webservice/lib.php"); 27 require_once 'Zend/XmlRpc/Server.php'; 28 29 /** 30 * The Zend XMLRPC server but with a fault that return debuginfo 31 * 32 * @package webservice_xmlrpc 33 * @copyright 2011 Jerome Mouneyrac 34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 35 * @since Moodle 2.2 36 */ 37 class moodle_zend_xmlrpc_server extends Zend_XmlRpc_Server { 38 39 /** 40 * Raise an xmlrpc server fault 41 * 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 44 * 45 * @param string|Exception $fault 46 * @param int $code 47 * @return Zend_XmlRpc_Server_Fault 48 */ 49 public function fault($fault = null, $code = 404) 50 { 51 // Intercept any exceptions with debug info and transform it in Moodle exception. 52 if ($fault instanceof Exception) { 53 // Code php exception must be a long 54 // we obtain a hash of the errorcode, and then to get an integer hash. 55 $code = base_convert(md5($fault->errorcode), 16, 10); 56 // Code php exception being a long, it has a maximum number of digits. 57 // we strip the $code to 8 digits, and hope for no error code collisions. 58 // Collisions should be pretty rare, and if needed the client can retrieve 59 // the accurate errorcode from the last | in the exception message. 60 $code = substr($code, 0, 8); 61 // Add the debuginfo to the exception message if debuginfo must be returned. 62 if (debugging() and isset($fault->debuginfo)) { 63 $fault = new Exception($fault->getMessage() . ' | DEBUG INFO: ' . $fault->debuginfo 64 . ' | ERRORCODE: ' . $fault->errorcode, $code); 65 } else { 66 $fault = new Exception($fault->getMessage() 67 . ' | ERRORCODE: ' . $fault->errorcode, $code); 68 } 69 } 70 71 return parent::fault($fault, $code); 72 } 73 } 74 75 /** 76 * XML-RPC service server implementation. 77 * 78 * @package webservice_xmlrpc 79 * @copyright 2009 Petr Skodak 80 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 81 * @since Moodle 2.0 82 */ 83 class webservice_xmlrpc_server extends webservice_zend_server { 84 85 /** 86 * Contructor 87 * 88 * @param string $authmethod authentication method of the web service (WEBSERVICE_AUTHMETHOD_PERMANENT_TOKEN, ...) 89 */ 90 public function __construct($authmethod) { 91 require_once 'Zend/XmlRpc/Server.php'; 92 parent::__construct($authmethod, 'moodle_zend_xmlrpc_server'); 93 $this->wsname = 'xmlrpc'; 94 } 95 96 /** 97 * Set up zend service class 98 */ 99 protected function init_zend_server() { 100 parent::init_zend_server(); 101 // this exception indicates request failed 102 Zend_XmlRpc_Server_Fault::attachFaultException('moodle_exception'); 103 //when DEBUG >= NORMAL then the thrown exceptions are "casted" into a plain PHP Exception class 104 //in order to display the $debuginfo (see moodle_zend_xmlrpc_server class - MDL-29435) 105 if (debugging()) { 106 Zend_XmlRpc_Server_Fault::attachFaultException('Exception'); 107 } 108 } 109 110 } 111 112 /** 113 * XML-RPC test client class 114 * 115 * @package webservice_xmlrpc 116 * @copyright 2009 Petr Skodak 117 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 118 * @since Moodle 2.0 119 */ 120 class webservice_xmlrpc_test_client implements webservice_test_client_interface { 121 /** 122 * Execute test client WS request 123 * @param string $serverurl server url (including token parameter or username/password parameters) 124 * @param string $function function name 125 * @param array $params parameters of the called function 126 * @return mixed 127 */ 128 public function simpletest($serverurl, $function, $params) { 129 //zend expects 0 based array with numeric indexes 130 $params = array_values($params); 131 132 require_once 'Zend/XmlRpc/Client.php'; 133 $client = new Zend_XmlRpc_Client($serverurl); 134 return $client->call($function, $params); 135 } 136 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |