diff --git a/lib/Ratchet/Logging/LoggerInterface.php b/lib/Ratchet/Logging/LoggerInterface.php deleted file mode 100644 index 4b8020d..0000000 --- a/lib/Ratchet/Logging/LoggerInterface.php +++ /dev/null @@ -1,25 +0,0 @@ -<?php -namespace Ratchet\Logging; - -/** - * A logger used by the server and extending applications for debugging info - */ -interface LoggerInterface { - /** - * Just an informational log - * @param string - */ - function note($msg); - - /** - * A problem, but nothing too serious - * @param string - */ - function warning($msg); - - /** - * Bad things have happened... - * @param string - */ - function error($msg); -} \ No newline at end of file diff --git a/lib/Ratchet/Logging/MonologAdapter.php b/lib/Ratchet/Logging/MonologAdapter.php deleted file mode 100644 index 8339de4..0000000 --- a/lib/Ratchet/Logging/MonologAdapter.php +++ /dev/null @@ -1,32 +0,0 @@ -<?php -namespace Ratchet\Logging; -use Monolog\Logger; - -/** - * Adapt the awesome Monolog Logger into the lowly Ratchet Logger - */ -class MonologAdapter extends Logger implements LoggerInterface { - /** - * Maps to Monolog\Logger::addInfo - * @param string - */ - function note($msg) { - $this->addInfo($msg); - } - - /** - * Maps to Monolog\Logger::addWarning - * @param string - */ - function warning($msg) { - $this->addWarning($msg); - } - - /** - * Maps to Monolog\Logger::addError - * @param string - */ - function error($msg) { - $this->addError($msg); - } -} \ No newline at end of file diff --git a/lib/Ratchet/Logging/NullLogger.php b/lib/Ratchet/Logging/NullLogger.php deleted file mode 100644 index 78c4f9b..0000000 --- a/lib/Ratchet/Logging/NullLogger.php +++ /dev/null @@ -1,17 +0,0 @@ -<?php -namespace Ratchet\Logging; - -/** - * Sends all logs into the void - * No one can hear you scream in /dev/null - */ -class NullLogger implements LoggerInterface { - function note($msg) { - } - - function warning($msg) { - } - - function error($msg) { - } -} \ No newline at end of file diff --git a/lib/Ratchet/Protocol/WebSocket.php b/lib/Ratchet/Protocol/WebSocket.php index f294e12..fd91718 100644 --- a/lib/Ratchet/Protocol/WebSocket.php +++ b/lib/Ratchet/Protocol/WebSocket.php @@ -17,6 +17,7 @@ use Ratchet\Protocol\WebSocket\Util\HTTP; * @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? * @todo Consider cheating the application...don't call _app::onOpen until handshake is complete - only issue is sending headers/cookies * @todo Consider chaning this class to a State Pattern. If a SocketObserver is passed in __construct, do what is there now. If it's an AppInterface change behaviour of socket interaction (onOpen, handshake, etc) + * @todo Change namespace to Ratchet\Protocol\WebSocket\Adapter */ class WebSocket implements ProtocolInterface { /** diff --git a/lib/Ratchet/Protocol/WebSocket/Version/HyBi10.php b/lib/Ratchet/Protocol/WebSocket/Version/HyBi10.php index b56b550..c0e1000 100644 --- a/lib/Ratchet/Protocol/WebSocket/Version/HyBi10.php +++ b/lib/Ratchet/Protocol/WebSocket/Version/HyBi10.php @@ -74,7 +74,7 @@ class HyBi10 implements VersionInterface { default: // Close connection on unknown opcode: - throw new \UnexpectedValueException('Unknown opcode'); + throw new \UnexpectedValueException("Unknown opcode ({$opcode})"); break; } diff --git a/lib/Ratchet/Server.php b/lib/Ratchet/Server.php index 78ccbbd..d15caab 100644 --- a/lib/Ratchet/Server.php +++ b/lib/Ratchet/Server.php @@ -2,8 +2,6 @@ namespace Ratchet; use Ratchet\Server\Aggregator; use Ratchet\Protocol\ProtocolInterface; -use Ratchet\Logging\LoggerInterface; -use Ratchet\Logging\NullLogger; use Ratchet\Command\CommandInterface; /** @@ -21,18 +19,13 @@ class Server implements SocketObserver, \IteratorAggregate { /** * @var array of Socket Resources */ - protected $_resources = array(); + protected $_resources = array(); /** * @var ArrayIterator of Resouces (Socket type) as keys, Ratchet\Socket as values */ protected $_connections; - /** - * @type Logging\LoggerInterface; - */ - protected $_log; - /** * @var SocketObserver * Maybe temporary? @@ -42,18 +35,12 @@ class Server implements SocketObserver, \IteratorAggregate { /** * @param Ratchet\Socket * @param SocketObserver - * @param Logging\LoggerInterface */ - public function __construct(SocketInterface $host, SocketObserver $application, LoggerInterface $logger = null) { + public function __construct(SocketInterface $host, SocketObserver $application) { $this->_master = $host; $socket = $host->getResource(); $this->_resources[] = $socket; - if (null === $logger) { - $logger = new NullLogger; - } - $this->_log = $logger; - $this->_connections = new \ArrayIterator(array()); $this->_app = $application; @@ -61,6 +48,7 @@ class Server implements SocketObserver, \IteratorAggregate { /** * @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; @@ -114,7 +102,6 @@ class Server implements SocketObserver, \IteratorAggregate { } } catch (Exception $se) { // Instead of logging error, will probably add/trigger onIOError/onError or something in SocketObserver - $this->_log->error($se->getCode() . ' - ' . $se->getMessage()); // temporary, move to application if ($se->getCode() != 35) { @@ -122,7 +109,8 @@ class Server implements SocketObserver, \IteratorAggregate { $close->execute($this); } } catch (\Exception $e) { - $this->_log->error('Big uh oh: ' . $e->getMessage()); + // onError() - but can I determine which is/was the target Socket that threw the exception...? + // $conn->close() ??? } } while (true); } @@ -132,14 +120,10 @@ class Server implements SocketObserver, \IteratorAggregate { $this->_resources[] = $new_connection->getResource(); $this->_connections[$new_connection->getResource()] = $new_connection; - $this->_log->note('New connection, ' . count($this->_connections) . ' total'); - return $this->_app->onOpen($new_connection); } public function onRecv(SocketInterface $from, $msg) { -// $this->_log->note('New message "' . trim($msg) . '"'); - return $this->_app->onRecv($from, $msg); } @@ -151,8 +135,6 @@ class Server implements SocketObserver, \IteratorAggregate { unset($this->_connections[$resource]); unset($this->_resources[array_search($resource, $this->_resources)]); - $this->_log->note('Connection closed, ' . count($this->_connections) . ' connections remain'); - return $cmd; } } \ No newline at end of file diff --git a/lib/Ratchet/SocketObserver.php b/lib/Ratchet/SocketObserver.php index bbb1591..f4214da 100644 --- a/lib/Ratchet/SocketObserver.php +++ b/lib/Ratchet/SocketObserver.php @@ -5,6 +5,7 @@ namespace Ratchet; * Observable/Observer design pattern interface for handing events on a socket * @todo Consider an onException method. Since server is running its own loop the app currently doesn't know when a problem is handled * @todo Consider an onDisconnect method for a server-side close()'ing of a connection - onClose would be client side close() + * @todo Consider adding __construct(SocketObserver $decorator = null) - on Server move Socket as parameter to run() */ interface SocketObserver { /** diff --git a/tests/Ratchet/Tests/Logging/NullLoggerTest.php b/tests/Ratchet/Tests/Logging/NullLoggerTest.php deleted file mode 100644 index c46d2d4..0000000 --- a/tests/Ratchet/Tests/Logging/NullLoggerTest.php +++ /dev/null @@ -1,30 +0,0 @@ -<?php -namespace Ratchet\Tests\Logging; -use Ratchet\Logging\NullLogger; - -/** - * @covers Ratchet\Logging\NullLogger - */ -class NullLoggerTest extends \PHPUnit_Framework_TestCase { - protected $_log; - - public function setUp() { - $this->_log = new NullLogger; - } - - public function testInterface() { - $this->assertInstanceOf('\\Ratchet\\Logging\\LoggerInterface', $this->_log); - } - - public function testNoteDoesNothing() { - $this->assertNull($this->_log->note('hi')); - } - - public function testWarningDoesNothing() { - $this->assertNull($this->_log->warning('hi')); - } - - public function testErrorDoesNothing() { - $this->assertNull($this->_log->error('hi')); - } -} \ No newline at end of file diff --git a/tests/Ratchet/Tests/Mock/ArrayLogger.php b/tests/Ratchet/Tests/Mock/ArrayLogger.php deleted file mode 100644 index 5b047a5..0000000 --- a/tests/Ratchet/Tests/Mock/ArrayLogger.php +++ /dev/null @@ -1,19 +0,0 @@ -<?php -namespace Ratchet\Tests\Mock; -use Ratchet\Logging\LoggerInterface; - -class ArrayLogger implements LoggerInterface { - public $last_msg = ''; - - public function note($msg) { - $this->last_msg = $msg; - } - - public function warning($msg) { - $this->last_msg = $msg; - } - - public function error($msg) { - $this->last_msg = $msg; - } -} \ No newline at end of file diff --git a/tests/Ratchet/Tests/ServerTest.php b/tests/Ratchet/Tests/ServerTest.php index 1f7ea82..9111364 100644 --- a/tests/Ratchet/Tests/ServerTest.php +++ b/tests/Ratchet/Tests/ServerTest.php @@ -3,7 +3,6 @@ namespace Ratchet\Tests; use Ratchet\Server; use Ratchet\Tests\Mock\FakeSocket as Socket; use Ratchet\Tests\Mock\Application as TestApp; -use Ratchet\Tests\Mock\ArrayLogger; /** * @covers Ratchet\Server @@ -32,32 +31,6 @@ class ServerTest extends \PHPUnit_Framework_TestCase { $this->assertThat($this->_server, $constraint); } - public function testNullLoggerIsSetInConstruct() { - $this->assertInstanceOf('\\Ratchet\\Logging\\LoggerInterface', $this->getPrivateProperty($this->_server, '_log')); - } - - public function testPassedLoggerIsSetInConstruct() { - $logger = new ArrayLogger; - $server = new Server(new Socket(), $this->_app, $logger); - - $this->assertSame($logger, $this->getPrivateProperty($server, '_log')); - } - -/* - public function testLoggerIsSetInMethod() { - $logger = new ArrayLogger; - $this->_server->setLogger($logger); - - $this->assertSame($logger, $this->getPrivateProperty($this->_server, '_log')); - } -*/ - -/* - public function testGetMasterReturnsCatalyst() { - $this->assertSame($this->_catalyst, $this->_server->getMaster()); - } -*/ - public function testIteration() { $this->assertInstanceOf('\\Iterator', $this->_server->getIterator()); }