From 155d3721867721965d9d9b176cb9c8f714335c2f Mon Sep 17 00:00:00 2001 From: Benjamin Loison Date: Tue, 31 Jan 2023 00:57:06 +0100 Subject: [PATCH] Run `php-cs-fixer fix --rules=@PSR12 websocket.php` --- website/websocket.php | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/website/websocket.php b/website/websocket.php index 3876286..9dc5a28 100644 --- a/website/websocket.php +++ b/website/websocket.php @@ -1,26 +1,31 @@ clients = new \SplObjectStorage; + public function __construct() + { + $this->clients = new \SplObjectStorage(); } - public function onOpen(ConnectionInterface $conn) { + public function onOpen(ConnectionInterface $conn) + { $this->clients->attach($conn); } - public function onMessage(ConnectionInterface $from, $msg) { + public function onMessage(ConnectionInterface $from, $msg) + { foreach ($this->clients as $client) { if ($from != $client) { $client->send($msg); @@ -28,17 +33,19 @@ class MyChat implements MessageComponentInterface { } } - public function onClose(ConnectionInterface $conn) { + public function onClose(ConnectionInterface $conn) + { $this->clients->detach($conn); } - public function onError(ConnectionInterface $conn, \Exception $e) { + public function onError(ConnectionInterface $conn, \Exception $e) + { $conn->close(); } } - // Run the server application through the WebSocket protocol on port 8080 - $app = new Ratchet\App('localhost', 8080); - $app->route('/chat', new MyChat, array('*')); - $app->route('/echo', new Ratchet\Server\EchoServer, array('*')); - $app->run(); +// Run the server application through the WebSocket protocol on port 8080 +$app = new Ratchet\App('localhost', 8080); +$app->route('/chat', new MyChat(), array('*')); +$app->route('/echo', new Ratchet\Server\EchoServer(), array('*')); +$app->run();