interface webservice_server {
/**
* Process request from client.
- * @param bool $simple use simple authentication
* @return void
*/
- public function run($simple);
+ public function run();
}
/**
/**
* Contructor
+ * @param bool $simple use simple authentication
*/
- public function __construct($zend_class) {
+ public function __construct($simple, $zend_class) {
+ $this->simple = $simple;
$this->zend_class = $zend_class;
}
* @param bool $simple use simple authentication
* @return void
*/
- public function run($simple) {
- $this->simple = $simple;
-
+ public function run() {
// we will probably need a lot of memory in some functions
@raise_memory_limit('128M');
// make a list of all functions user is allowed to excecute
$this->init_service_class();
- // start the server
+ // tell server what functions are available
$this->zend_server->setClass($this->service_class);
+
+ // execute and return response, this sends some headers too
$response = $this->zend_server->handle();
+
/*
$grrr = ob_get_clean();
error_log($grrr);
* @return void
*/
protected function init_zend_server() {
- include "Zend/Loader.php";
- Zend_Loader::registerAutoload();
- //TODO: set up some server options and debugging too - maybe a new method
- //TODO: add some zend exeption handler too
$this->zend_server = new $this->zend_class();
-
- // TODO: solve debugging level somehow
- Zend_XmlRpc_Server_Fault::attachFaultException('moodle_exception');
}
/**
/**
* Contructor
+ * @param bool $simple use simple authentication
*/
- public function __construct() {
+ public function __construct($simple) {
+ $this->simple = $simple;
}
/**
/**
* Process request from client.
- * @param bool $simple use simple authentication
* @return void
*/
- public function run($simple) {
- $this->simple = $simple;
-
+ public function run() {
// we will probably need a lot of memory in some functions
@raise_memory_limit('128M');
class webservice_xmlrpc_server extends webservice_zend_server {
/**
* Contructor
+ * @param bool $simple use simple authentication
*/
- public function __construct() {
- parent::__construct('Zend_XmlRpc_Server');
+ public function __construct($simple) {
+ require_once 'Zend/XmlRpc/Server.php';
+ parent::__construct($simple, 'Zend_XmlRpc_Server');
$this->wsname = 'xmlrpc';
}
+
+ /**
+ * Set up zend serice class
+ * @return void
+ */
+ protected function init_zend_server() {
+ parent::init_zend_server();
+ // this exception indicates request failed
+ Zend_XmlRpc_Server_Fault::attachFaultException('moodle_exception');
+ }
}
/**
//zend expects 0 based array with numeric indexes
$params = array_values($params);
- include "Zend/Loader.php";
- Zend_Loader::registerAutoload();
+ require_once 'Zend/XmlRpc/Client.php';
$client = new Zend_XmlRpc_Client($serverurl);
return $client->call($function, $params);
}