Skip to content

Commit

Permalink
Merge pull request #759 from mouyong/master
Browse files Browse the repository at this point in the history
添加对 Connection 的序列化操作
  • Loading branch information
walkor authored May 9, 2022
2 parents 9d6c228 + c14f192 commit b06f1fc
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
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(),
];
}
}

0 comments on commit b06f1fc

Please sign in to comment.