Continuing logical NS refactor
Updated more components to reflect new terminology when using Ratchet components
This commit is contained in:
parent
149a99cf7c
commit
2c976d0102
@ -17,7 +17,7 @@
|
|||||||
, "autoload": {
|
, "autoload": {
|
||||||
"psr-0": {
|
"psr-0": {
|
||||||
"Ratchet\\Tests": "tests"
|
"Ratchet\\Tests": "tests"
|
||||||
, "Ratchet": "lib"
|
, "Ratchet": "src"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
, "repositories": {
|
, "repositories": {
|
||||||
|
2
composer.lock
generated
2
composer.lock
generated
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"hash": "75f85f47f6365abbeeabb065601c6ec2",
|
"hash": "9c9347f555af9a961102c4158e6d2ae8",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"package": "guzzle",
|
"package": "guzzle",
|
||||||
|
@ -9,7 +9,7 @@ use Ratchet\Resource\Command\CommandInterface;
|
|||||||
/**
|
/**
|
||||||
* Creates an open-ended socket to listen on a port for incomming connections. Events are delegated through this to attached applications
|
* Creates an open-ended socket to listen on a port for incomming connections. Events are delegated through this to attached applications
|
||||||
*/
|
*/
|
||||||
class App implements MessageComponentInterface {
|
class IOServerComponent implements MessageComponentInterface {
|
||||||
/**
|
/**
|
||||||
* @var array of Socket Resources
|
* @var array of Socket Resources
|
||||||
*/
|
*/
|
||||||
@ -145,6 +145,9 @@ class App implements MessageComponentInterface {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @{inheritdoc}
|
||||||
|
*/
|
||||||
public function onOpen(ConnectionInterface $conn) {
|
public function onOpen(ConnectionInterface $conn) {
|
||||||
$new_socket = clone $conn->getSocket();
|
$new_socket = clone $conn->getSocket();
|
||||||
$new_socket->set_nonblock();
|
$new_socket->set_nonblock();
|
||||||
@ -156,10 +159,16 @@ class App implements MessageComponentInterface {
|
|||||||
return $this->_decorating->onOpen($new_connection);
|
return $this->_decorating->onOpen($new_connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @{inheritdoc}
|
||||||
|
*/
|
||||||
public function onMessage(ConnectionInterface $from, $msg) {
|
public function onMessage(ConnectionInterface $from, $msg) {
|
||||||
return $this->_decorating->onMessage($from, $msg);
|
return $this->_decorating->onMessage($from, $msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @{inheritdoc}
|
||||||
|
*/
|
||||||
public function onClose(ConnectionInterface $conn) {
|
public function onClose(ConnectionInterface $conn) {
|
||||||
$resource = $conn->getSocket()->getResource();
|
$resource = $conn->getSocket()->getResource();
|
||||||
|
|
||||||
@ -170,6 +179,9 @@ class App implements MessageComponentInterface {
|
|||||||
return $cmd;
|
return $cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @{inheritdoc}
|
||||||
|
*/
|
||||||
public function onError(ConnectionInterface $conn, \Exception $e) {
|
public function onError(ConnectionInterface $conn, \Exception $e) {
|
||||||
return $this->_decorating->onError($conn, $e);
|
return $this->_decorating->onError($conn, $e);
|
||||||
}
|
}
|
@ -25,7 +25,7 @@ use Ratchet\Component\WAMP\Command\Action\Prefix;
|
|||||||
* @link http://www.tavendo.de/autobahn/protocol.html
|
* @link http://www.tavendo.de/autobahn/protocol.html
|
||||||
* @link https://raw.github.com/oberstet/Autobahn/master/lib/javascript/autobahn.js
|
* @link https://raw.github.com/oberstet/Autobahn/master/lib/javascript/autobahn.js
|
||||||
*/
|
*/
|
||||||
class WAMPComponent implements WebSocketAppInterface {
|
class WAMPServerComponent implements WebSocketAppInterface {
|
||||||
const MSG_WELCOME = 0;
|
const MSG_WELCOME = 0;
|
||||||
const MSG_PREFIX = 1;
|
const MSG_PREFIX = 1;
|
||||||
const MSG_CALL = 2;
|
const MSG_CALL = 2;
|
@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Ratchet\Component\WAMP;
|
namespace Ratchet\Component\WAMP;
|
||||||
|
use Ratchet\Component\ComponentInterface;
|
||||||
use Ratchet\Resource\ConnectionInterface;
|
use Ratchet\Resource\ConnectionInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -7,7 +8,7 @@ use Ratchet\Resource\ConnectionInterface;
|
|||||||
* onMessage is replaced by various types of messages for this protocol (pub/sub or rpc)
|
* onMessage is replaced by various types of messages for this protocol (pub/sub or rpc)
|
||||||
* @todo Thought: URI as class. Class has short and long version stored (if as prefix)
|
* @todo Thought: URI as class. Class has short and long version stored (if as prefix)
|
||||||
*/
|
*/
|
||||||
interface WAMPServerComponentInterface {
|
interface WAMPServerComponentInterface extends ComponentInterface {
|
||||||
/**
|
/**
|
||||||
* When a new connection is opened it will be passed to this method
|
* When a new connection is opened it will be passed to this method
|
||||||
* @param Ratchet\Resource\Connection
|
* @param Ratchet\Resource\Connection
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Ratchet\Component\WebSocket;
|
namespace Ratchet\Component\WebSocket;
|
||||||
use Ratchet\Component\ComponentInterface;
|
use Ratchet\Component\MessageComponentInterface;
|
||||||
use Ratchet\Resource\ConnectionInterface;
|
use Ratchet\Resource\ConnectionInterface;
|
||||||
use Ratchet\Resource\Command\Factory;
|
use Ratchet\Resource\Command\Factory;
|
||||||
use Ratchet\Resource\Command\CommandInterface;
|
use Ratchet\Resource\Command\CommandInterface;
|
||||||
@ -14,10 +14,10 @@ use Ratchet\Component\WebSocket\Guzzle\Http\Message\RequestFactory;
|
|||||||
* @link http://ca.php.net/manual/en/ref.http.php
|
* @link http://ca.php.net/manual/en/ref.http.php
|
||||||
* @link http://dev.w3.org/html5/websockets/
|
* @link http://dev.w3.org/html5/websockets/
|
||||||
*/
|
*/
|
||||||
class WebSocketComponent implements ComponentInterface {
|
class WebSocketComponent implements MessageComponentInterface {
|
||||||
/**
|
/**
|
||||||
* Decorated component
|
* Decorated component
|
||||||
* @var Ratchet\Component\ComponentInterface
|
* @var Ratchet\Component\MessageComponentInterface
|
||||||
*/
|
*/
|
||||||
protected $_decorating;
|
protected $_decorating;
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ class WebSocketComponent implements ComponentInterface {
|
|||||||
*/
|
*/
|
||||||
public $accepted_subprotocols = array();
|
public $accepted_subprotocols = array();
|
||||||
|
|
||||||
public function __construct(ComponentInterface $component) {
|
public function __construct(MessageComponentInterface $component) {
|
||||||
$this->_decorating = $component;
|
$this->_decorating = $component;
|
||||||
$this->_factory = new Factory;
|
$this->_factory = new Factory;
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Ratchet\Component\WebSocket;
|
namespace Ratchet\Component\WebSocket;
|
||||||
use Ratchet\Component\ComponentInterface;
|
use Ratchet\Component\MessageComponentInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @todo App interfaces this (optionally) if is meant for WebSocket
|
* @todo App interfaces this (optionally) if is meant for WebSocket
|
||||||
* @todo WebSocket checks if instanceof AppInterface, if so uses getSubProtocol() when doing handshake
|
* @todo WebSocket checks if instanceof AppInterface, if so uses getSubProtocol() when doing handshake
|
||||||
* @todo Pick a better name for this...
|
* @todo Pick a better name for this...
|
||||||
*/
|
*/
|
||||||
interface WebSocketComponentInterface extends ComponentInterface {
|
interface WebSocketComponentInterface extends MessageComponentInterface {
|
||||||
/**
|
/**
|
||||||
* Currently instead of this, I'm setting header in the Connection object passed around...not sure which I like more
|
* Currently instead of this, I'm setting header in the Connection object passed around...not sure which I like more
|
||||||
* @param string
|
* @param string
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Ratchet\Resource\Command\Action;
|
namespace Ratchet\Resource\Command\Action;
|
||||||
use Ratchet\Resource\ConnectionInterface;
|
use Ratchet\Resource\ConnectionInterface;
|
||||||
|
use Ratchet\Resource\Command\CommandInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A single command tied to 1 socket connection
|
* A single command tied to 1 socket connection
|
||||||
|
@ -22,6 +22,9 @@ class Composite extends \SplQueue implements CommandInterface {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @{inheritdoc}
|
||||||
|
*/
|
||||||
public function execute(ComponentInterface $scope = null) {
|
public function execute(ComponentInterface $scope = null) {
|
||||||
$this->setIteratorMode(static::IT_MODE_DELETE);
|
$this->setIteratorMode(static::IT_MODE_DELETE);
|
||||||
|
|
||||||
|
@ -1,23 +1,23 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Ratchet\Tests\Application\Server;
|
namespace Ratchet\Tests\Application\Server;
|
||||||
use Ratchet\Component\Server\App as ServerApp;
|
use Ratchet\Component\Server\IOServerComponent;
|
||||||
use Ratchet\Tests\Mock\FakeSocket as Socket;
|
use Ratchet\Tests\Mock\FakeSocket as Socket;
|
||||||
use Ratchet\Tests\Mock\Component as TestApp;
|
use Ratchet\Tests\Mock\Component as TestApp;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers Ratchet\Component\Server\App
|
* @covers Ratchet\Component\Server\IOServerComponent
|
||||||
*/
|
*/
|
||||||
class AppTest extends \PHPUnit_Framework_TestCase {
|
class IOServerComponentTest extends \PHPUnit_Framework_TestCase {
|
||||||
protected $_catalyst;
|
protected $_catalyst;
|
||||||
protected $_server;
|
protected $_server;
|
||||||
protected $_app;
|
protected $_decorated;
|
||||||
|
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
$this->_catalyst = new Socket;
|
$this->_catalyst = new Socket;
|
||||||
$this->_app = new TestApp;
|
$this->_decorated = new TestApp;
|
||||||
$this->_server = new ServerApp($this->_app);
|
$this->_server = new IOServerComponent($this->_decorated);
|
||||||
|
|
||||||
$ref = new \ReflectionClass('\\Ratchet\\Component\\Server\\App');
|
$ref = new \ReflectionClass('\\Ratchet\\Component\\Server\\IOServerComponent');
|
||||||
$prop = $ref->getProperty('_run');
|
$prop = $ref->getProperty('_run');
|
||||||
$prop->setAccessible(true);
|
$prop->setAccessible(true);
|
||||||
$prop->setValue($this->_server, false);
|
$prop->setValue($this->_server, false);
|
||||||
@ -41,7 +41,7 @@ class AppTest extends \PHPUnit_Framework_TestCase {
|
|||||||
$master = $this->getMasterConnection();
|
$master = $this->getMasterConnection();
|
||||||
|
|
||||||
$this->_server->onOpen($master);
|
$this->_server->onOpen($master);
|
||||||
$clone = $this->_app->_conn_open;
|
$clone = $this->_decorated->_conn_open;
|
||||||
|
|
||||||
$this->assertEquals($master->getID() + 1, $clone->getID());
|
$this->assertEquals($master->getID() + 1, $clone->getID());
|
||||||
}
|
}
|
||||||
@ -54,12 +54,12 @@ class AppTest extends \PHPUnit_Framework_TestCase {
|
|||||||
// that way can mimic the TCP fragmentation/buffer situation
|
// that way can mimic the TCP fragmentation/buffer situation
|
||||||
|
|
||||||
$this->_server->onOpen($master);
|
$this->_server->onOpen($master);
|
||||||
$clone = $this->_app->_conn_open;
|
$clone = $this->_decorated->_conn_open;
|
||||||
|
|
||||||
// $this->_server->run($this->_catalyst);
|
// $this->_server->run($this->_catalyst);
|
||||||
$msg = 'Hello World!';
|
$msg = 'Hello World!';
|
||||||
$this->_server->onMessage($clone, $msg);
|
$this->_server->onMessage($clone, $msg);
|
||||||
|
|
||||||
$this->assertEquals($msg, $this->_app->_msg_recv);
|
$this->assertEquals($msg, $this->_decorated->_msg_recv);
|
||||||
}
|
}
|
||||||
}
|
}
|
2
vendor/.composer/ClassLoader.php
vendored
2
vendor/.composer/ClassLoader.php
vendored
@ -1,2 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace Composer\Autoload; class ClassLoader { private $prefixes = array(); private $fallbackDirs = array(); public function getPrefixes() { return $this->prefixes; } public function getFallbackDirs() { return $this->fallbackDirs; } public function add($prefix, $paths) { if (!$prefix) { $this->fallbackDirs = (array) $paths; return; } if (isset($this->prefixes[$prefix])) { $this->prefixes[$prefix] = array_merge( $this->prefixes[$prefix], (array) $paths ); } else { $this->prefixes[$prefix] = (array) $paths; } } public function register($prepend = false) { spl_autoload_register(array($this, 'loadClass'), true, $prepend); } public function loadClass($class) { if ($file = $this->findFile($class)) { require $file; return true; } } public function findFile($class) { if ('\\' == $class[0]) { $class = substr($class, 1); } if (false !== $pos = strrpos($class, '\\')) { $classPath = DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, substr($class, 0, $pos)); $className = substr($class, $pos + 1); } else { $classPath = null; $className = $class; } $classPath .= DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; foreach ($this->prefixes as $prefix => $dirs) { foreach ($dirs as $dir) { if (0 === strpos($class, $prefix)) { if (file_exists($dir . $classPath)) { return $dir . $classPath; } } } } foreach ($this->fallbackDirs as $dir) { if (file_exists($dir . $classPath)) { return $dir . $classPath; } } } }
|
|
22
vendor/.composer/autoload.php
vendored
22
vendor/.composer/autoload.php
vendored
@ -1,22 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
// autoload.php generated by Composer
|
|
||||||
if (!class_exists('Composer\\Autoload\\ClassLoader', false)) {
|
|
||||||
require __DIR__.'/ClassLoader.php';
|
|
||||||
}
|
|
||||||
|
|
||||||
$__composer_autoload_init = function() {
|
|
||||||
$loader = new \Composer\Autoload\ClassLoader();
|
|
||||||
|
|
||||||
$map = require __DIR__.'/autoload_namespaces.php';
|
|
||||||
|
|
||||||
foreach ($map as $namespace => $path) {
|
|
||||||
$loader->add($namespace, $path);
|
|
||||||
}
|
|
||||||
|
|
||||||
$loader->register();
|
|
||||||
|
|
||||||
return $loader;
|
|
||||||
};
|
|
||||||
|
|
||||||
return $__composer_autoload_init();
|
|
11
vendor/.composer/autoload_namespaces.php
vendored
11
vendor/.composer/autoload_namespaces.php
vendored
@ -1,11 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
// autoload_namespace.php generated by Composer
|
|
||||||
|
|
||||||
$vendorDir = dirname(__DIR__);
|
|
||||||
|
|
||||||
return array(
|
|
||||||
'Ratchet\\Tests' => dirname($vendorDir) . '/tests',
|
|
||||||
'Ratchet' => dirname($vendorDir) . '/lib',
|
|
||||||
'Guzzle' => $vendorDir . '/guzzle/src',
|
|
||||||
);
|
|
22
vendor/.composer/installed.json
vendored
22
vendor/.composer/installed.json
vendored
@ -1,22 +0,0 @@
|
|||||||
[
|
|
||||||
{
|
|
||||||
"name": "guzzle",
|
|
||||||
"version": "2.0.2",
|
|
||||||
"version_normalized": "2.0.2.0",
|
|
||||||
"source": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "https:\/\/github.com\/guzzle\/guzzle.git",
|
|
||||||
"reference": "ac64abc2c05b921efc4623379c1674a282475ae5"
|
|
||||||
},
|
|
||||||
"type": "library",
|
|
||||||
"names": [
|
|
||||||
"guzzle"
|
|
||||||
],
|
|
||||||
"installation-source": "source",
|
|
||||||
"autoload": {
|
|
||||||
"psr-0": {
|
|
||||||
"Guzzle": "src"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
Loading…
Reference in New Issue
Block a user