From ec607090d67f068daa9bc18ebac6683552c28b9c Mon Sep 17 00:00:00 2001 From: Chris Boden Date: Mon, 14 Nov 2011 17:05:25 -0500 Subject: [PATCH] Wrapped WebSocket connection data in object Trying to prevent accidental parameter clobbering --- lib/Ratchet/Application/WebSocket/App.php | 18 +++++++++--------- lib/Ratchet/Resource/Connection.php | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/Ratchet/Application/WebSocket/App.php b/lib/Ratchet/Application/WebSocket/App.php index cb4938c..31f633b 100644 --- a/lib/Ratchet/Application/WebSocket/App.php +++ b/lib/Ratchet/Application/WebSocket/App.php @@ -11,7 +11,6 @@ use Ratchet\Application\WebSocket\Util\HTTP; /** * The adapter to handle WebSocket requests/responses * This is a mediator between the Server and your application to handle real-time messaging through a web browser - * Sets 2 parameters on a Connection: handhsake_complete (bool) and websocket_version (Version\VersionInterface) * @link http://ca.php.net/manual/en/ref.http.php * @todo Make sure this works both ways (client/server) as stack needs to exist on client for framing * @todo Learn about closing the socket. A message has to be sent prior to closing - does the message get sent onClose event or CloseConnection command? @@ -40,7 +39,7 @@ class App implements ApplicationInterface, ConfiguratorInterface { public function __construct(ApplicationInterface $app = null) { if (null === $app) { - throw new \UnexpectedValueException("WebSocket requires an application to run off of"); + throw new \UnexpectedValueException("WebSocket requires an application to run"); } $this->_app = $app; @@ -62,17 +61,18 @@ class App implements ApplicationInterface, ConfiguratorInterface { } public function onOpen(Connection $conn) { - $conn->handshake_complete = false; + $conn->WebSocket = new \stdClass; + $conn->WebSocket->handshake = false; } public function onRecv(Connection $from, $msg) { - if (true !== $from->handshake_complete) { + if (true !== $from->WebSocket->handshake) { // need buffer checks in here - $from->websocket_version = $this->getVersion($msg); - $response = $from->websocket_version->handshake($msg); - $from->handshake_complete = true; + $from->WebSocket->version = $this->getVersion($msg); + $response = $from->WebSocket->version->handshake($msg); + $from->WebSocket->handshake = true; if (is_array($response)) { $header = ''; @@ -97,7 +97,7 @@ class App implements ApplicationInterface, ConfiguratorInterface { // buffer! - $msg = $from->websocket_version->unframe($msg); + $msg = $from->WebSocket->version->unframe($msg); if (is_array($msg)) { // temporary $msg = $msg['payload']; } @@ -126,7 +126,7 @@ class App implements ApplicationInterface, ConfiguratorInterface { */ protected function prepareCommand(CommandInterface $command = null) { if ($command instanceof SendMessage) { - $version = $command->getConnection()->websocket_version; + $version = $command->getConnection()->WebSocket->version; return $command->setMessage($version->frame($command->getMessage())); } diff --git a/lib/Ratchet/Resource/Connection.php b/lib/Ratchet/Resource/Connection.php index 7ffa464..64592cb 100644 --- a/lib/Ratchet/Resource/Connection.php +++ b/lib/Ratchet/Resource/Connection.php @@ -49,7 +49,7 @@ class Connection { * @return mixed * @throws \InvalidArgumentException */ - public function __get($name) { + public function &__get($name) { if (!isset($this->_data[$name])) { throw new \InvalidArgumentException("Attribute '{$name}' not found in Connection {$this->getID()}"); }