]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-12886 api improvments - the actuall validation implementation is missing - we...
authorskodak <skodak>
Wed, 16 Sep 2009 18:06:31 +0000 (18:06 +0000)
committerskodak <skodak>
Wed, 16 Sep 2009 18:06:31 +0000 (18:06 +0000)
lib/externallib.php

index 9d086d710221d7aed3dfffeba96072c2de7f62f2..57c3ea93b951c1553a52134a978da8d6b9c41c11 100644 (file)
@@ -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);