Skip to content

Commit

Permalink
优化注释,尽可能使用 inheritDoc 注释
Browse files Browse the repository at this point in the history
  • Loading branch information
Yurunsoft committed Oct 13, 2021
1 parent eaf72cd commit b0e9b21
Show file tree
Hide file tree
Showing 24 changed files with 84 additions and 148 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
class ConnectionContextGateway implements IHandler
{
/**
* 读取数据.
* {@inheritDoc}
*/
public function read(string $key): array
{
Expand All @@ -30,7 +30,7 @@ public function read(string $key): array
}

/**
* 保存数据.
* {@inheritDoc}
*/
public function save(string $key, array $data): void
{
Expand All @@ -42,7 +42,7 @@ public function save(string $key, array $data): void
}

/**
* 销毁数据.
* {@inheritDoc}
*/
public function destroy(string $key): void
{
Expand All @@ -54,7 +54,7 @@ public function destroy(string $key): void
}

/**
* 延迟销毁数据.
* {@inheritDoc}
*/
public function delayDestroy(string $key, int $ttl): void
{
Expand All @@ -68,7 +68,7 @@ public function delayDestroy(string $key, int $ttl): void
}

/**
* 数据是否存在.
* {@inheritDoc}
*/
public function exists(string $key): bool
{
Expand All @@ -81,7 +81,7 @@ public function exists(string $key): bool
}

/**
* 加锁
* {@inheritDoc}
*/
public function lock(string $key, ?callable $callable = null): bool
{
Expand All @@ -98,27 +98,23 @@ public function lock(string $key, ?callable $callable = null): bool
}

/**
* 解锁
* {@inheritDoc}
*/
public function unlock(): bool
{
return true;
}

/**
* 绑定一个标记到当前连接.
*
* @param int|string $clientId
* {@inheritDoc}
*/
public function bind(string $flag, $clientId): void
{
Gateway::bindUid($clientId, $flag);
}

/**
* 绑定一个标记到当前连接,如果已绑定返回false.
*
* @param int|string $clientId
* {@inheritDoc}
*/
public function bindNx(string $flag, $clientId): bool
{
Expand All @@ -128,28 +124,23 @@ public function bindNx(string $flag, $clientId): bool
}

/**
* 取消绑定.
*
* @param int|string $clientId
* @param int|null $keepTime 旧数据保持时间,null 则不保留
* {@inheritDoc}
*/
public function unbind(string $flag, $clientId, ?int $keepTime = null): void
{
Gateway::unbindUid($clientId, $flag);
}

/**
* 使用标记获取连接编号.
* {@inheritDoc}
*/
public function getClientIdByFlag(string $flag): array
{
return Gateway::getClientIdByUid($flag);
}

/**
* 使用标记获取连接编号.
*
* @param string[] $flags
* {@inheritDoc}
*/
public function getClientIdsByFlags(array $flags): array
{
Expand All @@ -163,21 +154,15 @@ public function getClientIdsByFlags(array $flags): array
}

/**
* 使用连接编号获取标记.
*
* @param int|string $clientId
* {@inheritDoc}
*/
public function getFlagByClientId($clientId): ?string
{
return Gateway::getUidByClientId($clientId);
}

/**
* 使用连接编号获取标记.
*
* @param int[]|string[] $clientIds
*
* @return string[]
* {@inheritDoc}
*/
public function getFlagsByClientIds(array $clientIds): array
{
Expand All @@ -191,7 +176,7 @@ public function getFlagsByClientIds(array $clientIds): array
}

/**
* 使用标记获取旧的连接编号.
* {@inheritDoc}
*/
public function getOldClientIdByFlag(string $flag): ?int
{
Expand Down
28 changes: 10 additions & 18 deletions src/Server/Group/GatewayGroupHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,37 @@
class GatewayGroupHandler implements IGroupHandler
{
/**
* 启动时执行.
* {@inheritDoc}
*/
public function startup(): void
{
}

/**
* 组是否存在.
* {@inheritDoc}
*/
public function hasGroup(string $groupName): bool
{
return Gateway::getClientCountByGroup($groupName) > 0;
}

/**
* 创建组,返回组对象
* {@inheritDoc}
*/
public function createGroup(string $groupName, int $maxClients = -1): void
{
}

/**
* 关闭组.
* {@inheritDoc}
*/
public function closeGroup(string $groupName): void
{
Gateway::ungroup($groupName);
}

/**
* 加入组,组不存在则自动创建.
*
* @param int|string $clientId
* {@inheritDoc}
*/
public function joinGroup(string $groupName, $clientId): bool
{
Expand All @@ -58,9 +56,7 @@ public function joinGroup(string $groupName, $clientId): bool
}

/**
* 离开组,组不存在则自动创建.
*
* @param int|string $clientId
* {@inheritDoc}
*/
public function leaveGroup(string $groupName, $clientId): bool
{
Expand All @@ -70,35 +66,31 @@ public function leaveGroup(string $groupName, $clientId): bool
}

/**
* 连接是否存在于组里.
*
* @param int|string $clientId
* {@inheritDoc}
*/
public function isInGroup(string $groupName, $clientId): bool
{
return isset(Gateway::getClientIdListByGroup($groupName)[$clientId]);
}

/**
* 获取所有连接ID.
*
* @return int[]|string[]
* {@inheritDoc}
*/
public function getClientIds(string $groupName): array
{
return Gateway::getClientIdListByGroup($groupName);
}

/**
* 获取组中的连接总数.
* {@inheritDoc}
*/
public function count(string $groupName): int
{
return Gateway::getClientCountByGroup($groupName);
}

/**
* 清空分组.
* {@inheritDoc}
*/
public function clear(): void
{
Expand Down
16 changes: 8 additions & 8 deletions src/Swoole/Http/Message/WorkermanGatewaySwooleRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ public function __construct(ISwooleServer $server, string $clientId, array $data
}

/**
* 初始化协议版本.
* {@inheritDoc}
*/
protected function initProtocolVersion(): void
{
[, $this->protocolVersion] = explode('/', $this->data['server']['SERVER_PROTOCOL']);
}

/**
* 初始化 headers.
* {@inheritDoc}
*/
protected function initHeaders(): void
{
Expand All @@ -56,15 +56,15 @@ protected function initHeaders(): void
}

/**
* 初始化 body.
* {@inheritDoc}
*/
protected function initBody(): void
{
$this->body = new MemoryStream('');
}

/**
* 初始化 uri.
* {@inheritDoc}
*/
protected function initUri(): void
{
Expand All @@ -73,23 +73,23 @@ protected function initUri(): void
}

/**
* 初始化 method.
* {@inheritDoc}
*/
protected function initMethod(): void
{
$this->method = $this->data['server']['REQUEST_METHOD'];
}

/**
* 初始化 server.
* {@inheritDoc}
*/
protected function initServer(): void
{
$this->server = $this->data['server'];
}

/**
* 初始化请求参数.
* {@inheritDoc}
*/
protected function initRequestParams(): void
{
Expand Down Expand Up @@ -119,7 +119,7 @@ public function getData(): array
}

/**
* 获取客户端地址
* {@inheritDoc}
*/
public function getClientAddress(): IPEndPoint
{
Expand Down
4 changes: 1 addition & 3 deletions src/Swoole/Server/Business/Task/WorkerTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
class WorkerTask implements ICoTask
{
/**
* 执行任务
*
* @return mixed
* {@inheritDoc}
*/
public function run(ITaskParam $param)
{
Expand Down
12 changes: 4 additions & 8 deletions src/Swoole/Server/Business/TcpBusinessServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class TcpBusinessServer extends \Imi\Swoole\Server\TcpServer\Server
protected CoPool $pool;

/**
* 获取服务器初始化需要的配置.
* {@inheritDoc}
*/
protected function getServerInitConfig(): array
{
Expand All @@ -47,7 +47,7 @@ protected function getServerInitConfig(): array
}

/**
* 构造方法.
* {@inheritDoc}
*/
public function __construct(string $name, array $config)
{
Expand Down Expand Up @@ -97,19 +97,15 @@ protected function initGatewayWorker(): void
}

/**
* 向客户端发送消息.
*
* @param int|string $clientId
* {@inheritDoc}
*/
public function send($clientId, string $data): bool
{
return Server::sendRaw($data, $clientId, $this->getName()) > 0;
}

/**
* 获取客户端地址
*
* @param string|int $clientId
* {@inheritDoc}
*/
public function getClientAddress($clientId): IPEndPoint
{
Expand Down
Loading

0 comments on commit b0e9b21

Please sign in to comment.