From d97ca0f3cbfbbff54092cc25288ca6f8d2c28fac Mon Sep 17 00:00:00 2001 From: Chris Boden Date: Thu, 25 Feb 2016 19:18:46 -0500 Subject: [PATCH] Switched index array storage to class container --- src/Ratchet/WebSocket/ConnContext.php | 20 ++++++++++++++++++++ src/Ratchet/WebSocket/WsServer.php | 10 +++++----- 2 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 src/Ratchet/WebSocket/ConnContext.php diff --git a/src/Ratchet/WebSocket/ConnContext.php b/src/Ratchet/WebSocket/ConnContext.php new file mode 100644 index 0000000..7aa6322 --- /dev/null +++ b/src/Ratchet/WebSocket/ConnContext.php @@ -0,0 +1,20 @@ +connection = $conn; + $this->streamer = $streamer; + } +} diff --git a/src/Ratchet/WebSocket/WsServer.php b/src/Ratchet/WebSocket/WsServer.php index 61d42b6..83fbce2 100644 --- a/src/Ratchet/WebSocket/WsServer.php +++ b/src/Ratchet/WebSocket/WsServer.php @@ -115,7 +115,7 @@ class WsServer implements HttpServerInterface { $this->ueFlowFactory ); - $this->connections->attach($conn, [$wsConn, $streamer]); + $this->connections->attach($conn, new ConnContext($wsConn, $streamer)); return $this->delegate->onOpen($wsConn); } @@ -129,7 +129,7 @@ class WsServer implements HttpServerInterface { } $context = $this->connections[$from]; - $context[1]->onData($msg); + $context->streamer->onData($msg); } /** @@ -140,7 +140,7 @@ class WsServer implements HttpServerInterface { $context = $this->connections[$conn]; $this->connections->detach($conn); - $this->delegate->onClose($context[0]); + $this->delegate->onClose($context->conn); } } @@ -150,7 +150,7 @@ class WsServer implements HttpServerInterface { public function onError(ConnectionInterface $conn, \Exception $e) { if ($this->connections->contains($conn)) { $context = $this->connections[$conn]; - $this->delegate->onError($context[0], $e); + $this->delegate->onError($context->connection, $e); } else { $conn->close(); } @@ -196,7 +196,7 @@ class WsServer implements HttpServerInterface { foreach ($this->connections as $key => $conn) { $context = $this->connections[$conn]; - $wsConn = $context[0]; + $wsConn = $context->connection; $wsConn->send($lastPing); $pingedConnections->attach($wsConn);