Fix settype to allow Null

This commit is contained in:
Ry0 2024-06-28 01:14:55 +03:00
parent ba2e00adac
commit 31f0d184e7
2 changed files with 28 additions and 5 deletions

View file

@ -485,9 +485,8 @@ final class Audio extends VKAPIRequestHandler
$this->requireUser(); $this->requireUser();
$this->willExecuteWriteAction(); $this->willExecuteWriteAction();
if(!is_null($album_id)) // Думаю ?int $album_id = NULL возвращает 0 из-за ?int if(!is_null($album_id))
if($album_id > 0) $this->fail(10, "album_id not implemented");
$this->fail(10, "album_id not implemented");
// TODO get rid of dups // TODO get rid of dups
$to = $this->getUser(); $to = $this->getUser();

View file

@ -234,8 +234,32 @@ final class VKAPIPresenter extends OpenVKPresenter
} }
try { try {
settype($val, $parameter->getType()->getName()); // Проверка типа параметра
$params[] = $val; $type = $parameter->getType();
if ($type && !$type->isBuiltin()) {
$params[] = $val; // Пользовательские типы оставляем как есть
} else if (is_null($val)) {
$params[] = $val; // Если значение NULL, то оставляем его NULL
} else {
switch ($type->getName()) {
case 'int':
$val = (int)$val;
break;
case 'float':
$val = (float)$val;
break;
case 'bool':
$val = (bool)$val;
break;
case 'string':
$val = (string)$val;
break;
// Добавить другие типы при необходимости
default:
settype($val, $type->getName());
}
$params[] = $val;
}
} catch (\Throwable $e) { } catch (\Throwable $e) {
// Just ignore the exception, since // Just ignore the exception, since
// some args are intended for internal use // some args are intended for internal use