diff --git a/README.md b/README.md index 7cb84ad..e6f762e 100644 --- a/README.md +++ b/README.md @@ -38,11 +38,11 @@ I'm looking into a couple daemonized servers written in PHP to run Ratchet on to ```php _clients = new \SplObjectStorage; } diff --git a/src/Ratchet/Application/ConfiguratorInterface.php b/src/Ratchet/Application/ConfiguratorInterface.php deleted file mode 100644 index abdfa30..0000000 --- a/src/Ratchet/Application/ConfiguratorInterface.php +++ /dev/null @@ -1,12 +0,0 @@ -_app = $application; } @@ -147,7 +148,7 @@ class App implements ApplicationInterface { } } - public function onOpen(Connection $conn) { + public function onOpen(ConnectionInterface $conn) { $new_socket = clone $conn->getSocket(); $new_socket->set_nonblock(); $new_connection = new Connection($new_socket); @@ -158,11 +159,11 @@ class App implements ApplicationInterface { return $this->_app->onOpen($new_connection); } - public function onMessage(Connection $from, $msg) { + public function onMessage(ConnectionInterface $from, $msg) { return $this->_app->onMessage($from, $msg); } - public function onClose(Connection $conn) { + public function onClose(ConnectionInterface $conn) { $resource = $conn->getSocket()->getResource(); $cmd = $this->_app->onClose($conn); @@ -172,7 +173,7 @@ class App implements ApplicationInterface { return $cmd; } - public function onError(Connection $conn, \Exception $e) { + public function onError(ConnectionInterface $conn, \Exception $e) { return $this->_app->onError($conn, $e); } } \ No newline at end of file diff --git a/src/Ratchet/Application/WAMP/App.php b/src/Ratchet/Component/WAMP/App.php similarity index 87% rename from src/Ratchet/Application/WAMP/App.php rename to src/Ratchet/Component/WAMP/App.php index 776bbba..c26fd12 100644 --- a/src/Ratchet/Application/WAMP/App.php +++ b/src/Ratchet/Component/WAMP/App.php @@ -1,11 +1,11 @@ WAMP = new \StdClass; $conn->WAMP->prefixes = array(); $conn->WAMP->subscriptions = array(); @@ -86,7 +86,7 @@ class App implements WebSocketAppInterface { * @throws Exception * @throws JSONException */ - public function onMessage(Connection $from, $msg) { + public function onMessage(ConnectionInterface $from, $msg) { if (null === ($json = @json_decode($msg, true))) { throw new JSONException; } @@ -133,7 +133,7 @@ class App implements WebSocketAppInterface { * @param ... * @return string */ - protected function getUri(Connection $conn, $uri) { + protected function getUri(ConnectionInterface $conn, $uri) { return (isset($conn->WAMP->prefixes[$uri]) ? $conn->WAMP->prefixes[$uri] : $uri); } @@ -157,11 +157,11 @@ class App implements WebSocketAppInterface { $this->_msg_buffer = new Composite; } - public function onClose(Connection $conn) { + public function onClose(ConnectionInterface $conn) { return $this->_app->onClose($conn); } - public function onError(Connection $conn, \Exception $e) { + public function onError(ConnectionInterface $conn, \Exception $e) { return $this->_app->onError($conn, $e); } } \ No newline at end of file diff --git a/src/Ratchet/Application/WAMP/Command/Action/CallError.php b/src/Ratchet/Component/WAMP/Command/Action/CallError.php similarity index 86% rename from src/Ratchet/Application/WAMP/Command/Action/CallError.php rename to src/Ratchet/Component/WAMP/Command/Action/CallError.php index 6938dc1..0afa7de 100644 --- a/src/Ratchet/Application/WAMP/Command/Action/CallError.php +++ b/src/Ratchet/Component/WAMP/Command/Action/CallError.php @@ -1,7 +1,7 @@ _app = $app; $this->_factory = new Factory; } - /** - * Return the desired socket configuration if hosting a WebSocket server - * This method may be removed - * @return array - */ - public static function getDefaultConfig() { - return array( - 'domain' => AF_INET - , 'type' => SOCK_STREAM - , 'protocol' => SOL_TCP - , 'options' => array( - SOL_SOCKET => array(SO_REUSEADDR => 1) - ) - ); - } - - public function onOpen(Connection $conn) { + public function onOpen(ConnectionInterface $conn) { $conn->WebSocket = new \stdClass; $conn->WebSocket->handshake = false; $conn->WebSocket->headers = ''; @@ -80,7 +63,7 @@ class App implements ApplicationInterface, ConfiguratorInterface { * @todo This needs some major refactoring * @todo "Once the client's opening handshake has been sent, the client MUST wait for a response from the server before sending any further data." */ - public function onMessage(Connection $from, $msg) { + public function onMessage(ConnectionInterface $from, $msg) { if (true !== $from->WebSocket->handshake) { if (!isset($from->WebSocket->version)) { $from->WebSocket->headers .= $msg; @@ -160,14 +143,14 @@ class App implements ApplicationInterface, ConfiguratorInterface { } } - public function onClose(Connection $conn) { + public function onClose(ConnectionInterface $conn) { return $this->prepareCommand($this->_app->onClose($conn)); } /** * @todo Shouldn't I be using prepareCommand() on the return? look into this */ - public function onError(Connection $conn, \Exception $e) { + public function onError(ConnectionInterface $conn, \Exception $e) { return $this->_app->onError($conn, $e); } diff --git a/src/Ratchet/Application/WebSocket/Command/Action/Disconnect.php b/src/Ratchet/Component/WebSocket/Command/Action/Disconnect.php similarity index 67% rename from src/Ratchet/Application/WebSocket/Command/Action/Disconnect.php rename to src/Ratchet/Component/WebSocket/Command/Action/Disconnect.php index f2e6a8d..3b2768b 100644 --- a/src/Ratchet/Application/WebSocket/Command/Action/Disconnect.php +++ b/src/Ratchet/Component/WebSocket/Command/Action/Disconnect.php @@ -1,7 +1,7 @@ _socket->close(); } diff --git a/src/Ratchet/Component/WebSocket/Command/Action/Ping.php b/src/Ratchet/Component/WebSocket/Command/Action/Ping.php new file mode 100644 index 0000000..4632e90 --- /dev/null +++ b/src/Ratchet/Component/WebSocket/Command/Action/Ping.php @@ -0,0 +1,12 @@ +onClose($this->getConnection()); @@ -19,7 +19,7 @@ class CloseConnection extends ActionTemplate { $comp->enqueue($ret); $rt = new Runtime($this->getConnection()); - $rt->setCommand(function(Connection $conn, ApplicationInterface $scope) { + $rt->setCommand(function(ConnectionInterface $conn, ComponentInterface $scope) { $conn->getSocket()->close(); }); $comp->enqueue($rt); diff --git a/src/Ratchet/Resource/Command/Action/Null.php b/src/Ratchet/Resource/Command/Action/Null.php index a23f703..42cb563 100644 --- a/src/Ratchet/Resource/Command/Action/Null.php +++ b/src/Ratchet/Resource/Command/Action/Null.php @@ -1,12 +1,12 @@ _command = $callback; } - public function execute(ApplicationInterface $scope = null) { + public function execute(ComponentInterface $scope = null) { return call_user_func($this->_command, $this->getConnection(), $scope); } } \ No newline at end of file diff --git a/src/Ratchet/Resource/Command/Action/SendMessage.php b/src/Ratchet/Resource/Command/Action/SendMessage.php index 74eb595..de4cc24 100644 --- a/src/Ratchet/Resource/Command/Action/SendMessage.php +++ b/src/Ratchet/Resource/Command/Action/SendMessage.php @@ -1,7 +1,7 @@ _message)) { throw new \UnexpectedValueException("Message is empty"); } diff --git a/src/Ratchet/Resource/Command/ActionInterface.php b/src/Ratchet/Resource/Command/ActionInterface.php index 514ee24..4c196f4 100644 --- a/src/Ratchet/Resource/Command/ActionInterface.php +++ b/src/Ratchet/Resource/Command/ActionInterface.php @@ -1,6 +1,6 @@ _conn = $conn; } diff --git a/src/Ratchet/Resource/Command/CommandInterface.php b/src/Ratchet/Resource/Command/CommandInterface.php index 986e5af..5ea31c6 100644 --- a/src/Ratchet/Resource/Command/CommandInterface.php +++ b/src/Ratchet/Resource/Command/CommandInterface.php @@ -1,6 +1,6 @@ setIteratorMode(static::IT_MODE_DELETE); $recursive = new self; diff --git a/src/Ratchet/Resource/Command/Factory.php b/src/Ratchet/Resource/Command/Factory.php index 559ee13..1de6b6d 100644 --- a/src/Ratchet/Resource/Command/Factory.php +++ b/src/Ratchet/Resource/Command/Factory.php @@ -1,6 +1,6 @@ _mapped_commands[$name])) { $cmd = $this->_mapped_commands[$name]; return new $cmd($conn); diff --git a/src/Ratchet/Resource/Connection.php b/src/Ratchet/Resource/Connection.php index 1a21f78..6f22a22 100644 --- a/src/Ratchet/Resource/Connection.php +++ b/src/Ratchet/Resource/Connection.php @@ -3,11 +3,10 @@ namespace Ratchet\Resource; use Ratchet\SocketInterface; /** - * @todo Consider if this belongs under Application - * @todo Construct should have StorageInterface, currently all is memory, should be different ones - * That will allow a queue system, communication between threaded connections + * A proxy object representing a connection to the application + * This acts as a container to storm data (in memory) about the connection */ -class Connection { +class Connection implements ConnectionInterface { protected $_data = array(); /** @@ -38,18 +37,14 @@ class Connection { } /** - * Set an attribute to the connection - * @param mixed - * @param mixed + * @{inheritdoc} */ public function __set($name, $value) { $this->_data[$name] = $value; } /** - * Get a previously set attribute bound to the connection - * @return mixed - * @throws \InvalidArgumentException + * @{inheritdoc} */ public function __get($name) { if (!$this->__isset($name)) { @@ -64,15 +59,14 @@ class Connection { } /** - * @param mixed - * @return bool + * @{inheritdoc} */ public function __isset($name) { return isset($this->_data[$name]); } /** - * @param mixed + * @{inheritdoc} */ public function __unset($name) { unset($this->_data[$name]); diff --git a/src/Ratchet/Resource/ConnectionInterface.php b/src/Ratchet/Resource/ConnectionInterface.php new file mode 100644 index 0000000..ed9ad9e --- /dev/null +++ b/src/Ratchet/Resource/ConnectionInterface.php @@ -0,0 +1,35 @@ + $pair) { - foreach ($pair as $optname => $optval) { - $socket->set_option($level, $optname, $optval); - } - } - } - - return $socket; - } - /** * @internal * @param int Specifies the protocol family to be used by the socket. diff --git a/tests/Ratchet/Tests/Application/Server/AppTest.php b/tests/Ratchet/Tests/Application/Server/AppTest.php index 4e3aed6..583f8ca 100644 --- a/tests/Ratchet/Tests/Application/Server/AppTest.php +++ b/tests/Ratchet/Tests/Application/Server/AppTest.php @@ -1,11 +1,11 @@ _app = new TestApp; $this->_server = new ServerApp($this->_app); - $ref = new \ReflectionClass('\Ratchet\Application\Server\App'); + $ref = new \ReflectionClass('\Ratchet\Component\Server\App'); $prop = $ref->getProperty('_run'); $prop->setAccessible(true); $prop->setValue($this->_server, false); diff --git a/tests/Ratchet/Tests/Application/WebSocket/AppTest.php b/tests/Ratchet/Tests/Application/WebSocket/AppTest.php deleted file mode 100644 index 126647a..0000000 --- a/tests/Ratchet/Tests/Application/WebSocket/AppTest.php +++ /dev/null @@ -1,20 +0,0 @@ -_ws = new RealApp(new Application); - } - - public function testGetConfigReturnsArray() { - $this->assertInternalType('array', $this->_ws->getDefaultConfig()); - } -} \ No newline at end of file diff --git a/tests/Ratchet/Tests/Application/WebSocket/Version/Hixie76Test.php b/tests/Ratchet/Tests/Application/WebSocket/Version/Hixie76Test.php index 58a6245..5661274 100644 --- a/tests/Ratchet/Tests/Application/WebSocket/Version/Hixie76Test.php +++ b/tests/Ratchet/Tests/Application/WebSocket/Version/Hixie76Test.php @@ -1,9 +1,9 @@ isInstanceOf('\\Ratchet\\Application\\WebSocket\\Version\\VersionInterface'); + $constraint = $this->isInstanceOf('\\Ratchet\\Component\\WebSocket\\Version\\VersionInterface'); $this->assertThat($this->_version, $constraint); } diff --git a/tests/Ratchet/Tests/Application/WebSocket/Version/HyBi10Test.php b/tests/Ratchet/Tests/Application/WebSocket/Version/HyBi10Test.php index 9b22b09..65bf06c 100644 --- a/tests/Ratchet/Tests/Application/WebSocket/Version/HyBi10Test.php +++ b/tests/Ratchet/Tests/Application/WebSocket/Version/HyBi10Test.php @@ -1,10 +1,10 @@ isInstanceOf('\\Ratchet\\Application\\WebSocket\\Version\\VersionInterface'); + $constraint = $this->isInstanceOf('\\Ratchet\\Component\\WebSocket\\Version\\VersionInterface'); $this->assertThat($this->_version, $constraint); } diff --git a/tests/Ratchet/Tests/Application/WebSocket/Version/RFC6455/FrameTest.php b/tests/Ratchet/Tests/Application/WebSocket/Version/RFC6455/FrameTest.php index c870d65..bd16598 100644 --- a/tests/Ratchet/Tests/Application/WebSocket/Version/RFC6455/FrameTest.php +++ b/tests/Ratchet/Tests/Application/WebSocket/Version/RFC6455/FrameTest.php @@ -1,9 +1,9 @@ isInstanceOf('\\Ratchet\\Application\\WebSocket\\Version\\VersionInterface'); + $constraint = $this->isInstanceOf('\\Ratchet\\Component\\WebSocket\\Version\\VersionInterface'); $this->assertThat($this->_version, $constraint); } diff --git a/tests/Ratchet/Tests/Mock/Application.php b/tests/Ratchet/Tests/Mock/Application.php index ac3314b..5cb5b61 100644 --- a/tests/Ratchet/Tests/Mock/Application.php +++ b/tests/Ratchet/Tests/Mock/Application.php @@ -1,10 +1,10 @@ _app = $app; } - public function onOpen(Connection $conn) { + public function onOpen(ConnectionInterface $conn) { $this->_conn_open = $conn; } - public function onMessage(Connection $from, $msg) { + public function onMessage(ConnectionInterface $from, $msg) { $this->_conn_recv = $from; $this->_msg_recv = $msg; } - public function onClose(Connection $conn) { + public function onClose(ConnectionInterface $conn) { $this->_conn_close = $conn; } - public function onError(Connection $conn, \Exception $e) { + public function onError(ConnectionInterface $conn, \Exception $e) { $this->_conn_error = $conn; $this->_excep_error = $e; }