forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
webservice MDL-12886 refactor web service description + implement cle…
…an_function_params() function
- Loading branch information
jerome
committed
Aug 25, 2009
1 parent
8676e9e
commit fbe52a3
Showing
6 changed files
with
511 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?php | ||
/* | ||
* Created on 01/12/2008 | ||
* | ||
* Moodle base webservice api | ||
* | ||
* @author Jerome Mouneyrac | ||
*/ | ||
|
||
/** | ||
* DO NOT USE ANYTHING FROM THIS FILE - WORK IN PROGRESS | ||
*/ | ||
abstract class moodle_external { | ||
|
||
protected $descriptions; | ||
|
||
/** | ||
* Constructor - We set the description of this API in order to be access by Web service | ||
*/ | ||
function __construct () { | ||
$this->descriptions = array(); | ||
} | ||
|
||
/** | ||
* | ||
* @param string $functionname | ||
* @return array | ||
*/ | ||
public function get_function_webservice_description($functionname) { | ||
if (key_exists($functionname, $this->descriptions)) { | ||
return $this->descriptions[$functionname]; | ||
} | ||
else { | ||
return false; | ||
} | ||
} | ||
|
||
/** | ||
* | ||
* @return array | ||
*/ | ||
public function get_descriptions() { | ||
return $this->descriptions; | ||
} | ||
|
||
/** | ||
* This function clean params, because it should only be called by external itself, it has to be protected (server should not call it) | ||
* @param array $params | ||
*/ | ||
protected function clean_function_params($functionname, &$params) { | ||
$description = $this->get_function_webservice_description($functionname); | ||
varlog($functionname); | ||
foreach ($params as $param) { //we are applying the algo for all params | ||
$key = key($description['params']); //get next key of the description array => params need to be ordered ! | ||
$this->clean_params($description['params'][$key], $param); | ||
|
||
} | ||
} | ||
|
||
/** | ||
* | ||
* @param <type> $params | ||
*/ | ||
protected function clean_params($description, &$params) { | ||
if (!is_array($params)) { | ||
$paramvalue = clean_param($params, $description); | ||
} else { | ||
foreach ($params as $paramname => &$paramvalue) { | ||
if (is_array($paramvalue)) { //it's a list | ||
//A description array does not support list of different objects | ||
//it's why we retrieve the first key, because there should be only one key | ||
$this->clean_params($description[key($description)], $paramvalue); | ||
} | ||
else { | ||
if (is_object($paramvalue)) { //is it a object | ||
$this->clean_object_types($description[$paramname], $paramvalue); | ||
} | ||
else { //it's a primary type | ||
$paramvalue = clean_param($paramvalue, $description[$paramname]); | ||
} | ||
} | ||
|
||
|
||
} | ||
|
||
} | ||
} | ||
|
||
protected function clean_object_types($objectdescription, &$paramobject) { | ||
foreach (get_object_vars($paramobject) as $propertyname => $propertyvalue) { | ||
if (is_array($propertyvalue)) { | ||
$this->clean_params($objectdescription->$propertyname, $propertyvalue); | ||
$paramobject->$propertyname = $propertyvalue; | ||
} else { | ||
$paramobject->$propertyname = clean_param($propertyvalue, $objectdescription->$propertyname); | ||
|
||
} | ||
} | ||
} | ||
|
||
} | ||
?> |
Oops, something went wrong.