From cb4934ec9932e66a3acade566e919fdf4cbd86b5 Mon Sep 17 00:00:00 2001 From: Matthew Maennche Date: Wed, 26 Jun 2024 20:54:23 -0500 Subject: [PATCH 1/4] PHP Compatability for Dynamic Properties React\Socket\Connection::$decor Ratchet\Server\IoConnection::$resourceId Ratchet\Server\IoConnection::$remoteAddress Ratchet\Server\IoConnection::$httpHeadersReceived Ratchet\Server\IoConnection::$httpBuffer Ratchet\Server\IoConnection::$httpRequest Ratchet\Server\IoConnection::$WebSocket --- src/Ratchet/Server/IoConnection.php | 12 ++++++++++-- src/Ratchet/WebSocket/Connection.php | 17 +++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 src/Ratchet/WebSocket/Connection.php diff --git a/src/Ratchet/Server/IoConnection.php b/src/Ratchet/Server/IoConnection.php index 9f864bb9..eb6ef260 100644 --- a/src/Ratchet/Server/IoConnection.php +++ b/src/Ratchet/Server/IoConnection.php @@ -1,7 +1,7 @@ decor = null; // Initialize as necessary + } + + + } \ No newline at end of file From 2de84531fb6c170422364d0f1b99dfaead240916 Mon Sep 17 00:00:00 2001 From: Matthew Maennche Date: Thu, 27 Jun 2024 08:17:31 -0500 Subject: [PATCH 2/4] PHP Compatability for Dynamic Properties React\Socket\Connection::$decor Ratchet\Server\IoConnection::$resourceId Ratchet\Server\IoConnection::$remoteAddress Ratchet\Server\IoConnection::$httpHeadersReceived Ratchet\Server\IoConnection::$httpBuffer Ratchet\Server\IoConnection::$httpRequest Ratchet\Server\IoConnection::$WebSocket --- src/Ratchet/Server/IoConnection.php | 2 +- src/Ratchet/WebSocket/Connection.php | 17 ----------------- 2 files changed, 1 insertion(+), 18 deletions(-) delete mode 100644 src/Ratchet/WebSocket/Connection.php diff --git a/src/Ratchet/Server/IoConnection.php b/src/Ratchet/Server/IoConnection.php index eb6ef260..f617ace9 100644 --- a/src/Ratchet/Server/IoConnection.php +++ b/src/Ratchet/Server/IoConnection.php @@ -1,7 +1,7 @@ decor = null; // Initialize as necessary - } - - - } \ No newline at end of file From 8cf05a78c3f051d5d10d4ccc455b90f765b8b317 Mon Sep 17 00:00:00 2001 From: Matthew Maennche Date: Thu, 27 Jun 2024 16:03:46 -0500 Subject: [PATCH 3/4] PHP Compatability for Dynamic Properties React\Socket\Connection::$decor --- src/Ratchet/Server/IoConnection.php | 8 +-- src/Ratchet/Server/IoServer.php | 82 ++++++++++++++++------------- 2 files changed, 48 insertions(+), 42 deletions(-) diff --git a/src/Ratchet/Server/IoConnection.php b/src/Ratchet/Server/IoConnection.php index f617ace9..d8f1559e 100644 --- a/src/Ratchet/Server/IoConnection.php +++ b/src/Ratchet/Server/IoConnection.php @@ -1,14 +1,14 @@ conn = $conn; } diff --git a/src/Ratchet/Server/IoServer.php b/src/Ratchet/Server/IoServer.php index b3fb7e0e..3c84d7cf 100644 --- a/src/Ratchet/Server/IoServer.php +++ b/src/Ratchet/Server/IoServer.php @@ -1,6 +1,7 @@ decor = new IoConnection($conn); - $conn->decor->resourceId = (int)$conn->stream; + $reactConn = new ReactConnection($conn->stream, $this->loop); + $reactConn->decor = new IoConnection($reactConn); + $reactConn->decor->resourceId = (int)$reactConn->stream; - $uri = $conn->getRemoteAddress(); - $conn->decor->remoteAddress = trim( + $uri = $reactConn->getRemoteAddress(); + $reactConn->decor->remoteAddress = trim( parse_url((strpos($uri, '://') === false ? 'tcp://' : '') . $uri, PHP_URL_HOST), '[]' ); - $this->app->onOpen($conn->decor); + $this->app->onOpen($reactConn->decor); - $conn->on('data', function ($data) use ($conn) { - $this->handleData($data, $conn); + $conn->on('data', function ($data) use ($reactConn) { + $this->handleData($data, $reactConn); }); - $conn->on('close', function () use ($conn) { - $this->handleEnd($conn); + $conn->on('close', function () use ($reactConn) { + $this->handleEnd($reactConn); }); - $conn->on('error', function (\Exception $e) use ($conn) { - $this->handleError($e, $conn); + $conn->on('error', function (\Exception $e) use ($reactConn) { + $this->handleError($e, $reactConn); }); } - /** - * Data has been received from React - * @param string $data - * @param \React\Socket\ConnectionInterface $conn - */ - public function handleData($data, $conn) { + /** + * Data has been received from React + * @param string $data + * @param ReactConnection $reactConn + * @throws \Exception + */ + public function handleData($data, $reactConn) { try { - $this->app->onMessage($conn->decor, $data); + $this->app->onMessage($reactConn->decor, $data); } catch (\Exception $e) { - $this->handleError($e, $conn); + $this->handleError($e, $reactConn); } } - /** - * A connection has been closed by React - * @param \React\Socket\ConnectionInterface $conn - */ - public function handleEnd($conn) { + /** + * A connection has been closed by React + * @param $reactConn + * @throws \Exception + */ + public function handleEnd($reactConn) { try { - $this->app->onClose($conn->decor); + $this->app->onClose($reactConn->decor); } catch (\Exception $e) { - $this->handleError($e, $conn); + $this->handleError($e, $reactConn); } - unset($conn->decor); + unset($reactConn->decor); } - /** - * An error has occurred, let the listening application know - * @param \Exception $e - * @param \React\Socket\ConnectionInterface $conn - */ - public function handleError(\Exception $e, $conn) { - $this->app->onError($conn->decor, $e); + /** + * An error has occurred, let the listening application know + * @param \Exception $e + * @param $reactConn + * @throws \Exception + */ + public function handleError(\Exception $e, $reactConn) { + $this->app->onError($reactConn->decor, $e); } } From a453e961a41f20d223c60ab9a7ff3a0f5a83c144 Mon Sep 17 00:00:00 2001 From: Matthew Maennche Date: Thu, 27 Jun 2024 16:11:19 -0500 Subject: [PATCH 4/4] PHP Compatability for Dynamic Properties React\Socket\Connection::$decor --- src/Ratchet/WebSocket/ReactConnection.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/Ratchet/WebSocket/ReactConnection.php diff --git a/src/Ratchet/WebSocket/ReactConnection.php b/src/Ratchet/WebSocket/ReactConnection.php new file mode 100644 index 00000000..6afc154d --- /dev/null +++ b/src/Ratchet/WebSocket/ReactConnection.php @@ -0,0 +1,14 @@ +