mirror of
https://github.com/openvk/openvk
synced 2024-12-23 00:51:03 +03:00
VKAPI: Re-add Utils.resolveScreenName (#886)
This commit is contained in:
parent
f9f6270da0
commit
04bca818b8
1 changed files with 36 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
|||
<?php declare(strict_types=1);
|
||||
namespace openvk\VKAPI\Handlers;
|
||||
use openvk\Web\Models\Repositories\{Users, Clubs};
|
||||
|
||||
final class Utils extends VKAPIRequestHandler
|
||||
{
|
||||
|
@ -7,4 +8,39 @@ final class Utils extends VKAPIRequestHandler
|
|||
{
|
||||
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" => (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"
|
||||
];
|
||||
}
|
||||
} 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"
|
||||
];
|
||||
}
|
||||
|
||||
return (object) [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue