Switched index array storage to class container

This commit is contained in:
Chris Boden 2016-02-25 19:18:46 -05:00
parent bfbeea6458
commit d97ca0f3cb
2 changed files with 25 additions and 5 deletions

View File

@ -0,0 +1,20 @@
<?php
namespace Ratchet\WebSocket;
use Ratchet\RFC6455\Messaging\MessageBuffer;
class ConnContext {
/**
* @var \Ratchet\WebSocket\WsConnection
*/
public $connection;
/**
* @var \Ratchet\RFC6455\Messaging\MessageBuffer;
*/
public $streamer;
public function __construct(WsConnection $conn, MessageBuffer $streamer) {
$this->connection = $conn;
$this->streamer = $streamer;
}
}

View File

@ -115,7 +115,7 @@ class WsServer implements HttpServerInterface {
$this->ueFlowFactory $this->ueFlowFactory
); );
$this->connections->attach($conn, [$wsConn, $streamer]); $this->connections->attach($conn, new ConnContext($wsConn, $streamer));
return $this->delegate->onOpen($wsConn); return $this->delegate->onOpen($wsConn);
} }
@ -129,7 +129,7 @@ class WsServer implements HttpServerInterface {
} }
$context = $this->connections[$from]; $context = $this->connections[$from];
$context[1]->onData($msg); $context->streamer->onData($msg);
} }
/** /**
@ -140,7 +140,7 @@ class WsServer implements HttpServerInterface {
$context = $this->connections[$conn]; $context = $this->connections[$conn];
$this->connections->detach($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) { public function onError(ConnectionInterface $conn, \Exception $e) {
if ($this->connections->contains($conn)) { if ($this->connections->contains($conn)) {
$context = $this->connections[$conn]; $context = $this->connections[$conn];
$this->delegate->onError($context[0], $e); $this->delegate->onError($context->connection, $e);
} else { } else {
$conn->close(); $conn->close();
} }
@ -196,7 +196,7 @@ class WsServer implements HttpServerInterface {
foreach ($this->connections as $key => $conn) { foreach ($this->connections as $key => $conn) {
$context = $this->connections[$conn]; $context = $this->connections[$conn];
$wsConn = $context[0]; $wsConn = $context->connection;
$wsConn->send($lastPing); $wsConn->send($lastPing);
$pingedConnections->attach($wsConn); $pingedConnections->attach($wsConn);