- improved logging

- fixed multiple problem with map sync
- added some "garbage collection" for unsubscribed connection data
- updated README.md
This commit is contained in:
Mark Friedrich
2019-07-01 19:59:52 +02:00
parent a25cf73daa
commit cbca53ad73
12 changed files with 1285 additions and 283 deletions

View File

@@ -0,0 +1,67 @@
<?php
namespace Exodus4D\Socket\Socket;
use Exodus4D\Socket\Log\Store;
use React\EventLoop;
use React\Socket;
use Ratchet\MessageComponentInterface;
abstract class AbstractSocket {
/**
* unique name for this component
* -> should be overwritten in child instances
* -> is used as "log store" name
*/
const COMPONENT_NAME = 'default';
/**
* global server loop
* @var EventLoop\LoopInterface
*/
protected $loop;
/**
* @var MessageComponentInterface
*/
protected $handler;
/**
* @var Store
*/
protected $logStore;
/**
* AbstractSocket constructor.
* @param EventLoop\LoopInterface $loop
* @param MessageComponentInterface $handler
* @param Store $store
*/
public function __construct(
EventLoop\LoopInterface $loop,
MessageComponentInterface $handler,
Store $store
){
$this->loop = $loop;
$this->handler = $handler;
$this->logStore = $store;
$this->log(['debug', 'info'], null, 'START', 'start Socket server…');
}
/**
* @param $logTypes
* @param Socket\ConnectionInterface|null $connection
* @param string $action
* @param string $message
*/
public function log($logTypes, ?Socket\ConnectionInterface $connection, string $action, string $message = '') : void {
if(!$this->logStore->isLocked()){
$remoteAddress = $connection ? $connection->getRemoteAddress() : null;
$this->logStore->log($logTypes, $remoteAddress, null, $action, $message);
}
}
}