mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-32581 support additional format field with all text field in extrnal lib function + new possible ws params to decide how format is returned (which are stored in a singleton)
This commit is contained in:
parent
4631e39533
commit
93ce0e8296
11 changed files with 382 additions and 88 deletions
|
@ -960,6 +960,38 @@ abstract class webservice_server implements webservice_server_interface {
|
|||
return $user;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Intercept some moodlewssettingXXX $_GET and $_POST parameter
|
||||
* that are related to the web service call and are not the function parameters
|
||||
*/
|
||||
protected function set_web_service_call_settings() {
|
||||
global $CFG;
|
||||
|
||||
// Default web service settings.
|
||||
// Must be the same XXX key name as the external_settings::set_XXX function.
|
||||
// Must be the same XXX ws parameter name as 'moodlewssettingXXX'.
|
||||
$externalsettings = array(
|
||||
'raw' => false,
|
||||
'fileurl' => true,
|
||||
'filter' => false);
|
||||
|
||||
// Load the external settings with the web service settings.
|
||||
$settings = external_settings::get_instance();
|
||||
foreach ($externalsettings as $name => $default) {
|
||||
|
||||
$wsparamname = 'moodlewssetting' . $name;
|
||||
|
||||
// Retrieve and remove the setting parameter from the request.
|
||||
$value = optional_param($wsparamname, $default, PARAM_BOOL);
|
||||
unset($_GET[$wsparamname]);
|
||||
unset($_POST[$wsparamname]);
|
||||
|
||||
$functioname = 'set_' . $name;
|
||||
$settings->$functioname($value);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1336,7 +1368,10 @@ class '.$classname.' {
|
|||
*/
|
||||
protected function parse_request() {
|
||||
|
||||
//Get GET and POST paramters
|
||||
// We are going to clean the POST/GET parameters from the parameters specific to the server.
|
||||
parent::set_web_service_call_settings();
|
||||
|
||||
// Get GET and POST paramters.
|
||||
$methodvariables = array_merge($_GET,$_POST);
|
||||
|
||||
if ($this->authmethod == WEBSERVICE_AUTHMETHOD_USERNAME) {
|
||||
|
|
|
@ -43,10 +43,9 @@ class webservice_rest_server extends webservice_base_server {
|
|||
* @param string $authmethod authentication method of the web service (WEBSERVICE_AUTHMETHOD_PERMANENT_TOKEN, ...)
|
||||
* @param string $restformat Format of the return values: 'xml' or 'json'
|
||||
*/
|
||||
public function __construct($authmethod, $restformat = 'xml') {
|
||||
public function __construct($authmethod) {
|
||||
parent::__construct($authmethod);
|
||||
$this->wsname = 'rest';
|
||||
$this->restformat = ($restformat != 'xml' && $restformat != 'json')?'xml':$restformat; //sanity check, we accept only xml or json
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -55,11 +54,22 @@ class webservice_rest_server extends webservice_base_server {
|
|||
* 1/ user authentication - username+password or token (wsusername, wspassword and wstoken parameters)
|
||||
* 2/ function name (wsfunction parameter)
|
||||
* 3/ function parameters (all other parameters except those above)
|
||||
* 4/ text format parameters
|
||||
* 5/ return rest format xml/json
|
||||
*/
|
||||
protected function parse_request() {
|
||||
|
||||
//Get GET and POST paramters
|
||||
$methodvariables = array_merge($_GET,$_POST);
|
||||
// Retrieve and clean the POST/GET parameters from the parameters specific to the server.
|
||||
parent::set_web_service_call_settings();
|
||||
|
||||
// Get GET and POST parameters.
|
||||
$methodvariables = array_merge($_GET, $_POST);
|
||||
|
||||
// Retrieve REST format parameter - 'xml' (default) or 'json'.
|
||||
$restformatisset = isset($methodvariables['moodlewsrestformat'])
|
||||
&& (($methodvariables['moodlewsrestformat'] == 'xml' || $methodvariables['moodlewsrestformat'] == 'json'));
|
||||
$this->restformat = $restformatisset ? $methodvariables['moodlewsrestformat'] : 'xml';
|
||||
unset($methodvariables['moodlewsrestformat']);
|
||||
|
||||
if ($this->authmethod == WEBSERVICE_AUTHMETHOD_USERNAME) {
|
||||
$this->username = isset($methodvariables['wsusername']) ? $methodvariables['wsusername'] : null;
|
||||
|
|
|
@ -42,16 +42,7 @@ if (!webservice_protocol_is_enabled('rest')) {
|
|||
die;
|
||||
}
|
||||
|
||||
$restformat = optional_param('moodlewsrestformat', 'xml', PARAM_ALPHA);
|
||||
//remove the alt from the request
|
||||
if(isset($_GET['moodlewsrestformat'])) {
|
||||
unset($_GET['moodlewsrestformat']);
|
||||
}
|
||||
if(isset($_POST['moodlewsrestformat'])) {
|
||||
unset($_POST['moodlewsrestformat']);
|
||||
}
|
||||
|
||||
$server = new webservice_rest_server(WEBSERVICE_AUTHMETHOD_PERMANENT_TOKEN, $restformat);
|
||||
$server = new webservice_rest_server(WEBSERVICE_AUTHMETHOD_PERMANENT_TOKEN);
|
||||
$server->run();
|
||||
die;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue