Improved datatypes
This commit is contained in:
parent
609ad26d24
commit
38a5a1336b
10
api.php
10
api.php
|
@ -15,7 +15,7 @@ class API {
|
||||||
return $input;
|
return $input;
|
||||||
},
|
},
|
||||||
"int" => function($input) {
|
"int" => function($input) {
|
||||||
if($input === null) return null;
|
if($input === null || $input === "") return null;
|
||||||
return intval($input);
|
return intval($input);
|
||||||
},
|
},
|
||||||
"float" => function($input) {
|
"float" => function($input) {
|
||||||
|
@ -23,7 +23,8 @@ class API {
|
||||||
return floatval($input);
|
return floatval($input);
|
||||||
},
|
},
|
||||||
"bool" => function($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);
|
$this->data = array_merge($_GET, $_POST);
|
||||||
|
@ -50,8 +51,7 @@ class API {
|
||||||
$datatype = trim(array_shift($split2));
|
$datatype = trim(array_shift($split2));
|
||||||
$default = count($split2) ? trim(implode("=", $split2)) : null;
|
$default = count($split2) ? trim(implode("=", $split2)) : null;
|
||||||
|
|
||||||
$result[$name] = $data[$name];
|
$result[$name] = isset($data[$name]) ? $data[$name] : null;
|
||||||
if(!isset($result[$name])) $result[$name] = null;
|
|
||||||
|
|
||||||
if($result[$name] === null && isset($default) && $default !== "") $result[$name] = $default;
|
if($result[$name] === null && isset($default) && $default !== "") $result[$name] = $default;
|
||||||
$result[$name] = $this->datatypes[$datatype]($result[$name]);
|
$result[$name] = $this->datatypes[$datatype]($result[$name]);
|
||||||
|
@ -108,4 +108,4 @@ class API {
|
||||||
die(json_encode($response));
|
die(json_encode($response));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue