From d97ca0f3cbfbbff54092cc25288ca6f8d2c28fac Mon Sep 17 00:00:00 2001 From: Chris Boden Date: Thu, 25 Feb 2016 19:18:46 -0500 Subject: [PATCH 1/3] 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); From 5137c2122a96f24b31a473570cdb4b5b3f36d5e5 Mon Sep 17 00:00:00 2001 From: Chris Boden Date: Thu, 25 Feb 2016 19:19:58 -0500 Subject: [PATCH 2/3] Use httpRequest in favour of WebSocket->request --- src/Ratchet/WebSocket/WsServer.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Ratchet/WebSocket/WsServer.php b/src/Ratchet/WebSocket/WsServer.php index 83fbce2..57f1ebe 100644 --- a/src/Ratchet/WebSocket/WsServer.php +++ b/src/Ratchet/WebSocket/WsServer.php @@ -87,11 +87,10 @@ class WsServer implements HttpServerInterface { throw new \UnexpectedValueException('$request can not be null'); } - $conn->httpRequest = $request; // This will replace ->WebSocket->request + $conn->httpRequest = $request; $conn->WebSocket = new \StdClass; $conn->WebSocket->closing = false; - $conn->WebSocket->request = $request; // deprecated $response = $this->handshakeNegotiator->handshake($request)->withHeader('X-Powered-By', \Ratchet\VERSION); From 01e1d159e830b2bc7f4f243c845bdddb13d23755 Mon Sep 17 00:00:00 2001 From: Chris Boden Date: Thu, 25 Feb 2016 19:26:42 -0500 Subject: [PATCH 3/3] Naming conventions --- src/Ratchet/WebSocket/ConnContext.php | 6 +++--- src/Ratchet/WebSocket/WsServer.php | 11 ++++------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/Ratchet/WebSocket/ConnContext.php b/src/Ratchet/WebSocket/ConnContext.php index 7aa6322..2eba782 100644 --- a/src/Ratchet/WebSocket/ConnContext.php +++ b/src/Ratchet/WebSocket/ConnContext.php @@ -11,10 +11,10 @@ class ConnContext { /** * @var \Ratchet\RFC6455\Messaging\MessageBuffer; */ - public $streamer; + public $buffer; - public function __construct(WsConnection $conn, MessageBuffer $streamer) { + public function __construct(WsConnection $conn, MessageBuffer $buffer) { $this->connection = $conn; - $this->streamer = $streamer; + $this->buffer = $buffer; } } diff --git a/src/Ratchet/WebSocket/WsServer.php b/src/Ratchet/WebSocket/WsServer.php index 57f1ebe..0238e23 100644 --- a/src/Ratchet/WebSocket/WsServer.php +++ b/src/Ratchet/WebSocket/WsServer.php @@ -127,8 +127,7 @@ class WsServer implements HttpServerInterface { return; } - $context = $this->connections[$from]; - $context->streamer->onData($msg); + $this->connections[$from]->buffer->onData($msg); } /** @@ -139,7 +138,7 @@ class WsServer implements HttpServerInterface { $context = $this->connections[$conn]; $this->connections->detach($conn); - $this->delegate->onClose($context->conn); + $this->delegate->onClose($context->connection); } } @@ -148,8 +147,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->connection, $e); + $this->delegate->onError($this->connections[$from]->connection, $e); } else { $conn->close(); } @@ -194,8 +192,7 @@ class WsServer implements HttpServerInterface { $lastPing = new Frame(uniqid(), true, Frame::OP_PING); foreach ($this->connections as $key => $conn) { - $context = $this->connections[$conn]; - $wsConn = $context->connection; + $wsConn = $this->connections[$from]->connection; $wsConn->send($lastPing); $pingedConnections->attach($wsConn);