diff --git a/src/Abstract/Type/Nex.php b/src/Abstract/Type/Nex.php new file mode 100644 index 0000000..beb7dd0 --- /dev/null +++ b/src/Abstract/Type/Nex.php @@ -0,0 +1,139 @@ +get('port')) $environment->set('port', 1900); + + if ($environment->get('dump')) + { + print( + str_replace( + [ + '{time}', + '{host}', + '{port}' + ], + [ + (string) date('c'), + (string) $environment->get('host'), + (string) $environment->get('port') + ], + _('[{time}] [construct] server {host}:{port}') + ) . PHP_EOL + ); + } + + $this->_environment = $environment; + + $this->init(); + } + + public function onOpen( + \Ratchet\ConnectionInterface $connection + ) { + if ($this->_environment->get('dump')) + { + print( + str_replace( + [ + '{time}', + '{host}', + '{crid}' + ], + [ + (string) date('c'), + (string) $connection->remoteAddress, + (string) $connection->resourceId + ], + _('[{time}] [open] incoming connection {host}#{crid}') + ) . PHP_EOL + ); + } + } + + public function onMessage( + \Ratchet\ConnectionInterface $connection, + $request + ) { + if ($this->_environment->get('dump')) + { + print( + str_replace( + [ + '{time}', + '{host}', + '{crid}' + ], + [ + (string) date('c'), + (string) $connection->remoteAddress, + (string) $connection->resourceId + ], + _('[{time}] [message] incoming connection {host}#{crid}') + ) . PHP_EOL + ); + } + } + + public function onClose( + \Ratchet\ConnectionInterface $connection + ) { + if ($this->_environment->get('dump')) + { + print( + str_replace( + [ + '{time}', + '{host}', + '{crid}' + ], + [ + (string) date('c'), + (string) $connection->remoteAddress, + (string) $connection->resourceId + ], + _('[{time}] [close] incoming connection {host}#{crid}') + ) . PHP_EOL + ); + } + } + + public function onError( + \Ratchet\ConnectionInterface $connection, + \Exception $exception + ) { + if ($this->_environment->get('dump')) + { + print( + str_replace( + [ + '{time}', + '{host}', + '{crid}', + '{info}' + ], + [ + (string) date('c'), + (string) $connection->remoteAddress, + (string) $connection->resourceId, + (string) $exception->getMessage() + ], + _('[{time}] [error] incoming connection {host}#{crid} reason: {info}') + ) . PHP_EOL + ); + } + + $connection->close(); + } +} \ No newline at end of file diff --git a/src/Controller/Nex/Filesystem.php b/src/Controller/Nex/Filesystem.php index 67d580e..fa06a46 100644 --- a/src/Controller/Nex/Filesystem.php +++ b/src/Controller/Nex/Filesystem.php @@ -2,30 +2,25 @@ namespace Yggverse\Next\Controller\Nex; -use \Ratchet\MessageComponentInterface; - -class Filesystem implements MessageComponentInterface +class Filesystem extends \Yggverse\Next\Abstract\Type\Nex { - private \Yggverse\Next\Model\Environment $_environment; private \Yggverse\Next\Model\Filesystem $_filesystem; - public function __construct( - \Yggverse\Next\Model\Environment $environment, - \Yggverse\Next\Model\Filesystem $filesystem - ) { - // Init environment - $this->_environment = $environment; - - // Init filesystem - $this->_filesystem = $filesystem; - - // Check port is defined - if (!$this->_environment->get('port')) + public function init() + { + // Validate environment arguments defined for this type + if (!$this->_environment->get('root')) { - // Set protocol defaults - $this->_environment->set('port', 1900); + throw new \Exception( + _('filesystem root path required!') + ); } + // Init filesystem + $this->_filesystem = new \Yggverse\Next\Model\Filesystem( + $this->_environment->get('root') + ); + // Dump event if ($this->_environment->get('dump')) { @@ -49,30 +44,6 @@ class Filesystem implements MessageComponentInterface } } - public function onOpen( - \Ratchet\ConnectionInterface $connection - ) { - // Dump event - if ($this->_environment->get('dump')) - { - print( - str_replace( - [ - '{time}', - '{host}', - '{crid}' - ], - [ - (string) date('c'), - (string) $connection->remoteAddress, - (string) $connection->resourceId - ], - _('[{time}] [open] incoming connection {host}#{crid}') - ) . PHP_EOL - ); - } - } - public function onMessage( \Ratchet\ConnectionInterface $connection, $request @@ -214,58 +185,4 @@ class Filesystem implements MessageComponentInterface // Disconnect $connection->close(); } - - public function onClose( - \Ratchet\ConnectionInterface $connection - ) { - // Dump event - if ($this->_environment->get('dump')) - { - print( - str_replace( - [ - '{time}', - '{host}', - '{crid}' - ], - [ - (string) date('c'), - (string) $connection->remoteAddress, - (string) $connection->resourceId - ], - _('[{time}] [close] incoming connection {host}#{crid}') - ) . PHP_EOL - ); - } - } - - public function onError( - \Ratchet\ConnectionInterface $connection, - \Exception $exception - ) { - // Dump event - if ($this->_environment->get('dump')) - { - print( - str_replace( - [ - '{time}', - '{host}', - '{crid}', - '{info}' - ], - [ - (string) date('c'), - (string) $connection->remoteAddress, - (string) $connection->resourceId, - (string) $exception->getMessage() - ], - _('[{time}] [error] incoming connection {host}#{crid} reason: {info}') - ) . PHP_EOL - ); - } - - // Disconnect - $connection->close(); - } } \ No newline at end of file