From 66e656ec63ef5c4a850fb92b2fb2e96e7228cc4b Mon Sep 17 00:00:00 2001
From: Chris Boden <cboden@gmail.com>
Date: Mon, 7 Nov 2011 12:06:01 -0500
Subject: [PATCH] Documentation

---
 README.md                                        | 16 ++++++++--------
 lib/Ratchet/Command/Action/SendMessage.php       |  1 +
 lib/Ratchet/Command/CommandInterface.php         |  1 +
 lib/Ratchet/Command/Factory.php                  | 11 +++++++++++
 lib/Ratchet/Protocol/WebSocket.php               |  6 +++++-
 lib/Ratchet/Protocol/WebSocket/Util/HTTP.php     |  3 +++
 .../Protocol/WebSocket/Version/Hixie76.php       |  1 +
 7 files changed, 30 insertions(+), 9 deletions(-)

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
 <?php
-namespace Me;
+namespace MyApps;
 use Ratchet\SocketObserver, Ratchet\SocketInterface;
 use Ratchet\Socket, Ratchet\Server, Ratchet\Protocol\WebSocket;
-use Ratchet\Command\Composite, Ratchet\Command\SendMessage;
+use Ratchet\Command\Factory;
 
 /**
  * Send any incoming messages to all connected clients (except sender)
  */
 class Chat implements SocketObserver {
+    protected $_factory;
     protected $_clients;
 
     public function __construct() {
+        $this->_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 @@
 <?php
 namespace Ratchet\Protocol;
 use Ratchet\Protocol\WebSocket\Client;
-use Ratchet\Protocol\WebSocket\Version;
 use Ratchet\Protocol\WebSocket\VersionInterface;
 use Ratchet\SocketInterface;
 use Ratchet\SocketObserver;
@@ -19,15 +18,20 @@ use Ratchet\Protocol\WebSocket\Util\HTTP;
  */
 class WebSocket implements ProtocolInterface {
     /**
+     * Lookup for connected clients
      * @type SplObjectStorage
      */
     protected $_clients;
 
     /**
+     * Decorated application
      * @type Ratchet\SocketObserver
      */
     protected $_app;
 
+    /**
+     * @internal
+     */
     protected $_versions = array(
         'HyBi10'  => 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 @@
 <?php
 namespace Ratchet\Protocol\WebSocket\Util;
 
+/**
+ * A helper class for handling HTTP requests
+ */
 class HTTP {
     /**
      * @param string
diff --git a/lib/Ratchet/Protocol/WebSocket/Version/Hixie76.php b/lib/Ratchet/Protocol/WebSocket/Version/Hixie76.php
index 9aea98a..5da1752 100644
--- a/lib/Ratchet/Protocol/WebSocket/Version/Hixie76.php
+++ b/lib/Ratchet/Protocol/WebSocket/Version/Hixie76.php
@@ -8,6 +8,7 @@ namespace Ratchet\Protocol\WebSocket\Version;
  */
 class Hixie76 implements VersionInterface {
     /**
+     * @param string
      * @return string
      */
     public function handshake($message) {