]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-12886 inproved hadnling of bool ws params and return values
authorPetr Skoda <skodak@moodle.org>
Mon, 26 Oct 2009 22:39:08 +0000 (22:39 +0000)
committerPetr Skoda <skodak@moodle.org>
Mon, 26 Oct 2009 22:39:08 +0000 (22:39 +0000)
lib/externallib.php
webservice/rest/locallib.php

index 6bcfc6a340f96dc13e9128144e2dac7a978c88e4..6e2b0458bd1cdd8bea0d27036be214696c54ea66 100644 (file)
@@ -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) {
index fe850fb933087f63e3cf2753e23f412bcbaf8ea5..edb42da34f57764a785b3d1bec786629980acdd7 100644 (file)
@@ -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 '<VALUE null="null"/>'."\n";
             } else {