From 47b7110dc1a2ca4ff89553c1db7cd47d882f74de Mon Sep 17 00:00:00 2001 From: Chris Boden Date: Sat, 12 Nov 2011 20:51:54 -0500 Subject: [PATCH] Namespaces Fixed all the namespaces to match new folder structure --- lib/Ratchet/Application/ProtocolInterface.php | 10 ++--- lib/Ratchet/Application/Server/App.php | 44 ++++++++----------- lib/Ratchet/Application/WebSocket/App.php | 41 +++++++++-------- .../Application/WebSocket/AppInterface.php | 8 ++-- lib/Ratchet/Application/WebSocket/Client.php | 6 +-- .../WebSocket/Command/Action/Disconnect.php | 8 ++-- .../WebSocket/Command/Action/Ping.php | 8 ++-- .../WebSocket/Command/Action/Pong.php | 8 ++-- .../Application/WebSocket/Util/HTTP.php | 2 +- .../Application/WebSocket/Version/Hixie76.php | 2 +- .../Application/WebSocket/Version/HyBi10.php | 4 +- .../WebSocket/Version/VersionInterface.php | 2 +- lib/Ratchet/ObserverInterface.php | 19 +++++--- .../Command/Action/CloseConnection.php | 14 +++--- lib/Ratchet/Resource/Command/Action/Null.php | 8 ++-- .../Resource/Command/Action/Runtime.php | 10 ++--- .../Resource/Command/Action/SendMessage.php | 8 ++-- .../Resource/Command/ActionInterface.php | 2 +- .../Resource/Command/ActionTemplate.php | 2 +- .../Resource/Command/CommandInterface.php | 8 ++-- lib/Ratchet/Resource/Command/Composite.php | 6 +-- lib/Ratchet/Resource/Command/Factory.php | 4 +- .../Resource/Connection/Connection.php | 2 +- .../Connection/ConnectionInterface.php | 2 +- lib/Ratchet/Socket.php | 5 ++- tests/Ratchet/Tests/Mock/Application.php | 8 ++-- tests/Ratchet/Tests/Mock/Protocol.php | 6 +-- .../WebSocket/Version/Hixie76Test.php | 6 +-- .../Protocol/WebSocket/Version/HyBi10Test.php | 9 ++-- .../Ratchet/Tests/Protocol/WebSocketTest.php | 11 ++--- tests/Ratchet/Tests/ServerTest.php | 28 +----------- tests/Ratchet/Tests/SocketTest.php | 6 --- 32 files changed, 142 insertions(+), 165 deletions(-) diff --git a/lib/Ratchet/Application/ProtocolInterface.php b/lib/Ratchet/Application/ProtocolInterface.php index f98c4b6..ae67292 100644 --- a/lib/Ratchet/Application/ProtocolInterface.php +++ b/lib/Ratchet/Application/ProtocolInterface.php @@ -1,12 +1,12 @@ _master = $host; - $socket = $host->getResource(); - $this->_resources[] = $socket; + public function __construct(ObserverInterface $application = null) { + if (null === $application) { + throw new \UnexpectedValueException("Server requires an application to run off of"); + } + $this->_app = $application; $this->_connections = new \ArrayIterator(array()); - - $this->_app = $application; - } - - /** - * @return ArrayIterator of SocketInterfaces - * @todo This interface was originally in place as Server was passed up/down chain, but isn't anymore, consider removing - */ - public function getIterator() { - return $this->_connections; } /* + * @param Ratchet\SocketInterface * @param mixed The address to listen for incoming connections on. "0.0.0.0" to listen from anywhere * @param int The port to listen to connections on - * @throws Exception + * @throws Ratchet\Exception * @todo Validate address. Use socket_get_option, if AF_INET must be IP, if AF_UNIX must be path * @todo Consider making the 4kb listener changable */ - public function run($address = '127.0.0.1', $port = 1025) { + public function run(SocketInterface $host, $address = '127.0.0.1', $port = 1025) { + $this->_master = $host; + $this->_resources[] = $host->getResource(); + $recv_bytes = 1024; set_time_limit(0); diff --git a/lib/Ratchet/Application/WebSocket/App.php b/lib/Ratchet/Application/WebSocket/App.php index 2fcc7ee..9158b28 100644 --- a/lib/Ratchet/Application/WebSocket/App.php +++ b/lib/Ratchet/Application/WebSocket/App.php @@ -1,13 +1,14 @@ null ); - public function __construct(SocketObserver $application) { + public function __construct(ObserverInterface $app = null) { + if (null === $app) { + throw new \UnexpectedValueException("WebSocket requires an application to run off of"); + } + $this->_clients = new \SplObjectStorage; - $this->_app = $application; + $this->_app = $app; $this->_factory = new Factory; } @@ -128,8 +133,8 @@ class WebSocket implements ProtocolInterface { /** * Checks if a return Command from your application is a message, if so encode it/them - * @param Ratchet\Command\CommandInterface|NULL - * @return Ratchet\Command\CommandInterface|NULL + * @param Ratchet\Resource\Command\CommandInterface|NULL + * @return Ratchet\Resource\Command\CommandInterface|NULL */ protected function prepareCommand(CommandInterface $command = null) { if ($command instanceof SendMessage) { @@ -169,7 +174,7 @@ class WebSocket implements ProtocolInterface { */ protected function versionFactory($version) { if (null === $this->_versions[$version]) { - $ns = __CLASS__ . "\\Version\\{$version}"; + $ns = __NAMESPACE__ . "\\Version\\{$version}"; $this->_version[$version] = new $ns; } diff --git a/lib/Ratchet/Application/WebSocket/AppInterface.php b/lib/Ratchet/Application/WebSocket/AppInterface.php index 0b613a7..bb35340 100644 --- a/lib/Ratchet/Application/WebSocket/AppInterface.php +++ b/lib/Ratchet/Application/WebSocket/AppInterface.php @@ -1,13 +1,13 @@ _socket->close(); } diff --git a/lib/Ratchet/Application/WebSocket/Command/Action/Ping.php b/lib/Ratchet/Application/WebSocket/Command/Action/Ping.php index ecb662c..ec550e7 100644 --- a/lib/Ratchet/Application/WebSocket/Command/Action/Ping.php +++ b/lib/Ratchet/Application/WebSocket/Command/Action/Ping.php @@ -1,9 +1,9 @@ onClose($this->getSocket()); @@ -19,7 +19,7 @@ class CloseConnection extends ActionTemplate { $comp->enqueue($ret); $rt = new Runtime($this->getSocket()); - $rt->setCommand(function(SocketInterface $socket, SocketObserver $scope) { + $rt->setCommand(function(SocketInterface $socket, ObserverInterface $scope) { $socket->close(); }); $comp->enqueue($rt); diff --git a/lib/Ratchet/Resource/Command/Action/Null.php b/lib/Ratchet/Resource/Command/Action/Null.php index 775641d..78a6e16 100644 --- a/lib/Ratchet/Resource/Command/Action/Null.php +++ b/lib/Ratchet/Resource/Command/Action/Null.php @@ -1,12 +1,12 @@ _command = $callback; } - public function execute(SocketObserver $scope = null) { + public function execute(ObserverInterface $scope = null) { return call_user_func($this->_command, $this->getSocket(), $scope); } } \ No newline at end of file diff --git a/lib/Ratchet/Resource/Command/Action/SendMessage.php b/lib/Ratchet/Resource/Command/Action/SendMessage.php index de02bd7..ca94da1 100644 --- a/lib/Ratchet/Resource/Command/Action/SendMessage.php +++ b/lib/Ratchet/Resource/Command/Action/SendMessage.php @@ -1,7 +1,7 @@ _message)) { throw new \UnexpectedValueException("Message is empty"); } diff --git a/lib/Ratchet/Resource/Command/ActionInterface.php b/lib/Ratchet/Resource/Command/ActionInterface.php index bccae43..6110279 100644 --- a/lib/Ratchet/Resource/Command/ActionInterface.php +++ b/lib/Ratchet/Resource/Command/ActionInterface.php @@ -1,5 +1,5 @@ setIteratorMode(static::IT_MODE_DELETE); $recursive = new self; diff --git a/lib/Ratchet/Resource/Command/Factory.php b/lib/Ratchet/Resource/Command/Factory.php index 68217b8..ba6b83d 100644 --- a/lib/Ratchet/Resource/Command/Factory.php +++ b/lib/Ratchet/Resource/Command/Factory.php @@ -1,9 +1,9 @@ + * @todo Possibly move this into Ratchet\Resource - another concrete could use streams */ class Socket implements SocketInterface { /** @@ -110,7 +111,7 @@ class Socket implements SocketInterface { } /** - * @param Ratchet\Protocol\ProtocolInterface + * @param Ratchet\Application\ProtocolInterface * @return Socket * @throws Exception */ diff --git a/tests/Ratchet/Tests/Mock/Application.php b/tests/Ratchet/Tests/Mock/Application.php index 3e0ed5f..a32db0e 100644 --- a/tests/Ratchet/Tests/Mock/Application.php +++ b/tests/Ratchet/Tests/Mock/Application.php @@ -1,11 +1,13 @@ isInstanceOf('\\Ratchet\\Protocol\\WebSocket\\Version\\VersionInterface'); + $constraint = $this->isInstanceOf('\\Ratchet\\Application\\WebSocket\\Version\\VersionInterface'); $this->assertThat($this->_version, $constraint); } diff --git a/tests/Ratchet/Tests/Protocol/WebSocket/Version/HyBi10Test.php b/tests/Ratchet/Tests/Protocol/WebSocket/Version/HyBi10Test.php index 79e6b2e..fe6bff8 100644 --- a/tests/Ratchet/Tests/Protocol/WebSocket/Version/HyBi10Test.php +++ b/tests/Ratchet/Tests/Protocol/WebSocket/Version/HyBi10Test.php @@ -1,9 +1,9 @@ _version = new HyBi10(); } + /** + * Is this useful? + */ public function testClassImplementsVersionInterface() { - $constraint = $this->isInstanceOf('\\Ratchet\\Protocol\\WebSocket\\Version\\VersionInterface'); + $constraint = $this->isInstanceOf('\\Ratchet\\Application\\WebSocket\\Version\\VersionInterface'); $this->assertThat($this->_version, $constraint); } diff --git a/tests/Ratchet/Tests/Protocol/WebSocketTest.php b/tests/Ratchet/Tests/Protocol/WebSocketTest.php index a7be41c..3402562 100644 --- a/tests/Ratchet/Tests/Protocol/WebSocketTest.php +++ b/tests/Ratchet/Tests/Protocol/WebSocketTest.php @@ -1,11 +1,11 @@ isInstanceOf('\\Ratchet\\SocketObserver'); - $this->assertThat($this->_ws, $constraint); - } - - public function testServerImplementsProtocolInterface() { - $constraint = $this->isInstanceOf('\\Ratchet\\Protocol\ProtocolInterface'); + $constraint = $this->isInstanceOf('\\Ratchet\\ObserverInterface'); $this->assertThat($this->_ws, $constraint); } diff --git a/tests/Ratchet/Tests/ServerTest.php b/tests/Ratchet/Tests/ServerTest.php index 9111364..026d530 100644 --- a/tests/Ratchet/Tests/ServerTest.php +++ b/tests/Ratchet/Tests/ServerTest.php @@ -1,6 +1,6 @@ _catalyst = new Socket; $this->_app = new TestApp; - $this->_server = new Server($this->_catalyst, $this->_app); + $this->_server = new Server($this->_app); } protected function getPrivateProperty($class, $name) { @@ -26,30 +26,6 @@ class ServerTest extends \PHPUnit_Framework_TestCase { return $property->getValue($class); } - public function testServerHasServerInterface() { - $constraint = $this->isInstanceOf('\\Ratchet\\SocketObserver'); - $this->assertThat($this->_server, $constraint); - } - - public function testIteration() { - $this->assertInstanceOf('\\Iterator', $this->_server->getIterator()); - } - - public function SKIPtestServerCanNotRunWithoutApplication() { - $this->setExpectedException('\\RuntimeException'); - $this->_server->run(); - } - -/* - public function testAttatchedReceiverIsSet() { - $app = new TestApp(); - - $this->_server->attatchReceiver($app); -// todo, use proper assertions...can't look them up atm, no internet - $this->assertAttributeEquals(Array(spl_object_hash($app) => $app), '_receivers', $this->_server); - } - -/**/ public function testBindToInvalidAddress() { return $this->markTestIncomplete(); diff --git a/tests/Ratchet/Tests/SocketTest.php b/tests/Ratchet/Tests/SocketTest.php index 7fa946c..14f784a 100644 --- a/tests/Ratchet/Tests/SocketTest.php +++ b/tests/Ratchet/Tests/SocketTest.php @@ -23,12 +23,6 @@ class SocketTest extends \PHPUnit_Framework_TestCase { $this->_socket = new Socket(); } -/* - public function testWhatGoesInConstructComesOut() { - $this->assertTrue(false); - } -*/ - public function testGetDefaultConfigForConstruct() { $ref_conf = static::getMethod('getConfig'); $config = $ref_conf->invokeArgs($this->_socket, array());