diff --git a/lib/Ratchet/Command/Action/CloseConnection.php b/lib/Ratchet/Command/Action/CloseConnection.php index a9ca45b..6061231 100644 --- a/lib/Ratchet/Command/Action/CloseConnection.php +++ b/lib/Ratchet/Command/Action/CloseConnection.php @@ -1,12 +1,14 @@ _socket = $socket; } - function execute() { + function execute(SocketObserver $scope = null) { + $ret = $scope->onClose($this->_socket); $this->_socket->close(); + + return $ret; } } \ No newline at end of file diff --git a/lib/Ratchet/Command/Action/Null.php b/lib/Ratchet/Command/Action/Null.php index 0f87558..cd8f8e0 100644 --- a/lib/Ratchet/Command/Action/Null.php +++ b/lib/Ratchet/Command/Action/Null.php @@ -1,15 +1,16 @@ _command = $callback; } - public function execute() { + public function execute(SocketObserver $scope = null) { return call_user_func($this->_command, $socket); } } \ No newline at end of file diff --git a/lib/Ratchet/Command/Action/SendMessage.php b/lib/Ratchet/Command/Action/SendMessage.php index 16029c4..9678aac 100644 --- a/lib/Ratchet/Command/Action/SendMessage.php +++ b/lib/Ratchet/Command/Action/SendMessage.php @@ -1,12 +1,13 @@ _message)) { throw new \UnexpectedValueException("Message is empty"); } diff --git a/lib/Ratchet/Command/ActionInterface.php b/lib/Ratchet/Command/ActionInterface.php new file mode 100644 index 0000000..9e5153e --- /dev/null +++ b/lib/Ratchet/Command/ActionInterface.php @@ -0,0 +1,11 @@ +enqueue($cmd); + } + + return; + } + + parent::enqueue($command); } - public function execute() { + public function execute(SocketObserver $scope = null) { $this->setIteratorMode(static::IT_MODE_DELETE); + $recursive = new self; + foreach ($this as $command) { - $command->execute(); + $ret = $command->execute($scope); + + if ($ret instanceof CommandInterface) { + $recursive->enqueue($ret); + } + } + + if (count($recursive) > 0) { + return $recursive; } } } \ No newline at end of file diff --git a/lib/Ratchet/Protocol/WebSocket.php b/lib/Ratchet/Protocol/WebSocket.php index e5d05a3..3445e8a 100644 --- a/lib/Ratchet/Protocol/WebSocket.php +++ b/lib/Ratchet/Protocol/WebSocket.php @@ -98,7 +98,7 @@ class WebSocket implements ProtocolInterface { } } catch (\UnexpectedValueException $e) { $cmd = new Composite; - $close = new \Ratchet\Command\Close($from); + $close = new \Ratchet\Command\Action\CloseConnection($from); // This is to change to Disconnect (proper protocol close) $cmd->enqueue($close); return $cmd; diff --git a/lib/Ratchet/Protocol/WebSocket/Command/Action/Disconnect.php b/lib/Ratchet/Protocol/WebSocket/Command/Action/Disconnect.php new file mode 100644 index 0000000..85d6ef8 --- /dev/null +++ b/lib/Ratchet/Protocol/WebSocket/Command/Action/Disconnect.php @@ -0,0 +1,20 @@ +_code = (int)$code; + + // re-do message based on code + } + + public function execute(SocketObserver $scope = null) { + parent::execute(); + $this->_socket->close(); + } +} \ No newline at end of file diff --git a/lib/Ratchet/Protocol/WebSocket/Command/Action/Ping.php b/lib/Ratchet/Protocol/WebSocket/Command/Action/Ping.php index 419d7d4..3f9ac1c 100644 --- a/lib/Ratchet/Protocol/WebSocket/Command/Action/Ping.php +++ b/lib/Ratchet/Protocol/WebSocket/Command/Action/Ping.php @@ -1,12 +1,13 @@ execute(); + while ($res instanceof CommandInterface) { + $res = $res->execute($this); } } } catch (Exception $se) {