tapi/app/entity/gateway/ws/PutMessage.php

59 lines
1.4 KiB
PHP

<?php
namespace app\entity\gateway\ws;
use app\enum\gateway\WsEventEnum;
use app\enum\gateway\WsTypeEnum;
/**
* Ws消息入参
*/
class PutMessage
{
readonly public WsTypeEnum $type;
readonly public WsEventEnum $event;
readonly public array $data;
public string $wsClientId;
public int $userId = 0;
public string $userType = '';
public array $userClient = [];
public function __construct(string $ws_client_id, string $type, string $event, array $data = [])
{
$this->wsClientId = $ws_client_id;
$this->type = WsTypeEnum::tryFrom($type);
$this->event = WsEventEnum::tryFrom($event);
$this->data = $data;
}
public function get($name, $default = null)
{
return $this->data[$name] ?? $default;
}
public function login(int $user_id, string $user_type, array $user_client = []): bool
{
if (empty($user_id) || empty($user_type) || count($user_client) == 0) {
return false;
}
$this->userId = $user_id;
$this->userType = $user_type;
$this->userClient = $user_client;
return true;
}
public function getClientId(): string
{
return $this->userClient['id'] ?? '';
}
public function getClientName()
{
return $this->userClient['name'] ?? '';
}
public function getClientVersion()
{
return $this->userClient['version'] ?? '';
}
}