diff --git a/README.md b/README.md index 485cb1b..e4f0287 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Re-use your application without changing any of its code just by wrapping it in ##WebSockets -* Supports the HyBi-10 and Hixie76 protocol versions +* Supports the HyBi-10 and Hixie76 protocol versions (at the same time) * Tested on Chrome 14, Firefox 7, Safari 5, iOS 4.2 --- @@ -17,18 +17,20 @@ Re-use your application without changing any of its code just by wrapping it in ```php _factory = new Factory; $this->_clients = new \SplObjectStorage; } @@ -37,13 +39,11 @@ class Chat implements SocketObserver { } public function onRecv(SocketInterface $from, $msg) { - $stack = new Composite; + $stack = $this->_factory->newComposite(); + foreach ($this->_clients as $client) { if ($from != $client) { - $message = new SendMessage($client); - $message->setMessage($msg); - - $stack->enqueue($message); + $stack->enqueue($this->_factory->newCommand('SendMessage', $client)->setMessage($msg)); } } diff --git a/lib/Ratchet/Command/Action/SendMessage.php b/lib/Ratchet/Command/Action/SendMessage.php index 30178a5..16029c4 100644 --- a/lib/Ratchet/Command/Action/SendMessage.php +++ b/lib/Ratchet/Command/Action/SendMessage.php @@ -24,6 +24,7 @@ class SendMessage implements CommandInterface { /** * The message to send to the socket(s) * @param string + * @return SendMessage Fluid interface */ public function setMessage($msg) { $this->_message = (string)$msg; diff --git a/lib/Ratchet/Command/CommandInterface.php b/lib/Ratchet/Command/CommandInterface.php index 986a747..5574ae4 100644 --- a/lib/Ratchet/Command/CommandInterface.php +++ b/lib/Ratchet/Command/CommandInterface.php @@ -9,6 +9,7 @@ use Ratchet\SocketInterface; interface CommandInterface { /** * Pass the Sockets to execute the command on + * @param Ratchet\SocketInterface */ function __construct(SocketInterface $socket); diff --git a/lib/Ratchet/Command/Factory.php b/lib/Ratchet/Command/Factory.php index cb88629..79ba037 100644 --- a/lib/Ratchet/Command/Factory.php +++ b/lib/Ratchet/Command/Factory.php @@ -9,10 +9,17 @@ class Factory { $this->addActionPath(__NAMESPACE__ . '\\Action'); } + /** + * Add a new namespace of which CommandInterfaces reside under to autoload with $this->newCommand() + * @param string + */ public function addActionPath($namespace) { $this->_paths[] = $this->slashIt($namespace); } + /** + * @return Composite + */ public function newComposite() { return new Composite; } @@ -38,6 +45,10 @@ class Factory { return new $cmd($conn); } + /** + * @param string + * @return string + */ protected function slashIt($ns) { return (substr($ns, -1) == '\\' ? $ns : $ns . '\\'); } diff --git a/lib/Ratchet/Protocol/WebSocket.php b/lib/Ratchet/Protocol/WebSocket.php index b3b5ae9..e5d05a3 100644 --- a/lib/Ratchet/Protocol/WebSocket.php +++ b/lib/Ratchet/Protocol/WebSocket.php @@ -1,7 +1,6 @@ null , 'Hixie76' => null diff --git a/lib/Ratchet/Protocol/WebSocket/Util/HTTP.php b/lib/Ratchet/Protocol/WebSocket/Util/HTTP.php index 8e52f61..d4f34c8 100644 --- a/lib/Ratchet/Protocol/WebSocket/Util/HTTP.php +++ b/lib/Ratchet/Protocol/WebSocket/Util/HTTP.php @@ -1,6 +1,9 @@