From 38a5a1336bba99eda1774e35ae92935404ae82cc Mon Sep 17 00:00:00 2001 From: Filip Znachor Date: Sat, 23 Sep 2023 13:02:00 +0200 Subject: [PATCH] Improved datatypes --- api.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/api.php b/api.php index 31b06da..c570f64 100644 --- a/api.php +++ b/api.php @@ -15,7 +15,7 @@ class API { return $input; }, "int" => function($input) { - if($input === null) return null; + if($input === null || $input === "") return null; return intval($input); }, "float" => function($input) { @@ -23,7 +23,8 @@ class API { return floatval($input); }, "bool" => function($input) { - return !in_array($input, ["0", "false", null]); + if($input == null) return null; + return !in_array($input, ["0", "false"]); } ]; $this->data = array_merge($_GET, $_POST); @@ -50,8 +51,7 @@ class API { $datatype = trim(array_shift($split2)); $default = count($split2) ? trim(implode("=", $split2)) : null; - $result[$name] = $data[$name]; - if(!isset($result[$name])) $result[$name] = null; + $result[$name] = isset($data[$name]) ? $data[$name] : null; if($result[$name] === null && isset($default) && $default !== "") $result[$name] = $default; $result[$name] = $this->datatypes[$datatype]($result[$name]); @@ -108,4 +108,4 @@ class API { die(json_encode($response)); } -} \ No newline at end of file +}