mirror of
https://github.com/openvk/openvk
synced 2025-07-07 08:19:49 +03:00
Add Utils.resolveScreenName
This commit is contained in:
parent
12c41dcdd6
commit
6aa860c8d6
1 changed files with 27 additions and 0 deletions
|
@ -1,10 +1,37 @@
|
|||
<?php declare(strict_types=1);
|
||||
namespace openvk\VKAPI\Handlers;
|
||||
|
||||
use openvk\Web\Models\Entities\Alias;
|
||||
use openvk\Web\Models\Repositories\Aliases;
|
||||
|
||||
final class Utils extends VKAPIRequestHandler
|
||||
{
|
||||
function getServerTime(): int
|
||||
{
|
||||
return time();
|
||||
}
|
||||
|
||||
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" => intval(substr($screen_name, strlen("id"))),
|
||||
"type" => "user"
|
||||
];
|
||||
} else if (substr($screen_name, 0, strlen("club")) === "club") {
|
||||
return (object) [
|
||||
"object_id" => intval(substr($screen_name, strlen("club"))),
|
||||
"type" => "group"
|
||||
];
|
||||
}
|
||||
} else {
|
||||
$alias = (new Aliases)->getByShortCode($screen_name);
|
||||
if (!$alias) return (object)[];
|
||||
return (object) [
|
||||
"object_id" => $alias->getOwnerId(),
|
||||
"type" => $alias->getType()
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue