From 31f0d184e71d42ea7d02cf19d4c7efa81990872c Mon Sep 17 00:00:00 2001 From: Ry0 <43928323+xRy0@users.noreply.github.com> Date: Fri, 28 Jun 2024 01:14:55 +0300 Subject: [PATCH] Fix settype to allow Null --- VKAPI/Handlers/Audio.php | 5 ++--- Web/Presenters/VKAPIPresenter.php | 28 ++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/VKAPI/Handlers/Audio.php b/VKAPI/Handlers/Audio.php index 43c6acdf..004daef4 100644 --- a/VKAPI/Handlers/Audio.php +++ b/VKAPI/Handlers/Audio.php @@ -485,9 +485,8 @@ final class Audio extends VKAPIRequestHandler $this->requireUser(); $this->willExecuteWriteAction(); - if(!is_null($album_id)) // Думаю ?int $album_id = NULL возвращает 0 из-за ?int - if($album_id > 0) - $this->fail(10, "album_id not implemented"); + if(!is_null($album_id)) + $this->fail(10, "album_id not implemented"); // TODO get rid of dups $to = $this->getUser(); diff --git a/Web/Presenters/VKAPIPresenter.php b/Web/Presenters/VKAPIPresenter.php index e906ce50..4b57fe68 100644 --- a/Web/Presenters/VKAPIPresenter.php +++ b/Web/Presenters/VKAPIPresenter.php @@ -234,8 +234,32 @@ final class VKAPIPresenter extends OpenVKPresenter } 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) { // Just ignore the exception, since // some args are intended for internal use