MDL-12886 api improvments - the actuall validation implementation is missing - we need to finalize the param description first
This commit is contained in:
+18
-15
@@ -41,14 +41,30 @@ class restricted_context_exception extends moodle_exception {
|
||||
* Base class for external api methods.
|
||||
*/
|
||||
class external_api {
|
||||
|
||||
|
||||
private static $contextrestriction;
|
||||
|
||||
/**
|
||||
* Set context restriction for all folowing subsequent function calls.
|
||||
* @param stdClass $contex
|
||||
* @return void
|
||||
*/
|
||||
public static function set_context_restriction($contex) {
|
||||
self::$contextrestriction = $context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates submitted function barameters, if anything is incorrect
|
||||
* invalid_parameter_exception is thrown.
|
||||
* @param ? $description description of parameters
|
||||
* @param array $params the actual parameters
|
||||
* @return ? params with added defaults for optional items, invalid_parameters_exception thrown if any problem found
|
||||
*/
|
||||
public static function validate_params($description, $params) {
|
||||
//TODO: we need to define the structure of param descriptions
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes sure user may execute functions in this context.
|
||||
* @param object $context
|
||||
@@ -90,18 +106,6 @@ class external_api {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Some automatic type validation of parameters
|
||||
* @param string $functionname
|
||||
* @param mixed $params
|
||||
* @return mixed cleaned parameters
|
||||
*/
|
||||
protected static function cleanparams($functionname, $params) {
|
||||
//TODO: implement cleaning
|
||||
// do we need this? We need only basic data types for web services, right?
|
||||
return $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns detailed information about external function
|
||||
* @param string $functionname name of external function
|
||||
@@ -110,7 +114,6 @@ class external_api {
|
||||
public static function get_function_info($functionname) {
|
||||
global $CFG, $DB;
|
||||
|
||||
//TODO: this is very slow, we should add some caching here
|
||||
$function = $DB->get_record('external_functions', array('name'=>$functionname), '*', MUST_EXIST);
|
||||
|
||||
$defpath = get_component_directory($function->component);
|
||||
|
||||
Reference in New Issue
Block a user