Removed Logging
Removed logging - use Decorator as replacement (https://raw.github.com/cboden/RatchetApps/master/lib/RatchetApps/Logger.php)
This commit is contained in:
parent
cf3ba7c4ad
commit
bf0787b7cd
@ -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);
|
|
||||||
}
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
@ -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) {
|
|
||||||
}
|
|
||||||
}
|
|
@ -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 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 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 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 {
|
class WebSocket implements ProtocolInterface {
|
||||||
/**
|
/**
|
||||||
|
@ -74,7 +74,7 @@ class HyBi10 implements VersionInterface {
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
// Close connection on unknown opcode:
|
// Close connection on unknown opcode:
|
||||||
throw new \UnexpectedValueException('Unknown opcode');
|
throw new \UnexpectedValueException("Unknown opcode ({$opcode})");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
namespace Ratchet;
|
namespace Ratchet;
|
||||||
use Ratchet\Server\Aggregator;
|
use Ratchet\Server\Aggregator;
|
||||||
use Ratchet\Protocol\ProtocolInterface;
|
use Ratchet\Protocol\ProtocolInterface;
|
||||||
use Ratchet\Logging\LoggerInterface;
|
|
||||||
use Ratchet\Logging\NullLogger;
|
|
||||||
use Ratchet\Command\CommandInterface;
|
use Ratchet\Command\CommandInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -21,18 +19,13 @@ class Server implements SocketObserver, \IteratorAggregate {
|
|||||||
/**
|
/**
|
||||||
* @var array of Socket Resources
|
* @var array of Socket Resources
|
||||||
*/
|
*/
|
||||||
protected $_resources = array();
|
protected $_resources = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var ArrayIterator of Resouces (Socket type) as keys, Ratchet\Socket as values
|
* @var ArrayIterator of Resouces (Socket type) as keys, Ratchet\Socket as values
|
||||||
*/
|
*/
|
||||||
protected $_connections;
|
protected $_connections;
|
||||||
|
|
||||||
/**
|
|
||||||
* @type Logging\LoggerInterface;
|
|
||||||
*/
|
|
||||||
protected $_log;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var SocketObserver
|
* @var SocketObserver
|
||||||
* Maybe temporary?
|
* Maybe temporary?
|
||||||
@ -42,18 +35,12 @@ class Server implements SocketObserver, \IteratorAggregate {
|
|||||||
/**
|
/**
|
||||||
* @param Ratchet\Socket
|
* @param Ratchet\Socket
|
||||||
* @param SocketObserver
|
* @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;
|
$this->_master = $host;
|
||||||
$socket = $host->getResource();
|
$socket = $host->getResource();
|
||||||
$this->_resources[] = $socket;
|
$this->_resources[] = $socket;
|
||||||
|
|
||||||
if (null === $logger) {
|
|
||||||
$logger = new NullLogger;
|
|
||||||
}
|
|
||||||
$this->_log = $logger;
|
|
||||||
|
|
||||||
$this->_connections = new \ArrayIterator(array());
|
$this->_connections = new \ArrayIterator(array());
|
||||||
|
|
||||||
$this->_app = $application;
|
$this->_app = $application;
|
||||||
@ -61,6 +48,7 @@ class Server implements SocketObserver, \IteratorAggregate {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return ArrayIterator of SocketInterfaces
|
* @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() {
|
public function getIterator() {
|
||||||
return $this->_connections;
|
return $this->_connections;
|
||||||
@ -114,7 +102,6 @@ class Server implements SocketObserver, \IteratorAggregate {
|
|||||||
}
|
}
|
||||||
} catch (Exception $se) {
|
} catch (Exception $se) {
|
||||||
// Instead of logging error, will probably add/trigger onIOError/onError or something in SocketObserver
|
// 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
|
// temporary, move to application
|
||||||
if ($se->getCode() != 35) {
|
if ($se->getCode() != 35) {
|
||||||
@ -122,7 +109,8 @@ class Server implements SocketObserver, \IteratorAggregate {
|
|||||||
$close->execute($this);
|
$close->execute($this);
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} 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);
|
} while (true);
|
||||||
}
|
}
|
||||||
@ -132,14 +120,10 @@ class Server implements SocketObserver, \IteratorAggregate {
|
|||||||
$this->_resources[] = $new_connection->getResource();
|
$this->_resources[] = $new_connection->getResource();
|
||||||
$this->_connections[$new_connection->getResource()] = $new_connection;
|
$this->_connections[$new_connection->getResource()] = $new_connection;
|
||||||
|
|
||||||
$this->_log->note('New connection, ' . count($this->_connections) . ' total');
|
|
||||||
|
|
||||||
return $this->_app->onOpen($new_connection);
|
return $this->_app->onOpen($new_connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onRecv(SocketInterface $from, $msg) {
|
public function onRecv(SocketInterface $from, $msg) {
|
||||||
// $this->_log->note('New message "' . trim($msg) . '"');
|
|
||||||
|
|
||||||
return $this->_app->onRecv($from, $msg);
|
return $this->_app->onRecv($from, $msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,8 +135,6 @@ class Server implements SocketObserver, \IteratorAggregate {
|
|||||||
unset($this->_connections[$resource]);
|
unset($this->_connections[$resource]);
|
||||||
unset($this->_resources[array_search($resource, $this->_resources)]);
|
unset($this->_resources[array_search($resource, $this->_resources)]);
|
||||||
|
|
||||||
$this->_log->note('Connection closed, ' . count($this->_connections) . ' connections remain');
|
|
||||||
|
|
||||||
return $cmd;
|
return $cmd;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -5,6 +5,7 @@ namespace Ratchet;
|
|||||||
* Observable/Observer design pattern interface for handing events on a socket
|
* 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 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 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 {
|
interface SocketObserver {
|
||||||
/**
|
/**
|
||||||
|
@ -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'));
|
|
||||||
}
|
|
||||||
}
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -3,7 +3,6 @@ namespace Ratchet\Tests;
|
|||||||
use Ratchet\Server;
|
use Ratchet\Server;
|
||||||
use Ratchet\Tests\Mock\FakeSocket as Socket;
|
use Ratchet\Tests\Mock\FakeSocket as Socket;
|
||||||
use Ratchet\Tests\Mock\Application as TestApp;
|
use Ratchet\Tests\Mock\Application as TestApp;
|
||||||
use Ratchet\Tests\Mock\ArrayLogger;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers Ratchet\Server
|
* @covers Ratchet\Server
|
||||||
@ -32,32 +31,6 @@ class ServerTest extends \PHPUnit_Framework_TestCase {
|
|||||||
$this->assertThat($this->_server, $constraint);
|
$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() {
|
public function testIteration() {
|
||||||
$this->assertInstanceOf('\\Iterator', $this->_server->getIterator());
|
$this->assertInstanceOf('\\Iterator', $this->_server->getIterator());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user