2020-11-01 01:36:35 +03:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
namespace openvk\VKAPI\Handlers;
|
2023-06-10 18:56:07 +03:00
|
|
|
use openvk\Web\Models\Repositories\{Users, Clubs};
|
2020-11-01 01:36:35 +03:00
|
|
|
|
|
|
|
final class Utils extends VKAPIRequestHandler
|
|
|
|
{
|
|
|
|
function getServerTime(): int
|
|
|
|
{
|
|
|
|
return time();
|
|
|
|
}
|
2023-06-10 18:56:07 +03:00
|
|
|
|
|
|
|
function resolveScreenName(string $screen_name): object
|
|
|
|
{
|
|
|
|
if(\Chandler\MVC\Routing\Router::i()->getMatchingRoute("/$screen_name")[0]->presenter !== "UnknownTextRouteStrategy") {
|
|
|
|
if(substr($screen_name, 0, strlen("id")) === "id") {
|
|
|
|
return (object) [
|
|
|
|
"object_id" => (int) substr($screen_name, strlen("id")),
|
|
|
|
"type" => "user"
|
|
|
|
];
|
|
|
|
} else if(substr($screen_name, 0, strlen("club")) === "club") {
|
|
|
|
return (object) [
|
|
|
|
"object_id" => (int) substr($screen_name, strlen("club")),
|
|
|
|
"type" => "group"
|
|
|
|
];
|
2024-03-27 23:38:35 +03:00
|
|
|
} else $this->fail(104, "Not found");
|
2023-06-10 18:56:07 +03:00
|
|
|
} else {
|
|
|
|
$user = (new Users)->getByShortURL($screen_name);
|
|
|
|
if($user) {
|
|
|
|
return (object) [
|
|
|
|
"object_id" => $user->getId(),
|
|
|
|
"type" => "user"
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
$club = (new Clubs)->getByShortURL($screen_name);
|
|
|
|
if($club) {
|
|
|
|
return (object) [
|
|
|
|
"object_id" => $club->getId(),
|
|
|
|
"type" => "group"
|
|
|
|
];
|
|
|
|
}
|
2024-03-27 23:38:35 +03:00
|
|
|
|
|
|
|
$this->fail(104, "Not found");
|
2023-06-10 18:56:07 +03:00
|
|
|
}
|
|
|
|
}
|
2024-03-27 23:38:35 +03:00
|
|
|
|
|
|
|
function resolveGuid(string $guid): object
|
|
|
|
{
|
|
|
|
$user = (new Users)->getByChandlerUserId($guid);
|
|
|
|
if (is_null($user))
|
|
|
|
$this->fail(104, "Not found");
|
|
|
|
|
|
|
|
return $user->toVkApiStruct($this->getUser());
|
|
|
|
}
|
2020-11-01 01:36:35 +03:00
|
|
|
}
|