From 63cea891b9de7a2809e5582b038d8f50505ca975 Mon Sep 17 00:00:00 2001 From: jerome Date: Wed, 18 Feb 2009 05:01:10 +0000 Subject: [PATCH] web service MDL-12886 add beta documentation generator --- webservice/documentation.php | 187 ++++++++++++++++++ .../soap/testclient/zend_soap_client.php | 1 - 2 files changed, 187 insertions(+), 1 deletion(-) create mode 100644 webservice/documentation.php diff --git a/webservice/documentation.php b/webservice/documentation.php new file mode 100644 index 0000000000..22d59576ef --- /dev/null +++ b/webservice/documentation.php @@ -0,0 +1,187 @@ +SOAP Manual + 1. Call the method tmp_get_token on "http://remotemoodle/webservice/soap/zend_soap_server.php?wsdl"
+ Function parameter is an array: in PHP it would be array('username' => "wsuser", 'password' => "wspassword")
+ Return value is a token (integer)
+
+ 2. Then call a moodle web service method on "http://remotemoodle/webservice/soap/zend_soap_server.php?token=the_received_token&classpath=the_moodle_path&wsdl"
+ Every method has only one parameter which is an array.
+
+ For example in PHP for this specific function:
+ Moodle path: user
+ tmp_delete_user( string username, integer mnethostid, )
+ You will call something like:
+ your_client->tmp_delete_user(array('username' => "username_to_delete",'mnethostid' => 1))
+ +EOF; + break; + default: + break; + } + echo $documentation; +} + + +function generate_functionlist () { + global $CFG; + $documentation = <<list of web services functions +EOF; + + //retrieve all external file + $externalfiles = array(); + $externalfunctions = array(); + setListApiFiles($externalfiles, $CFG->dirroot); + + foreach ($externalfiles as $file) { + require($file); + + $classpath = substr($file,strlen($CFG->dirroot)+1); //remove the dir root + / from the file path + $classpath = substr($classpath,0,strlen($classpath) - 13); //remove /external.php from the classpath + $classpath = str_replace('/','_',$classpath); //convert all / into _ + $classname = $classpath."_external"; + $api = new $classname(); + $documentation .= <<Moodle path: {$classpath} +EOF; + + foreach($api->get_descriptions() as $functionname => $description) { + + $documentation .= <<{$functionname}( + +EOF; + + foreach ($description['params'] as $param => $paramtype) { + $wsparamtype = converterMoodleParamIntoWsParam($paramtype); + $documentation .= << +EOF; + foreach ($description['optionalparams'] as $param => $paramtype) { + $wsparamtype = converterMoodleParamIntoWsParam($paramtype); + $documentation .= << +EOF; + $documentation .= << +EOF; + } + + } + + echo $documentation; + +} + + /** + * Convert a Moodle type (PARAM_ALPHA, PARAM_NUMBER,...) as a SOAP type (string, interger,...) + * @param integer $moodleparam + * @return string SOAP type + */ +function converterMoodleParamIntoWsParam($moodleparam) { + switch ($moodleparam) { + case PARAM_NUMBER: + return "integer"; + break; + case PARAM_INT: + return "integer"; + break; + case PARAM_BOOL: + return "boolean"; + break; + case PARAM_ALPHANUM: + return "string"; + break; + case PARAM_RAW: + return "string"; + break; + default: + return "object"; + break; + } +} + + /** + * Retrieve all external.php from Moodle + * @param $ + * @param $directorypath + * @return boolean true if n + */ +function setListApiFiles( &$files, $directorypath ) +{ + if(is_dir($directorypath)){ //check that we are browsing a folder not a file + + if( $dh = opendir($directorypath)) + { + while( false !== ($file = readdir($dh))) + { + + if( $file == '.' || $file == '..') { // Skip '.' and '..' + continue; + } + $path = $directorypath . '/' . $file; + ///browse the subfolder + if( is_dir($path) ) { + setListApiFiles($files, $path); + } + ///retrieve api.php file + else if ($file == "external.php") { + $files[] = $path; + } + } + closedir($dh); + + } + } +} + + +?> diff --git a/webservice/soap/testclient/zend_soap_client.php b/webservice/soap/testclient/zend_soap_client.php index 063aa9f625..219efbd64c 100644 --- a/webservice/soap/testclient/zend_soap_client.php +++ b/webservice/soap/testclient/zend_soap_client.php @@ -41,7 +41,6 @@ try { } catch (moodle_exception $exception) { echo $exception; } -echo $CFG->wwwroot."/webservice/soap/zend_soap_server.php?token=".$token."&classpath=user&wsdl"; //2. test functions $client = new Zend_Soap_Client($CFG->wwwroot."/webservice/soap/zend_soap_server.php?token=".$token."&classpath=user&wsdl"); -- 2.39.5