Added "set:" preffix to check the parameter was set

This commit is contained in:
Bofh 2022-12-24 18:41:40 +01:00
parent f306f8dd4d
commit 177b6a6804
1 changed files with 6 additions and 0 deletions

View File

@ -100,6 +100,9 @@ function arg($arg, $default=null, $validator=null) {
} else if (strpos($arg,'b64:') === 0) {
$type = 'base64';
$arg = substr($arg, 4);
} else if (strpos($arg,'set:') === 0) {
$type = 'exists';
$arg = substr($arg, 4);
}
$ps = explode('.', $arg);
@ -116,6 +119,9 @@ function arg($arg, $default=null, $validator=null) {
if ($arr === null)
$arr = $ps[0];
eval('$value = isset($'.$arr.'["'.$ps[1].'"]) ? $'.$arr.'["'.$ps[1].'"] : null;');
if ($type === 'exists')
return $value !== null;
if ($value === null)
return !$require ? $default : apiresult(['error' => '<'.$arg.'> parameter must be specified'], 400);