name = $name ?: uniqid("group"); } public function add(WebSocketInterface $connection): void { if (in_array($connection, $this->connections)) return; $this->connections[] = $connection; $this->emit(self::EVENT_JOIN, [ $this->name, $connection ]); } public function remove(WebSocketInterface $connection): void { if (!in_array($connection, $this->connections)) return; $this->connections = array_filter($this->connections, fn($other) => $other != $connection); $this->emit(self::EVENT_LEAVE, [ $this->name, $connection ]); } public function count(): int { return count($this->connections); } public function getIterator(): Traversable { return new ArrayIterator($this->connections); } public function getAll(): array { return $this->connections; } public function getName(): string { return $this->name; } public function write(string $payload) { } }