aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoricewing <icewing@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-03-25 14:25:27 +0000
committericewing <icewing@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-03-25 14:25:27 +0000
commitdf7287609844fc382d1af8538d1c5e98b209f258 (patch)
treedc13a5bd65622833192a660234fdc344e626fd33
parent495c1cbee5cf0f601655c045332cd5d35759bf1b (diff)
downloadelgg-df7287609844fc382d1af8538d1c5e98b209f258.tar.gz
elgg-df7287609844fc382d1af8538d1c5e98b209f258.tar.bz2
Marcus Povey <marcus@dushka.co.uk>
* Array support added to api git-svn-id: https://code.elgg.org/elgg/trunk@266 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r--engine/lib/api.php47
1 files changed, 42 insertions, 5 deletions
diff --git a/engine/lib/api.php b/engine/lib/api.php
index b2696ade9..5ad5e6602 100644
--- a/engine/lib/api.php
+++ b/engine/lib/api.php
@@ -232,7 +232,12 @@
*
* @param string $method The api name to expose this as, eg "myapi.dosomething"
* @param string $function Your function callback.
- * @param array $parameters Optional list of parameters in the same order as in your function, with optional parameters last.
+ * @param array $parameters Optional list of parameters in the same order as in your function, with optional parameters last.
+ * This array should be in the format
+ * "variable" = array (
+ * type => 'int' | 'bool' | 'float' | 'string' | 'array'
+ * required => true (default) | false
+ * )
* @param string $call_method Define what call method should be used for this function.
* @param bool $require_auth Whether this requires a user authentication token or not (default is true)
* @param string $description Optional human readable description of the function.
@@ -295,7 +300,7 @@
if ((isset($METHODS[$method]["function"])) && (is_callable($METHODS[$method]["function"])))
{
// See if this is being made with the right call method
- if (strcmp(get_call_method(), $METHODS[$method]["call_method"]))
+ if (strcmp(get_call_method(), $METHODS[$method]["call_method"])==0)
{
$serialised_parameters = "";
@@ -341,6 +346,28 @@
break;
case 'float': $serialised_parameters .= "," . (float)trim($parameters[$key]);
break;
+ case 'array':
+ $array = "array(";
+
+ if (is_array($parameters[$key]))
+ {
+ foreach ($parameters[$key] as $k => $v)
+ {
+ $k = sanitise_string($k);
+ $v = sanitise_string($v);
+
+ $array .= "'$k'=>'$v',";
+ }
+
+ $array = trim($array,",");
+ }
+ else
+ throw APIException("$key does not appear to be an array.");
+
+ $array .= ")";
+
+ $serialised_parameters .= $array;
+ break;
default : throw new APIException("Unrecognised type in cast {$value['type']} for variable '$key' in method '$method'");
}
@@ -386,14 +413,24 @@
/**
* Simple api to return a list of all api's installed on the system.
*/
- function list_all_apis()
+ function list_all_apis(array $foo)
{
global $METHODS;
- return $METHODS;
+ //return $METHODS;
+return $foo;
}
// Expose some system api functions
- expose_function("system.api.list", "list_all_apis", NULL, "GET", false, "List all available API calls on the system.");
+ expose_function("system.api.list", "list_all_apis", array(
+ "bibble" => array(
+ 'type' => 'array',
+ 'required' => true
+ ),
+ "monkey" => array (
+ 'type' => 'int',
+ 'required' => true
+ )
+ ), "GET", false, "List all available API calls on the system.");
// PAM AUTH HMAC functions ////////////////////////////////////////////////////////////////