diff --git a/lib/Ratchet/Command/Action/CloseConnection.php b/lib/Ratchet/Command/Action/CloseConnection.php index cd7b374..a9ca45b 100644 --- a/lib/Ratchet/Command/Action/CloseConnection.php +++ b/lib/Ratchet/Command/Action/CloseConnection.php @@ -12,8 +12,8 @@ class CloseConnection implements CommandInterface { */ protected $_socket; - public function __construct(SocketInterface $sockets) { - $this->_socket = $sockets; + public function __construct(SocketInterface $socket) { + $this->_socket = $socket; } function execute() { diff --git a/lib/Ratchet/Command/Composite.php b/lib/Ratchet/Command/Composite.php index 28b3a58..56f5ca1 100644 --- a/lib/Ratchet/Command/Composite.php +++ b/lib/Ratchet/Command/Composite.php @@ -3,28 +3,6 @@ namespace Ratchet\Command; use Ratchet\SocketInterface; class Composite extends \SplQueue { - /** - * @param string - * @param Ratchet\SocketInterface - * @return CommandInterface - */ - public function NOPEcreate($name, SocketInterface $socket) { - $class = __NAMESPACE__ . "\\{$name}\\"; - if (!class_exists($class)) { - throw new \UnexpectedValueException("Command {$name} not found"); - } - - $cmd = new $class($socket); - - if ($cmd instanceof CommandInterface) { - throw new RuntimeException("{$name} is not a valid command"); - } - - $this->enqueue($cmd); - - return $cmd; - } - public function enqueue(CommandInterface $command) { return parent::enqueue($command); } diff --git a/lib/Ratchet/Protocol/WebSocket.php b/lib/Ratchet/Protocol/WebSocket.php index 4af38ab..b3b5ae9 100644 --- a/lib/Ratchet/Protocol/WebSocket.php +++ b/lib/Ratchet/Protocol/WebSocket.php @@ -15,7 +15,6 @@ use Ratchet\Protocol\WebSocket\Util\HTTP; * This is a mediator between the Server and your application to handle real-time messaging through a web browser * @link http://ca.php.net/manual/en/ref.http.php * @todo Make sure this works both ways (client/server) as stack needs to exist on client for framing - * @todo Clean up Client/Version stuff. This should be a factory making single instances of Version classes, implement chain of reponsibility for version - client should implement an interface? * @todo Make sure all SendMessage Commands are framed, not just ones received from onRecv */ class WebSocket implements ProtocolInterface { @@ -36,7 +35,7 @@ class WebSocket implements ProtocolInterface { public function __construct(SocketObserver $application) { $this->_clients = new \SplObjectStorage; - $this->_app = $application; + $this->_app = $application; } /** @@ -58,6 +57,9 @@ class WebSocket implements ProtocolInterface { return $this->_app->onOpen($conn); } + /** + * @todo Cleanup spaghetti code + */ public function onRecv(SocketInterface $from, $msg) { $client = $this->_clients[$from]; if (true !== $client->isHandshakeComplete()) { @@ -102,7 +104,7 @@ class WebSocket implements ProtocolInterface { if ($cmds instanceof Composite) { foreach ($cmds as $cmd) { if ($cmd instanceof SendMessage) { - $sock = $cmd->_socket; + $sock = $cmd->_socket; // bad $clnt = $this->_clients[$sock]; $cmd->setMessage($clnt->getVersion()->frame($cmd->getMessage())); diff --git a/lib/Ratchet/Protocol/WebSocket/Command/Action/Ping.php b/lib/Ratchet/Protocol/WebSocket/Command/Action/Ping.php index b6e1dc2..419d7d4 100644 --- a/lib/Ratchet/Protocol/WebSocket/Command/Action/Ping.php +++ b/lib/Ratchet/Protocol/WebSocket/Command/Action/Ping.php @@ -1,10 +1,8 @@ _version->frame($string); + $unframed = $this->_version->unframe($framed); + + $this->assertEquals($string, $unframed['payload']); + } } \ No newline at end of file