Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加对 Connection 的序列化操作 #759

Merged
merged 17 commits into from
May 9, 2022
24 changes: 23 additions & 1 deletion src/Connection/TcpConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/**
* TcpConnection.
*/
class TcpConnection extends ConnectionInterface
class TcpConnection extends ConnectionInterface implements \JsonSerializable
{
/**
* Read buffer size.
Expand Down Expand Up @@ -969,6 +969,28 @@ public static function enableCache($value)
{
static::$_enableCache = (bool)$value;
}

/**
* Get the json_encode informattion.
*
* @return string
*/
public function jsonSerialize()
{
return [
'id' => $this->id,
'status' => $this->getStatus(),
'transport' => $this->transport,
'getRemoteIp' => $this->getRemoteIp(),
'remotePort' => $this->getRemotePort(),
'getRemoteAddress' => $this->getRemoteAddress(),
'getLocalIp' => $this->getLocalIp(),
'getLocalPort' => $this->getLocalPort(),
'getLocalAddress' => $this->getLocalAddress(),
'isIpV4' => $this->isIpV4(),
'isIpV6' => $this->isIpV6(),
];
}

/**
* Destruct.
Expand Down
22 changes: 21 additions & 1 deletion src/Connection/UdpConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/**
* UdpConnection.
*/
class UdpConnection extends ConnectionInterface
class UdpConnection extends ConnectionInterface implements \JsonSerializable
{
/**
* Application layer protocol.
Expand Down Expand Up @@ -206,4 +206,24 @@ public function getSocket()
{
return $this->_socket;
}

/**
* Get the json_encode informattion.
*
* @return string
*/
public function jsonSerialize()
{
return [
'transport' => $this->transport,
'getRemoteIp' => $this->getRemoteIp(),
'remotePort' => $this->getRemotePort(),
'getRemoteAddress' => $this->getRemoteAddress(),
'getLocalIp' => $this->getLocalIp(),
'getLocalPort' => $this->getLocalPort(),
'getLocalAddress' => $this->getLocalAddress(),
'isIpV4' => $this->isIpV4(),
'isIpV6' => $this->isIpV6(),
];
}
}