From 2458e30a86863f2f810e95c6302dbe9bbd0f00f3 Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Sat, 24 Oct 2009 15:28:01 +0000 Subject: [PATCH] MDL-12886 zend base class improvements, somebody forgot to update Zend framework, this should help with compativiltiy too --- webservice/lib.php | 32 ++++++++++++------------------ webservice/rest/locallib.php | 4 ++-- webservice/rest/server.php | 4 ++-- webservice/rest/simpleserver.php | 4 ++-- webservice/xmlrpc/locallib.php | 19 ++++++++++++++---- webservice/xmlrpc/server.php | 4 ++-- webservice/xmlrpc/simpleserver.php | 4 ++-- 7 files changed, 38 insertions(+), 33 deletions(-) diff --git a/webservice/lib.php b/webservice/lib.php index 5f983231eb..3a5637ed80 100644 --- a/webservice/lib.php +++ b/webservice/lib.php @@ -61,10 +61,9 @@ function webservice_protocol_is_enabled($protocol) { interface webservice_server { /** * Process request from client. - * @param bool $simple use simple authentication * @return void */ - public function run($simple); + public function run(); } /** @@ -108,8 +107,10 @@ abstract class webservice_zend_server implements webservice_server { /** * 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; } @@ -118,9 +119,7 @@ abstract class webservice_zend_server implements webservice_server { * @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'); @@ -143,9 +142,12 @@ abstract class webservice_zend_server implements webservice_server { // 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); @@ -333,14 +335,7 @@ class '.$classname.' { * @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'); } /** @@ -499,8 +494,10 @@ abstract class webservice_base_server implements webservice_server { /** * Contructor + * @param bool $simple use simple authentication */ - public function __construct() { + public function __construct($simple) { + $this->simple = $simple; } /** @@ -528,12 +525,9 @@ abstract class webservice_base_server implements webservice_server { /** * 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'); diff --git a/webservice/rest/locallib.php b/webservice/rest/locallib.php index c6eab0d5a7..935852f894 100644 --- a/webservice/rest/locallib.php +++ b/webservice/rest/locallib.php @@ -33,8 +33,8 @@ class webservice_rest_server extends webservice_base_server { /** * Contructor */ - public function __construct() { - parent::__construct(); + public function __construct($simple) { + parent::__construct($simple); $this->wsname = 'rest'; } diff --git a/webservice/rest/server.php b/webservice/rest/server.php index 0e9def198d..6df08b9865 100644 --- a/webservice/rest/server.php +++ b/webservice/rest/server.php @@ -32,7 +32,7 @@ if (!webservice_protocol_is_enabled('rest')) { die; } -$server = new webservice_rest_server(); -$server->run(false); +$server = new webservice_rest_server(false); +$server->run(); die; diff --git a/webservice/rest/simpleserver.php b/webservice/rest/simpleserver.php index 73a5e08e0f..464536ef3b 100644 --- a/webservice/rest/simpleserver.php +++ b/webservice/rest/simpleserver.php @@ -32,8 +32,8 @@ if (!webservice_protocol_is_enabled('rest')) { die; } -$server = new webservice_rest_server(); -$server->run(true); +$server = new webservice_rest_server(true); +$server->run(); die; diff --git a/webservice/xmlrpc/locallib.php b/webservice/xmlrpc/locallib.php index ea4e7865d2..d356a4c597 100644 --- a/webservice/xmlrpc/locallib.php +++ b/webservice/xmlrpc/locallib.php @@ -32,11 +32,23 @@ require_once("$CFG->dirroot/webservice/lib.php"); 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'); + } } /** @@ -54,8 +66,7 @@ class webservice_xmlrpc_test_client implements webservice_test_client_interface //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); } diff --git a/webservice/xmlrpc/server.php b/webservice/xmlrpc/server.php index 0a8bde0251..23e2bb4179 100644 --- a/webservice/xmlrpc/server.php +++ b/webservice/xmlrpc/server.php @@ -32,7 +32,7 @@ if (!webservice_protocol_is_enabled('xmlrpc')) { die; } -$server = new webservice_xmlrpc_server(); -$server->run(false); +$server = new webservice_xmlrpc_server(true); +$server->run(); die; diff --git a/webservice/xmlrpc/simpleserver.php b/webservice/xmlrpc/simpleserver.php index c7a1338b35..d05578fd62 100644 --- a/webservice/xmlrpc/simpleserver.php +++ b/webservice/xmlrpc/simpleserver.php @@ -39,8 +39,8 @@ if (!webservice_protocol_is_enabled('xmlrpc')) { die; } -$server = new webservice_xmlrpc_server(); -$server->run(true); +$server = new webservice_xmlrpc_server(true); +$server->run(); die; -- 2.39.5