From 6a44d8123a927c3694f26160878afba9baf0de05 Mon Sep 17 00:00:00 2001 From: Chris Boden Date: Wed, 18 Apr 2012 21:14:58 -0400 Subject: [PATCH 01/11] Packagist test --- composer.json | 2 +- composer.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index e54a528..e1c6a63 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "cboden/Ratchet" , "type": "library" , "description": "PHP WebSocket server component library" - , "keywords": ["WebSocket"] + , "keywords": ["WebSocket", "Server"] , "repository": "https://github.com/cboden/Ratchet" , "license": "MIT" , "authors": [ diff --git a/composer.lock b/composer.lock index c3e0e39..6a2e39f 100644 --- a/composer.lock +++ b/composer.lock @@ -1,5 +1,5 @@ { - "hash": "be8f67a3964cca0e4ffe4b98a7527daa", + "hash": "b2332c240ecc001df7f0f0623491f8c3", "packages": [ { "package": "guzzle", From 59823fc2dedbe3d6272b812dab7f06c1fea2fc8f Mon Sep 17 00:00:00 2001 From: Chris Boden Date: Wed, 18 Apr 2012 21:48:21 -0400 Subject: [PATCH 02/11] Attempting dependency fix --- README.md | 6 +++--- composer.json | 21 ++++++++++++--------- composer.lock | 11 +++-------- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 39fd4b2..64be92c 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Build Status](https://secure.travis-ci.org/cboden/Ratchet.png)](http://travis-ci.org/cboden/Ratchet) +[![Build Status](https://secure.travis-ci.org/cboden/Ratchet.png?branch=master)](http://travis-ci.org/cboden/Ratchet) #Ratchet @@ -21,13 +21,13 @@ Note that you can not run two applications (Apache and Ratchet) on the same port Cookies from your domain will be passed to the socket server, allowing you to identify users. Accessing your website's session data in Ratchet is a [feature in the works](https://github.com/cboden/Ratchet/tree/symfony/sessions). -See https://github.com/cboden/socket-demos for some out-of-the-box working demos using Ratchet. +See https://github.com/cboden/Ratchet-examples for some out-of-the-box working demos using Ratchet. ###Future considerations Ideally, soon, web servers will start supporting WebSockets to some capacity and PHP will no longer need to run its self from the command line. In theory, the server (like Nginx) would recognize the HTTP handshake request to upgrade the protocol to WebSockets and run/pass data through to a user -configured PHP file. When this happens, you can keep your script the same, just remove the Server Application wrapper and maybe eventually the +configured PHP file. When this happens, you can keep your script the same, just remove the IOServerComponent wrapper and maybe eventually the WebSocket Application wrapper if the servers recognize the protocol message framing. --- diff --git a/composer.json b/composer.json index e1c6a63..899d359 100644 --- a/composer.json +++ b/composer.json @@ -18,13 +18,20 @@ , "Ratchet": "src" } } - , "repositories": { - "guzzle": { + , "require": { + "php": ">=5.3.2" + , "guzzle/guzzle": "v2.0.2" + } + , "replace": { + "guzzle/guzzle": "v2.0.2" + } + , "repositories": [ + { "type": "package" , "package": { - "name": "guzzle" + "name": "guzzle/guzzle" , "type": "library" - , "version": "2.0.2" + , "version": "v2.0.2" , "autoload": { "psr-0": { "Guzzle": "src" @@ -37,9 +44,5 @@ } } } - } - , "require": { - "php": ">=5.3.2" - , "guzzle": "2.0.2" - } + ] } \ No newline at end of file diff --git a/composer.lock b/composer.lock index 6a2e39f..21b9d7d 100644 --- a/composer.lock +++ b/composer.lock @@ -1,14 +1,9 @@ { - "hash": "b2332c240ecc001df7f0f0623491f8c3", + "hash": "3fb51c7b57fb058065e37de578901055", "packages": [ { - "package": "guzzle", - "version": "2.0.2" - }, - { - "package": "symfony/http-foundation", - "version": "dev-master", - "source-reference": "b9aceabb83f3d03fe451cdd867d987e863e7a25e" + "package": "guzzle/guzzle", + "version": "v2.0.2" } ], "packages-dev": null, From 71ad5da58e166e7c99564441279fe60cec935ff5 Mon Sep 17 00:00:00 2001 From: Chris Boden Date: Wed, 18 Apr 2012 21:55:30 -0400 Subject: [PATCH 03/11] Another dependency fix attempt --- composer.json | 3 --- composer.lock | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 899d359..c3356e3 100644 --- a/composer.json +++ b/composer.json @@ -22,9 +22,6 @@ "php": ">=5.3.2" , "guzzle/guzzle": "v2.0.2" } - , "replace": { - "guzzle/guzzle": "v2.0.2" - } , "repositories": [ { "type": "package" diff --git a/composer.lock b/composer.lock index 21b9d7d..ffb54f4 100644 --- a/composer.lock +++ b/composer.lock @@ -1,5 +1,5 @@ { - "hash": "3fb51c7b57fb058065e37de578901055", + "hash": "ccba37aea83a191c0846f8cdd9c57025", "packages": [ { "package": "guzzle/guzzle", From ffabf09426a1c1404261869c5abe8c5c1f6b0bbc Mon Sep 17 00:00:00 2001 From: Chris Boden Date: Wed, 18 Apr 2012 22:12:28 -0400 Subject: [PATCH 04/11] Deps - I give up Trying to control fetching the Guzzle repo without its dependencies, as they're not needed in Ratchet - but composer isn't recognizing my git repo overriding Guzzle's composer files --- composer.json | 20 -------------------- composer.lock | 17 ++++++++++++++++- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/composer.json b/composer.json index c3356e3..137e81d 100644 --- a/composer.json +++ b/composer.json @@ -22,24 +22,4 @@ "php": ">=5.3.2" , "guzzle/guzzle": "v2.0.2" } - , "repositories": [ - { - "type": "package" - , "package": { - "name": "guzzle/guzzle" - , "type": "library" - , "version": "v2.0.2" - , "autoload": { - "psr-0": { - "Guzzle": "src" - } - } - , "source": { - "url": "https://github.com/guzzle/guzzle.git" - , "type": "git" - , "reference": "ac64abc2c05b921efc4623379c1674a282475ae5" - } - } - } - ] } \ No newline at end of file diff --git a/composer.lock b/composer.lock index ffb54f4..184b061 100644 --- a/composer.lock +++ b/composer.lock @@ -1,9 +1,24 @@ { - "hash": "ccba37aea83a191c0846f8cdd9c57025", + "hash": "2e386d1cab16a0caaed00960707929ce", "packages": [ + { + "package": "doctrine/common", + "version": "2.2.x-dev", + "source-reference": "1e0aa60d109c630d19543d999f12e2852ef8f932" + }, { "package": "guzzle/guzzle", "version": "v2.0.2" + }, + { + "package": "symfony/event-dispatcher", + "version": "dev-master", + "source-reference": "07e1d0174f3a0ec36bbe04b3850270df7a86271d" + }, + { + "package": "symfony/validator", + "version": "dev-master", + "source-reference": "ce994a5616b20f6ebf37d66a1a89bdd3af6b4ea2" } ], "packages-dev": null, From e06aa30096274b16745cc502e0980078f86829ff Mon Sep 17 00:00:00 2001 From: Chris Boden Date: Sun, 22 Apr 2012 13:15:43 -0400 Subject: [PATCH 05/11] BC Break - Server::run parameters change Updated IoServerComponent::run parameters * $port is now first * only $port is required * SocketInterface is last and optional --- README.md | 8 ++++---- src/Ratchet/Component/Server/IOServerComponent.php | 12 +++++++++--- src/Ratchet/Resource/Socket/BSDSocket.php | 1 - .../Tests/Component/Server/IOServerComponentTest.php | 4 ++-- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 64be92c..3a60c10 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ A PHP 5.3 (PSR-0 compliant) component library for serving sockets and building socket based applications. Build up your application through simple interfaces using the decorator and command patterns. Re-use your application without changing any of its code just by combining different components. -Ratchet's primary intention is to be used as a WebSocket server (and a client in 0.6). +Ratchet's primary intention is to be used as a WebSocket server. ##WebSockets @@ -14,7 +14,7 @@ Ratchet's primary intention is to be used as a WebSocket server (and a client in ##Requirements -Shell access is required and a dedicated (virtual) machine with root access is recommended. +Shell access is required and a dedicated machine with root access is recommended. To avoid proxy/firewall blockage it's recommended WebSockets are run on port 80, which requires root access. Note that you can not run two applications (Apache and Ratchet) on the same port, thus the requirement for a separate machine (for now). @@ -28,7 +28,7 @@ See https://github.com/cboden/Ratchet-examples for some out-of-the-box working d Ideally, soon, web servers will start supporting WebSockets to some capacity and PHP will no longer need to run its self from the command line. In theory, the server (like Nginx) would recognize the HTTP handshake request to upgrade the protocol to WebSockets and run/pass data through to a user configured PHP file. When this happens, you can keep your script the same, just remove the IOServerComponent wrapper and maybe eventually the -WebSocket Application wrapper if the servers recognize the protocol message framing. +WebSocketComponent wrapper if the servers recognize the protocol message framing. --- @@ -86,7 +86,7 @@ class Chat implements MessageComponentInterface { } // Run the server application through the WebSocket protocol $server = new Server(new WebSocket(new Chat)); - $server->run(new Socket, '0.0.0.0', 80); + $server->run(80); ``` # php chat.php \ No newline at end of file diff --git a/src/Ratchet/Component/Server/IOServerComponent.php b/src/Ratchet/Component/Server/IOServerComponent.php index d292d57..d2dac8c 100644 --- a/src/Ratchet/Component/Server/IOServerComponent.php +++ b/src/Ratchet/Component/Server/IOServerComponent.php @@ -2,6 +2,7 @@ namespace Ratchet\Component\Server; use Ratchet\Component\MessageComponentInterface; use Ratchet\Resource\Socket\SocketInterface; +use Ratchet\Resource\Socket\BSDSocket; use Ratchet\Resource\ConnectionInterface; use Ratchet\Resource\Connection; use Ratchet\Resource\Command\CommandInterface; @@ -63,12 +64,17 @@ class IOServerComponent implements MessageComponentInterface { /* * Run the server infinitely - * @param Ratchet\Resource\Socket\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 (make sure to run as root if < 1000) + * @param mixed The address to listen for incoming connections on. "0.0.0.0" to listen from anywhere + * @param Ratchet\Resource\Socket\SocketInterface * @throws Ratchet\Exception */ - public function run(SocketInterface $host, $address = '127.0.0.1', $port = 1025) { + public function run($port, $address = '0.0.0.0', SocketInterface $host = null) { + if (null === $host) { + $host = new BSDSocket; + $host->set_option(SOL_SOCKET, SO_REUSEADDR, 1); + } + $this->_connections[$host->getResource()] = new Connection($host); $this->_resources[] = $host->getResource(); diff --git a/src/Ratchet/Resource/Socket/BSDSocket.php b/src/Ratchet/Resource/Socket/BSDSocket.php index 4e15730..353054a 100644 --- a/src/Ratchet/Resource/Socket/BSDSocket.php +++ b/src/Ratchet/Resource/Socket/BSDSocket.php @@ -237,7 +237,6 @@ class BSDSocket implements SocketInterface { $return = array(); foreach ($collection as $key => $socket) { -die("Checking if sock is instance of this: " . (int)($socket instanceof $this) . "\n"); $return[$key] = ($socket instanceof $this ? $socket->getResource() : $socket); } diff --git a/tests/Ratchet/Tests/Component/Server/IOServerComponentTest.php b/tests/Ratchet/Tests/Component/Server/IOServerComponentTest.php index 99b4cfc..8dd6798 100644 --- a/tests/Ratchet/Tests/Component/Server/IOServerComponentTest.php +++ b/tests/Ratchet/Tests/Component/Server/IOServerComponentTest.php @@ -37,7 +37,7 @@ class IOServerComponentTest extends \PHPUnit_Framework_TestCase { } public function testOnOpenPassesClonedSocket() { - $this->_server->run($this->_catalyst); + $this->_server->run(1025, '127.0.0.1', $this->_catalyst); $master = $this->getMasterConnection(); $this->_server->onOpen($master); @@ -47,7 +47,7 @@ class IOServerComponentTest extends \PHPUnit_Framework_TestCase { } public function testOnMessageSendsToApp() { - $this->_server->run($this->_catalyst); + $this->_server->run(1025, '127.0.0.1', $this->_catalyst); $master = $this->getMasterConnection(); // todo, make FakeSocket better, set data in select, recv to pass data when called, then do this check From 3908a69741b7884d78b38477b7427d3fe08e2cc4 Mon Sep 17 00:00:00 2001 From: Chris Boden Date: Wed, 25 Apr 2012 20:50:07 -0400 Subject: [PATCH 06/11] Cleanup --- README.md | 8 ++++---- composer.json | 3 ++- src/Ratchet/Component/Client/App.php | 0 3 files changed, 6 insertions(+), 5 deletions(-) delete mode 100644 src/Ratchet/Component/Client/App.php diff --git a/README.md b/README.md index 3a60c10..523457b 100644 --- a/README.md +++ b/README.md @@ -39,9 +39,8 @@ WebSocketComponent wrapper if the servers recognize the protocol message framing namespace MyApps; use Ratchet\Component\MessageComponentInterface; use Ratchet\Resource\ConnectionInterface; -use Ratchet\Resource\Socket\BSDSocket as Socket; -use Ratchet\Component\Server\IOServerComponent as Server; -use Ratchet\Component\WebSocket\WebSocketComponent as WebSocket; +use Ratchet\Component\Server\IOServerComponent; +use Ratchet\Component\WebSocket\WebSocketComponent; use Ratchet\Resource\Command\Composite as Cmds; use Ratchet\Resource\Command\Action\SendMessage; use Ratchet\Resource\Command\Action\CloseConnection; @@ -84,8 +83,9 @@ class Chat implements MessageComponentInterface { return new CloseConnection($conn); } } + // Run the server application through the WebSocket protocol - $server = new Server(new WebSocket(new Chat)); + $server = new IOServerComponent(new WebSocketComponent(new Chat)); $server->run(80); ``` diff --git a/composer.json b/composer.json index 137e81d..0897e66 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,8 @@ "name": "cboden/Ratchet" , "type": "library" , "description": "PHP WebSocket server component library" - , "keywords": ["WebSocket", "Server"] + , "keywords": ["WebSockets", "Server", "Ratchet", "Sockets"] + , "website": "http://socketo.me" , "repository": "https://github.com/cboden/Ratchet" , "license": "MIT" , "authors": [ diff --git a/src/Ratchet/Component/Client/App.php b/src/Ratchet/Component/Client/App.php deleted file mode 100644 index e69de29..0000000 From 01ccbcf8c81a75cd275451424dd1b0c692031125 Mon Sep 17 00:00:00 2001 From: Chris Boden Date: Wed, 25 Apr 2012 21:00:08 -0400 Subject: [PATCH 07/11] Fixed inheritdoc syntax --- src/Ratchet/Component/Server/IOServerComponent.php | 8 ++++---- src/Ratchet/Component/WebSocket/WebSocketComponent.php | 2 +- src/Ratchet/Resource/Command/Action/Runtime.php | 2 +- src/Ratchet/Resource/Command/Action/SendMessage.php | 2 +- src/Ratchet/Resource/Command/Composite.php | 2 +- src/Ratchet/Resource/Connection.php | 8 ++++---- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Ratchet/Component/Server/IOServerComponent.php b/src/Ratchet/Component/Server/IOServerComponent.php index d2dac8c..f328647 100644 --- a/src/Ratchet/Component/Server/IOServerComponent.php +++ b/src/Ratchet/Component/Server/IOServerComponent.php @@ -154,7 +154,7 @@ class IOServerComponent implements MessageComponentInterface { } /** - * @{inheritdoc} + * {@inheritdoc} */ public function onOpen(ConnectionInterface $conn) { $new_socket = clone $conn->getSocket(); @@ -168,14 +168,14 @@ class IOServerComponent implements MessageComponentInterface { } /** - * @{inheritdoc} + * {@inheritdoc} */ public function onMessage(ConnectionInterface $from, $msg) { return $this->_decorating->onMessage($from, $msg); } /** - * @{inheritdoc} + * {@inheritdoc} */ public function onClose(ConnectionInterface $conn) { $resource = $conn->getSocket()->getResource(); @@ -188,7 +188,7 @@ class IOServerComponent implements MessageComponentInterface { } /** - * @{inheritdoc} + * {@inheritdoc} */ public function onError(ConnectionInterface $conn, \Exception $e) { return $this->_decorating->onError($conn, $e); diff --git a/src/Ratchet/Component/WebSocket/WebSocketComponent.php b/src/Ratchet/Component/WebSocket/WebSocketComponent.php index 454128d..a2267fd 100644 --- a/src/Ratchet/Component/WebSocket/WebSocketComponent.php +++ b/src/Ratchet/Component/WebSocket/WebSocketComponent.php @@ -52,7 +52,7 @@ class WebSocketComponent implements MessageComponentInterface { } /** - * @{inheritdoc} + * {@inheritdoc} */ public function onOpen(ConnectionInterface $conn) { $conn->WebSocket = new \stdClass; diff --git a/src/Ratchet/Resource/Command/Action/Runtime.php b/src/Ratchet/Resource/Command/Action/Runtime.php index 4211054..17ccd17 100644 --- a/src/Ratchet/Resource/Command/Action/Runtime.php +++ b/src/Ratchet/Resource/Command/Action/Runtime.php @@ -21,7 +21,7 @@ class Runtime extends ActionTemplate { } /** - * @{inheritdoc} + * {@inheritdoc} */ public function execute(ComponentInterface $scope = null) { $cmd = $this->_command; diff --git a/src/Ratchet/Resource/Command/Action/SendMessage.php b/src/Ratchet/Resource/Command/Action/SendMessage.php index 8a9bc84..3eca5fe 100644 --- a/src/Ratchet/Resource/Command/Action/SendMessage.php +++ b/src/Ratchet/Resource/Command/Action/SendMessage.php @@ -30,7 +30,7 @@ class SendMessage extends ActionTemplate { } /** - * @{inheritdoc} + * {@inheritdoc} * @throws \UnexpectedValueException if a message was not set with setMessage() */ public function execute(ComponentInterface $scope = null) { diff --git a/src/Ratchet/Resource/Command/Composite.php b/src/Ratchet/Resource/Command/Composite.php index be44815..1a0f8d3 100644 --- a/src/Ratchet/Resource/Command/Composite.php +++ b/src/Ratchet/Resource/Command/Composite.php @@ -23,7 +23,7 @@ class Composite extends \SplQueue implements CommandInterface { } /** - * @{inheritdoc} + * {@inheritdoc} */ public function execute(ComponentInterface $scope = null) { $this->setIteratorMode(static::IT_MODE_DELETE); diff --git a/src/Ratchet/Resource/Connection.php b/src/Ratchet/Resource/Connection.php index 5d5e015..e15eaa9 100644 --- a/src/Ratchet/Resource/Connection.php +++ b/src/Ratchet/Resource/Connection.php @@ -37,14 +37,14 @@ class Connection implements ConnectionInterface { } /** - * @{inheritdoc} + * {@inheritdoc} */ public function __set($name, $value) { $this->_data[$name] = $value; } /** - * @{inheritdoc} + * {@inheritdoc} */ public function __get($name) { if (!$this->__isset($name)) { @@ -59,14 +59,14 @@ class Connection implements ConnectionInterface { } /** - * @{inheritdoc} + * {@inheritdoc} */ public function __isset($name) { return isset($this->_data[$name]); } /** - * @{inheritdoc} + * {@inheritdoc} */ public function __unset($name) { unset($this->_data[$name]); From dd79245ecf3cb6a6260fc93922d78f5c16639a89 Mon Sep 17 00:00:00 2001 From: Chris Boden Date: Wed, 25 Apr 2012 21:58:12 -0400 Subject: [PATCH 08/11] Simplified Removed magic methods from Connection(Interface) Connection is closer to a POPO now --- composer.lock | 6 +-- src/Ratchet/Resource/Connection.php | 38 ------------------- src/Ratchet/Resource/ConnectionInterface.php | 26 ------------- .../Ratchet/Tests/Resource/ConnectionTest.php | 25 ------------ tests/bootstrap.php | 2 +- 5 files changed, 4 insertions(+), 93 deletions(-) diff --git a/composer.lock b/composer.lock index 184b061..4018db3 100644 --- a/composer.lock +++ b/composer.lock @@ -1,5 +1,5 @@ { - "hash": "2e386d1cab16a0caaed00960707929ce", + "hash": "bd52a853cdf4e34ae75e805f32ed97ae", "packages": [ { "package": "doctrine/common", @@ -13,12 +13,12 @@ { "package": "symfony/event-dispatcher", "version": "dev-master", - "source-reference": "07e1d0174f3a0ec36bbe04b3850270df7a86271d" + "source-reference": "b98d68d3b8513c62d35504570f09e9d3dc33d083" }, { "package": "symfony/validator", "version": "dev-master", - "source-reference": "ce994a5616b20f6ebf37d66a1a89bdd3af6b4ea2" + "source-reference": "53ec97264f909d29ae01665e8345f8fb763b94f3" } ], "packages-dev": null, diff --git a/src/Ratchet/Resource/Connection.php b/src/Ratchet/Resource/Connection.php index e15eaa9..df2c5c4 100644 --- a/src/Ratchet/Resource/Connection.php +++ b/src/Ratchet/Resource/Connection.php @@ -7,8 +7,6 @@ use Ratchet\Resource\Socket\SocketInterface; * This acts as a container to storm data (in memory) about the connection */ class Connection implements ConnectionInterface { - protected $_data = array(); - /** * @var Ratchet\Resource\Socket\SocketInterface */ @@ -35,40 +33,4 @@ class Connection implements ConnectionInterface { public function getSocket() { return $this->_socket; } - - /** - * {@inheritdoc} - */ - public function __set($name, $value) { - $this->_data[$name] = $value; - } - - /** - * {@inheritdoc} - */ - public function __get($name) { - if (!$this->__isset($name)) { - throw new \InvalidArgumentException("Attribute '{$name}' not found in Connection {$this->getID()}"); - } - - if (is_callable($this->_data[$name])) { - return $this->_data[$name]($this); - } else { - return $this->_data[$name]; - } - } - - /** - * {@inheritdoc} - */ - public function __isset($name) { - return isset($this->_data[$name]); - } - - /** - * {@inheritdoc} - */ - public function __unset($name) { - unset($this->_data[$name]); - } } \ No newline at end of file diff --git a/src/Ratchet/Resource/ConnectionInterface.php b/src/Ratchet/Resource/ConnectionInterface.php index ed9ad9e..6b0608c 100644 --- a/src/Ratchet/Resource/ConnectionInterface.php +++ b/src/Ratchet/Resource/ConnectionInterface.php @@ -6,30 +6,4 @@ interface ConnectionInterface { * @return int */ function getId(); - - - /** - * Set an attribute to the connection - * @param mixed - * @param mixed - */ - function __set($name, $value); - - /** - * Get a previously set attribute bound to the connection - * @return mixed - * @throws \InvalidArgumentException - */ - function __get($name); - - /** - * @param mixed - * @return bool - */ - function __isset($name); - - /** - * @param mixed - */ - function __unset($name); } \ No newline at end of file diff --git a/tests/Ratchet/Tests/Resource/ConnectionTest.php b/tests/Ratchet/Tests/Resource/ConnectionTest.php index 375c09c..97c3994 100644 --- a/tests/Ratchet/Tests/Resource/ConnectionTest.php +++ b/tests/Ratchet/Tests/Resource/ConnectionTest.php @@ -43,31 +43,6 @@ class ConnectionTest extends \PHPUnit_Framework_TestCase { $this->assertEquals($val, $this->_c->{$key}); } - public function testExceptionThrownOnInvalidGet() { - $this->setExpectedException('InvalidArgumentException'); - $ret = $this->_c->faked; - } - - public static function lambdaProvider() { - return array( - array('hello', 'world') - , array('obj', new \stdClass) - , array('arr', array()) - ); - } - - /** - * @dataProvider lambdaProvider - */ - public function testLambdaReturnValueOnGet($key, $val) { - $fn = function() use ($val) { - return $val; - }; - - $this->_c->{$key} = $fn; - $this->assertSame($val, $this->_c->{$key}); - } - /** * @dataProvider keyAndValProvider */ diff --git a/tests/bootstrap.php b/tests/bootstrap.php index f814127..9c15fdc 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -2,4 +2,4 @@ error_reporting(E_ALL | E_STRICT); - require_once dirname(__DIR__) . '/vendor/.composer/autoload.php'; \ No newline at end of file + require_once dirname(__DIR__) . '/vendor/autoload.php'; \ No newline at end of file From aa51ea53f9374a79d6fe1db62ff3a3974bb7a7a9 Mon Sep 17 00:00:00 2001 From: Chris Boden Date: Wed, 25 Apr 2012 22:15:06 -0400 Subject: [PATCH 09/11] IO adds remoteAddress to Connection --- src/Ratchet/Component/Server/IOServerComponent.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Ratchet/Component/Server/IOServerComponent.php b/src/Ratchet/Component/Server/IOServerComponent.php index f328647..e207540 100644 --- a/src/Ratchet/Component/Server/IOServerComponent.php +++ b/src/Ratchet/Component/Server/IOServerComponent.php @@ -161,6 +161,8 @@ class IOServerComponent implements MessageComponentInterface { $new_socket->set_nonblock(); $new_connection = new Connection($new_socket); + $new_connection->remoteAddress = $new_socket->getRemoteAddress(); + $this->_resources[] = $new_connection->getSocket()->getResource(); $this->_connections[$new_connection->getSocket()->getResource()] = $new_connection; From f98cda3e298c6450ffcf420ccc94b7b087f9fa1b Mon Sep 17 00:00:00 2001 From: Chris Boden Date: Wed, 25 Apr 2012 22:22:49 -0400 Subject: [PATCH 10/11] Fixed unit test namespace --- tests/Ratchet/Tests/Component/Server/IOServerComponentTest.php | 2 +- tests/Ratchet/Tests/Component/WebSocket/Version/Hixie76Test.php | 2 +- tests/Ratchet/Tests/Component/WebSocket/Version/HyBi10Test.php | 2 +- .../Tests/Component/WebSocket/Version/RFC6455/FrameTest.php | 2 +- .../WebSocket/Version/RFC6455/HandshakeVerifierTest.php | 2 +- tests/Ratchet/Tests/Component/WebSocket/Version/RFC6455Test.php | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/Ratchet/Tests/Component/Server/IOServerComponentTest.php b/tests/Ratchet/Tests/Component/Server/IOServerComponentTest.php index 8dd6798..5a03df0 100644 --- a/tests/Ratchet/Tests/Component/Server/IOServerComponentTest.php +++ b/tests/Ratchet/Tests/Component/Server/IOServerComponentTest.php @@ -1,5 +1,5 @@ Date: Wed, 25 Apr 2012 22:59:46 -0400 Subject: [PATCH 11/11] Replaced Connection::getId() with resourceId property --- src/Ratchet/Component/Server/IOServerComponent.php | 1 + src/Ratchet/Resource/Connection.php | 7 ------- src/Ratchet/Resource/ConnectionInterface.php | 4 ---- .../Tests/Component/Server/IOServerComponentTest.php | 2 +- tests/Ratchet/Tests/Mock/FakeSocket.php | 2 +- 5 files changed, 3 insertions(+), 13 deletions(-) diff --git a/src/Ratchet/Component/Server/IOServerComponent.php b/src/Ratchet/Component/Server/IOServerComponent.php index e207540..15bb5f5 100644 --- a/src/Ratchet/Component/Server/IOServerComponent.php +++ b/src/Ratchet/Component/Server/IOServerComponent.php @@ -162,6 +162,7 @@ class IOServerComponent implements MessageComponentInterface { $new_connection = new Connection($new_socket); $new_connection->remoteAddress = $new_socket->getRemoteAddress(); + $new_connection->resourceId = (int)substr((string)$new_socket->getResource(), strrpos((string)$new_socket->getResource(), '#') + 1); $this->_resources[] = $new_connection->getSocket()->getResource(); $this->_connections[$new_connection->getSocket()->getResource()] = $new_connection; diff --git a/src/Ratchet/Resource/Connection.php b/src/Ratchet/Resource/Connection.php index df2c5c4..4f1485c 100644 --- a/src/Ratchet/Resource/Connection.php +++ b/src/Ratchet/Resource/Connection.php @@ -16,13 +16,6 @@ class Connection implements ConnectionInterface { $this->_socket = $socket; } - /** - * @return int - */ - public function getID() { - return (int)(string)$this->_socket; - } - /** * This is here because I couldn't figure out a better/easier way to tie a connection and socket together for the server and commands * Anyway, if you're here, it's not recommended you use this/directly interact with the socket in your App... diff --git a/src/Ratchet/Resource/ConnectionInterface.php b/src/Ratchet/Resource/ConnectionInterface.php index 6b0608c..93dd516 100644 --- a/src/Ratchet/Resource/ConnectionInterface.php +++ b/src/Ratchet/Resource/ConnectionInterface.php @@ -2,8 +2,4 @@ namespace Ratchet\Resource; interface ConnectionInterface { - /** - * @return int - */ - function getId(); } \ No newline at end of file diff --git a/tests/Ratchet/Tests/Component/Server/IOServerComponentTest.php b/tests/Ratchet/Tests/Component/Server/IOServerComponentTest.php index 5a03df0..f0a3389 100644 --- a/tests/Ratchet/Tests/Component/Server/IOServerComponentTest.php +++ b/tests/Ratchet/Tests/Component/Server/IOServerComponentTest.php @@ -43,7 +43,7 @@ class IOServerComponentTest extends \PHPUnit_Framework_TestCase { $this->_server->onOpen($master); $clone = $this->_decorated->_conn_open; - $this->assertEquals($master->getID() + 1, $clone->getID()); + $this->assertEquals($master->resourceId + 1, $clone->resourceId); } public function testOnMessageSendsToApp() { diff --git a/tests/Ratchet/Tests/Mock/FakeSocket.php b/tests/Ratchet/Tests/Mock/FakeSocket.php index f547238..1ef7e63 100644 --- a/tests/Ratchet/Tests/Mock/FakeSocket.php +++ b/tests/Ratchet/Tests/Mock/FakeSocket.php @@ -12,7 +12,7 @@ class FakeSocket implements SocketInterface { public $_last = array(); public function getResource() { - return null; + return "#{$this->_id}"; } public function __toString() {