diff --git a/lib/Ratchet/Command/CloseConnection.php b/lib/Ratchet/Command/Action/CloseConnection.php similarity index 84% rename from lib/Ratchet/Command/CloseConnection.php rename to lib/Ratchet/Command/Action/CloseConnection.php index 41308de..cd7b374 100644 --- a/lib/Ratchet/Command/CloseConnection.php +++ b/lib/Ratchet/Command/Action/CloseConnection.php @@ -1,5 +1,6 @@ addActionPath(__NAMESPACE__ . '\\Action'); + } + + public function addActionPath($namespace) { + $this->_paths[] = $this->slashIt($namespace); + } + + public function newComposite() { + return new Composite; + } + + /** + * @param string + * @return CommandInterface + * @throws UnexpectedValueException + */ + public function newCommand($name, SocketInterface $conn) { + $cmd = null; + foreach ($this->_paths as $path) { + if (class_exists($path . $name)) { + $cmd = $path . $name; + break; + } + } + + if (null === $cmd) { + throw new \UnexepctedValueException("Command {$name} not found"); + } + + return new $cmd($conn); + } + + protected function slashIt($ns) { + return (substr($ns, -1) == '\\' ? $ns : $ns . '\\'); + } +} \ No newline at end of file diff --git a/lib/Ratchet/Protocol/WebSocket.php b/lib/Ratchet/Protocol/WebSocket.php index 80e5a55..5ca2ad6 100644 --- a/lib/Ratchet/Protocol/WebSocket.php +++ b/lib/Ratchet/Protocol/WebSocket.php @@ -7,7 +7,7 @@ use Ratchet\Protocol\WebSocket\VersionInterface; use Ratchet\SocketInterface; use Ratchet\SocketObserver; use Ratchet\Command\CommandInterface; -use Ratchet\Command\SendMessage; +use Ratchet\Command\Action\SendMessage; use Ratchet\Command\Composite; /** diff --git a/lib/Ratchet/Command/Ping.php b/lib/Ratchet/Protocol/WebSocket/Command/Action/Ping.php similarity index 100% rename from lib/Ratchet/Command/Ping.php rename to lib/Ratchet/Protocol/WebSocket/Command/Action/Ping.php diff --git a/lib/Ratchet/Command/Pong.php b/lib/Ratchet/Protocol/WebSocket/Command/Action/Pong.php similarity index 100% rename from lib/Ratchet/Command/Pong.php rename to lib/Ratchet/Protocol/WebSocket/Command/Action/Pong.php