From 6958d26168eb1f48edf283dd49763589209ba526 Mon Sep 17 00:00:00 2001 From: Gonzalo Alonso Date: Mon, 11 Jun 2018 12:49:17 -0300 Subject: [PATCH 1/3] implements ClientInterface class Client implements ClientInterface --- Client/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Client/Client.php b/Client/Client.php index a15281f..d1a6e56 100644 --- a/Client/Client.php +++ b/Client/Client.php @@ -7,7 +7,7 @@ /** * @author Pierre Rolland */ -class Client +class Client implements ClientInterface { /** @var ConnectionInterface */ protected $connection; From 23bf42eb9c27ff6aae0440ae1bcec5eb4f3b992e Mon Sep 17 00:00:00 2001 From: Gonzalo Alonso Date: Mon, 11 Jun 2018 12:50:28 -0300 Subject: [PATCH 2/3] new $this->clientClass($conn); $this->clientStack->addClient(new $this->clientClass($conn)); --- Websocket.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Websocket.php b/Websocket.php index b7607aa..a98586e 100644 --- a/Websocket.php +++ b/Websocket.php @@ -30,7 +30,7 @@ public function __construct(HandlerRegistry $handlerRegistry, string $clientClas public function onOpen(ConnectionInterface $conn) { - $this->clientStack->addClient(new ${$this->clientClass}($conn)); + $this->clientStack->addClient(new $this->clientClass($conn)); } public function onMessage(ConnectionInterface $from, $msg) From 7983001044f3739e2b377373a220c7f6d8cdca73 Mon Sep 17 00:00:00 2001 From: Gonzalo Alonso Date: Mon, 11 Jun 2018 16:16:07 -0300 Subject: [PATCH 3/3] function getClients return all clients --- Client/ClientStack.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Client/ClientStack.php b/Client/ClientStack.php index 7477f1e..988544b 100644 --- a/Client/ClientStack.php +++ b/Client/ClientStack.php @@ -28,6 +28,11 @@ public function removeClient(ConnectionInterface $connection) unset($this->clients[$this->getClientIndex($connection)]); } + public function getClients(): array + { + return $this->clients; + } + private function getClientIndex(ConnectionInterface $connection): int { foreach ($this->clients as $i => $c) {