From b3d58bceb96fd8cd6e7f08a26f138c0398372f4e Mon Sep 17 00:00:00 2001 From: jerome Date: Wed, 2 Sep 2009 03:58:09 +0000 Subject: [PATCH] web services MDL-12886 ws params: objects into an object were not cleaned, neither documented --- lib/moodleexternal.php | 26 +++++++++++++++----------- webservice/wsdoc.php | 34 ++++++++++++++++------------------ 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/lib/moodleexternal.php b/lib/moodleexternal.php index 9ff5a382fb..9bbd367322 100644 --- a/lib/moodleexternal.php +++ b/lib/moodleexternal.php @@ -62,12 +62,12 @@ abstract class moodle_external { $nextdescriptionkey = key($description); if (isset($nextdescriptionkey)) { $this->clean_params($description[$nextdescriptionkey], $params[key($params)]); - } else { + } else { throw new moodle_exception('wswrongparams'); } } else { - if (is_object($params)) { //is it a object + if (is_object($params)) { //it's an object $this->clean_object($description, $params); } else { //it's a primary type @@ -79,18 +79,22 @@ abstract class moodle_external { protected function clean_object($objectdescription, &$paramobject) { foreach (get_object_vars($paramobject) as $propertyname => $propertyvalue) { - if (is_array($propertyvalue)) { - if (isset($objectdescription->$propertyname)) { - $this->clean_params($objectdescription->$propertyname, $propertyvalue); + if (!isset($objectdescription->$propertyname)) { //if the param is not defined into the web service description + throw new moodle_exception('wswrongparams'); //throw exception + } + if (is_array($propertyvalue)) { //the object property is a list + $this->clean_params($objectdescription->$propertyname, $propertyvalue); + $paramobject->$propertyname = $propertyvalue; + + } + else { + if (is_object($propertyvalue)) { //the object property is an object + $this->clean_object($objectdescription->$propertyname, $propertyvalue); $paramobject->$propertyname = $propertyvalue; - } else { - throw new moodle_exception('wswrongparams'); } - } else { - if (isset($objectdescription->$propertyname)) { + else { //the object property is a primary type $paramobject->$propertyname = clean_param($propertyvalue, $objectdescription->$propertyname); - } else { - throw new moodle_exception('wswrongparams'); + } } } diff --git a/webservice/wsdoc.php b/webservice/wsdoc.php index f08eaba149..5e2c97c933 100644 --- a/webservice/wsdoc.php +++ b/webservice/wsdoc.php @@ -96,8 +96,8 @@ function generate_functionlist () { EOF; $arrayparams = array(); $comma=""; + //TODO: this is not an array anymore!!! (all algo function) foreach($functiondescription['params'] as $param => $type) { - // $type = converterMoodleParamIntoWsParam($type); $documentation .= <<{$comma} {$type} {$param} EOF; @@ -110,7 +110,6 @@ EOF; EOF; if (array_key_exists('return', $functiondescription)) { foreach($functiondescription['return'] as $return => $type) { - // $thetype = converterMoodleParamIntoWsParam($type); $documentation .= << @@ -137,7 +136,6 @@ EOF; EOF; } else { - // $type = converterMoodleParamIntoWsParam($type); $documentation .= <<{$param} : {$type}
EOF; @@ -167,26 +165,28 @@ function convertDescriptionType(&$description) { } else { if (is_object($type)) { //is it a object - convertObjectTypes($type); + convertObjectTypes($type); } else { //it's a primary type - - $type = converterMoodleParamIntoWsParam($type); + $type = converterMoodleParamIntoWsParam($type); } } - } } function convertObjectTypes(&$type) { - foreach (get_object_vars($type) as $propertyname => $propertytype) { - if (is_array($propertytype)) { - convertDescriptionType($propertytype); - $type->$propertyname = $propertytype; - } else { - $type->$propertyname = converterMoodleParamIntoWsParam($propertytype); - } - } + foreach (get_object_vars($type) as $propertyname => $propertytype) { //browse all properties of the object + if (is_array($propertytype)) { //the property is an array + convertDescriptionType($propertytype); + $type->$propertyname = $propertytype; + } else if (is_object($propertytype)) { //the property is an object + convertObjectTypes($propertytype); + $type->$propertyname = $propertytype; + } + else { //the property is a primary type + $type->$propertyname = converterMoodleParamIntoWsParam($propertytype); + } + } } /** @@ -208,7 +208,7 @@ function converterMoodleParamIntoWsParam($moodleparam) { case PARAM_ALPHANUM: return "string"; break; - case PARAM_ALPHA: + case PARAM_ALPHA: return "string"; break; case PARAM_RAW: @@ -238,8 +238,6 @@ function converterMoodleParamIntoWsParam($moodleparam) { return "string"; break; default: - - //return get_object_vars($moodleparam); return "object"; break; } -- 2.39.5