From: Petr Skoda Date: Mon, 26 Oct 2009 22:39:08 +0000 (+0000) Subject: MDL-12886 inproved hadnling of bool ws params and return values X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=4f0c6ad11013f14e44619abd38d1878c64f6683a;p=moodle.git MDL-12886 inproved hadnling of bool ws params and return values --- diff --git a/lib/externallib.php b/lib/externallib.php index 6bcfc6a340..6e2b0458bd 100644 --- a/lib/externallib.php +++ b/lib/externallib.php @@ -163,6 +163,13 @@ class external_api { if (is_array($params) or is_object($params)) { throw new invalid_parameter_exception('Scalar type expected, array or object received.'); } + + if ($description->type == PARAM_BOOL) { + // special case for PARAM_BOOL - we want true/false instead of the usual 1/0 - we can not be too strict here ;-) + if (is_bool($params) or $params === 0 or $params === 1 or $params === '0' or $params === '1') { + return (bool)$params; + } + } return validate_param($params, $description->type, $description->allownull, 'Invalid external api parameter'); } else if ($description instanceof external_single_structure) { diff --git a/webservice/rest/locallib.php b/webservice/rest/locallib.php index fe850fb933..edb42da34f 100644 --- a/webservice/rest/locallib.php +++ b/webservice/rest/locallib.php @@ -127,6 +127,10 @@ class webservice_rest_server extends webservice_base_server { return ''; } else if ($desc instanceof external_value) { + if (is_bool($returns)) { + // we want 1/0 instead of true/false here + $returns = (int)$returns; + } if (is_null($returns)) { return ''."\n"; } else {