diff --git a/src/Connection/TcpConnection.php b/src/Connection/TcpConnection.php index b190bfec3..9b3c845ce 100644 --- a/src/Connection/TcpConnection.php +++ b/src/Connection/TcpConnection.php @@ -21,7 +21,7 @@ /** * TcpConnection. */ -class TcpConnection extends ConnectionInterface +class TcpConnection extends ConnectionInterface implements \JsonSerializable { /** * Read buffer size. @@ -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. diff --git a/src/Connection/UdpConnection.php b/src/Connection/UdpConnection.php index 7be400f40..813b48cd6 100644 --- a/src/Connection/UdpConnection.php +++ b/src/Connection/UdpConnection.php @@ -17,7 +17,7 @@ /** * UdpConnection. */ -class UdpConnection extends ConnectionInterface +class UdpConnection extends ConnectionInterface implements \JsonSerializable { /** * Application layer protocol. @@ -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(), + ]; + } }