mirror of
https://github.com/openvk/openvk
synced 2025-02-02 04:55:28 +03:00
Alexander Minkin
6ec54a379d
* feat(lint): add php-cs-fixer for linting Removing previous CODE_STYLE as it was not enforced anyway and using PER-CS 2.0. This is not the reformatting commit. * style: format code according to PER-CS 2.0 with php-cs-fixer * ci(actions): add lint action Resolves #1132.
62 lines
1.8 KiB
PHP
62 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace openvk\VKAPI\Handlers;
|
|
|
|
use openvk\Web\Models\Repositories\{Users, Clubs};
|
|
|
|
final class Utils extends VKAPIRequestHandler
|
|
{
|
|
public function getServerTime(): int
|
|
{
|
|
return time();
|
|
}
|
|
|
|
public 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",
|
|
];
|
|
} elseif (substr($screen_name, 0, strlen("club")) === "club") {
|
|
return (object) [
|
|
"object_id" => (int) substr($screen_name, strlen("club")),
|
|
"type" => "group",
|
|
];
|
|
} else {
|
|
$this->fail(104, "Not found");
|
|
}
|
|
} 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",
|
|
];
|
|
}
|
|
|
|
$this->fail(104, "Not found");
|
|
}
|
|
}
|
|
|
|
public function resolveGuid(string $guid): object
|
|
{
|
|
$user = (new Users())->getByChandlerUserId($guid);
|
|
if (is_null($user)) {
|
|
$this->fail(104, "Not found");
|
|
}
|
|
|
|
return $user->toVkApiStruct($this->getUser());
|
|
}
|
|
}
|