From c8f15f57ab9ea66bd65ecad81021cd4cc152bf49 Mon Sep 17 00:00:00 2001 From: "Bruno O. Notario" Date: Sun, 17 Apr 2022 01:16:25 -0300 Subject: [PATCH] New __testType function for allow mixed params Uses PHPDoc mixed in params to allow any values in your rest method. --- system/engine/restful.php | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/system/engine/restful.php b/system/engine/restful.php index b135f62..673b804 100644 --- a/system/engine/restful.php +++ b/system/engine/restful.php @@ -115,13 +115,13 @@ class RESTful extends Controller { if(is_array($type)){ foreach ($type as $avalType) { - if(call_user_func("is_" . $avalType, $data)) { + if(self::__testType( $avalType, $data)) { $invalidDataType = false; break; } } } else { - if(call_user_func("is_" . $type, $data)) { + if(self::__testType($type, $data)) { $invalidDataType = false; } } @@ -161,6 +161,35 @@ class RESTful extends Controller { } } + static function __testType($type, $data){ + + switch ($type) { + case 'mixed': + return true; + break; + + case 'int': + case 'string': + case 'array': + case 'integer': + case 'bool': + case 'double': + case 'float': + case 'long': + case 'null': + case 'numeric': + case 'scalar': + case 'real': + return call_user_func("is_" . $type, $data); + break; + + default: + return false; + break; + } + + } + /** * Not found default method *