2018-02-28 01:27:35 +03:00
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace api\modules\oauth\models;
|
|
|
|
|
|
|
|
use api\modules\oauth\exceptions\UnsupportedOauthClientType;
|
|
|
|
use common\models\OauthClient;
|
|
|
|
|
2025-01-15 14:13:08 +01:00
|
|
|
final class OauthClientFormFactory {
|
2018-02-28 01:27:35 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws UnsupportedOauthClientType
|
|
|
|
*/
|
|
|
|
public static function create(OauthClient $client): OauthClientTypeForm {
|
2024-12-02 15:10:55 +05:00
|
|
|
return match ($client->type) {
|
2025-01-15 14:13:08 +01:00
|
|
|
OauthClient::TYPE_WEB_APPLICATION => new WebApplicationType([
|
2024-12-02 15:10:55 +05:00
|
|
|
'name' => $client->name,
|
|
|
|
'websiteUrl' => $client->website_url,
|
|
|
|
'description' => $client->description,
|
|
|
|
'redirectUri' => $client->redirect_uri,
|
|
|
|
]),
|
2025-01-15 14:13:08 +01:00
|
|
|
OauthClient::TYPE_DESKTOP_APPLICATION => new DesktopApplicationType([
|
|
|
|
'name' => $client->name,
|
|
|
|
'description' => $client->description,
|
|
|
|
'websiteUrl' => $client->website_url,
|
|
|
|
]),
|
2024-12-02 15:10:55 +05:00
|
|
|
OauthClient::TYPE_MINECRAFT_SERVER => new MinecraftServerType([
|
|
|
|
'name' => $client->name,
|
|
|
|
'websiteUrl' => $client->website_url,
|
|
|
|
'minecraftServerIp' => $client->minecraft_server_ip,
|
|
|
|
]),
|
2025-01-15 14:13:08 +01:00
|
|
|
// @phpstan-ignore match.unreachable (Not quite correct code, but the value comes from the user and might be not expected)
|
2024-12-02 15:10:55 +05:00
|
|
|
default => throw new UnsupportedOauthClientType($client->type),
|
|
|
|
};
|
2018-02-28 01:27:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|