Namespaces

Fixed all the namespaces to match new folder structure
This commit is contained in:
Chris Boden 2011-11-12 20:51:54 -05:00
parent 5386b4c066
commit 47b7110dc1
32 changed files with 142 additions and 165 deletions

View File

@ -1,12 +1,12 @@
<?php <?php
namespace Ratchet\Protocol; namespace Ratchet\Application;
use Ratchet\SocketObserver; use Ratchet\ObserverInterface;
interface ProtocolInterface extends SocketObserver { interface ProtocolInterface extends ObserverInterface {
/** /**
* @param Ratchet\SocketObserver Application to wrap in protocol * @param Ratchet\ObserverInterface Application to wrap in protocol
*/ */
function __construct(SocketObserver $application); // function __construct(ObserverInterface $application);
/** /**
* @return array * @return array

View File

@ -1,8 +1,8 @@
<?php <?php
namespace Ratchet; namespace Ratchet\Application\Server;
use Ratchet\Server\Aggregator; use Ratchet\ObserverInterface;
use Ratchet\Protocol\ProtocolInterface; use Ratchet\SocketInterface;
use Ratchet\Command\CommandInterface; 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
@ -10,10 +10,10 @@ use Ratchet\Command\CommandInterface;
* @todo Currently passing Socket object down the decorated chain - should be sending reference to it instead; Receivers do not interact with the Socket directly, they do so through the Command pattern * @todo Currently passing Socket object down the decorated chain - should be sending reference to it instead; Receivers do not interact with the Socket directly, they do so through the Command pattern
* @todo With all these options for the server I should probably use a DIC * @todo With all these options for the server I should probably use a DIC
*/ */
class Server implements SocketObserver, \IteratorAggregate { class App implements ObserverInterface {
/** /**
* The master socket, receives all connections * The master socket, receives all connections
* @type Socket * @var Socket
*/ */
protected $_master = null; protected $_master = null;
@ -28,41 +28,35 @@ class Server implements SocketObserver, \IteratorAggregate {
protected $_connections; protected $_connections;
/** /**
* @var SocketObserver * @var Ratchet\ObserverInterface
* Maybe temporary? * Maybe temporary?
*/ */
protected $_app; protected $_app;
/** /**
* @param Ratchet\Socket * @param Ratchet\ObserverInterface
* @param SocketObserver
*/ */
public function __construct(SocketInterface $host, SocketObserver $application) { public function __construct(ObserverInterface $application = null) {
$this->_master = $host; if (null === $application) {
$socket = $host->getResource(); throw new \UnexpectedValueException("Server requires an application to run off of");
$this->_resources[] = $socket; }
$this->_app = $application;
$this->_connections = new \ArrayIterator(array()); $this->_connections = new \ArrayIterator(array());
$this->_app = $application;
}
/**
* @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;
} }
/* /*
* @param Ratchet\SocketInterface
* @param mixed The address to listen for incoming connections on. "0.0.0.0" to listen from anywhere * @param mixed The address to listen for incoming connections on. "0.0.0.0" to listen from anywhere
* @param int The port to listen to connections on * @param int The port to listen to connections on
* @throws Exception * @throws Ratchet\Exception
* @todo Validate address. Use socket_get_option, if AF_INET must be IP, if AF_UNIX must be path * @todo Validate address. Use socket_get_option, if AF_INET must be IP, if AF_UNIX must be path
* @todo Consider making the 4kb listener changable * @todo Consider making the 4kb listener changable
*/ */
public function run($address = '127.0.0.1', $port = 1025) { public function run(SocketInterface $host, $address = '127.0.0.1', $port = 1025) {
$this->_master = $host;
$this->_resources[] = $host->getResource();
$recv_bytes = 1024; $recv_bytes = 1024;
set_time_limit(0); set_time_limit(0);

View File

@ -1,13 +1,14 @@
<?php <?php
namespace Ratchet\Protocol; namespace Ratchet\Application\WebSocket;
use Ratchet\Protocol\WebSocket\Client; use Ratchet\Application\WebSocket\Client;
use Ratchet\Protocol\WebSocket\VersionInterface; use Ratchet\Application\WebSocket\VersionInterface;
use Ratchet\SocketInterface; use Ratchet\SocketInterface;
use Ratchet\SocketObserver; use Ratchet\ObserverInterface;
use Ratchet\Command\Factory; use Ratchet\Resource\Command\Factory;
use Ratchet\Command\CommandInterface; use Ratchet\Resource\Command\CommandInterface;
use Ratchet\Command\Action\SendMessage; use Ratchet\Resource\Command\Action\SendMessage;
use Ratchet\Protocol\WebSocket\Util\HTTP; use Ratchet\Application\WebSocket\Util\HTTP;
use Ratchet\Application\ProtocolInterface;
/** /**
* The adapter to handle WebSocket requests/responses * The adapter to handle WebSocket requests/responses
@ -16,10 +17,10 @@ use Ratchet\Protocol\WebSocket\Util\HTTP;
* @todo Make sure this works both ways (client/server) as stack needs to exist on client for framing * @todo Make sure this works both ways (client/server) as stack needs to exist on client for framing
* @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 ObserverInterface 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 * @todo Change namespace to Ratchet\Application\WebSocket\Adapter
*/ */
class WebSocket implements ProtocolInterface { class App implements ProtocolInterface {
/** /**
* Lookup for connected clients * Lookup for connected clients
* @var SplObjectStorage * @var SplObjectStorage
@ -28,12 +29,12 @@ class WebSocket implements ProtocolInterface {
/** /**
* Decorated application * Decorated application
* @var Ratchet\SocketObserver * @var Ratchet\ObserverInterface
*/ */
protected $_app; protected $_app;
/** /**
* @var Ratchet\Command\Factory * @var Ratchet\Resource\Command\Factory
*/ */
protected $_factory; protected $_factory;
@ -45,9 +46,13 @@ class WebSocket implements ProtocolInterface {
, 'Hixie76' => null , 'Hixie76' => null
); );
public function __construct(SocketObserver $application) { public function __construct(ObserverInterface $app = null) {
if (null === $app) {
throw new \UnexpectedValueException("WebSocket requires an application to run off of");
}
$this->_clients = new \SplObjectStorage; $this->_clients = new \SplObjectStorage;
$this->_app = $application; $this->_app = $app;
$this->_factory = new Factory; $this->_factory = new Factory;
} }
@ -128,8 +133,8 @@ class WebSocket implements ProtocolInterface {
/** /**
* Checks if a return Command from your application is a message, if so encode it/them * Checks if a return Command from your application is a message, if so encode it/them
* @param Ratchet\Command\CommandInterface|NULL * @param Ratchet\Resource\Command\CommandInterface|NULL
* @return Ratchet\Command\CommandInterface|NULL * @return Ratchet\Resource\Command\CommandInterface|NULL
*/ */
protected function prepareCommand(CommandInterface $command = null) { protected function prepareCommand(CommandInterface $command = null) {
if ($command instanceof SendMessage) { if ($command instanceof SendMessage) {
@ -169,7 +174,7 @@ class WebSocket implements ProtocolInterface {
*/ */
protected function versionFactory($version) { protected function versionFactory($version) {
if (null === $this->_versions[$version]) { if (null === $this->_versions[$version]) {
$ns = __CLASS__ . "\\Version\\{$version}"; $ns = __NAMESPACE__ . "\\Version\\{$version}";
$this->_version[$version] = new $ns; $this->_version[$version] = new $ns;
} }

View File

@ -1,13 +1,13 @@
<?php <?php
namespace Ratchet\Protocol\WebSocket; namespace Ratchet\Application\WebSocket;
use Ratchet\SocketObserver; use Ratchet\ObserverInterface;
use Ratchet\SocketInterface; use Ratchet\SocketInterface;
/** /**
* @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
*/ */
interface AppInterface extends SocketObserver { interface AppInterface extends ObserverInterface {
/** /**
* @return string * @return string
*/ */
@ -16,7 +16,7 @@ interface AppInterface extends SocketObserver {
/** /**
* @param Ratchet\SocketInterface * @param Ratchet\SocketInterface
* @param string * @param string
* @return Ratchet\Command\CommandInterface|null * @return Ratchet\Resource\Command\CommandInterface|null
*/ */
function onOpen(SocketInterface $conn, $headers); function onOpen(SocketInterface $conn, $headers);
} }

View File

@ -1,6 +1,6 @@
<?php <?php
namespace Ratchet\Protocol\WebSocket; namespace Ratchet\Application\WebSocket;
use Ratchet\Protocol\WebSocket\Version\VersionInterface; use Ratchet\Application\WebSocket\Version\VersionInterface;
/** /**
* A representation of a Socket connection of the user on the other end of the socket * A representation of a Socket connection of the user on the other end of the socket
@ -8,7 +8,7 @@ use Ratchet\Protocol\WebSocket\Version\VersionInterface;
*/ */
class Client { class Client {
/** /**
* @var Ratchet\Protocol\WebSocket\Version\VersionInterface * @var Ratchet\Application\WebSocket\Version\VersionInterface
*/ */
protected $_version = null; protected $_version = null;

View File

@ -1,8 +1,8 @@
<?php <?php
namespace Ratchet\Protocol\WebSocket\Command\Action; namespace Ratchet\Application\WebSocket\Command\Action;
use Ratchet\SocketInterface; use Ratchet\SocketInterface;
use Ratchet\Command\Action\SendMessage; use Ratchet\Resource\Command\Action\SendMessage;
use Ratchet\SocketObserver; use Ratchet\ObserverInterface;
class Disconnect extends SendMessage { class Disconnect extends SendMessage {
protected $_code = 1000; protected $_code = 1000;
@ -13,7 +13,7 @@ class Disconnect extends SendMessage {
// re-do message based on code // re-do message based on code
} }
public function execute(SocketObserver $scope = null) { public function execute(ObserverInterface $scope = null) {
parent::execute(); parent::execute();
$this->_socket->close(); $this->_socket->close();
} }

View File

@ -1,9 +1,9 @@
<?php <?php
namespace Ratchet\Protocol\WebSocket\Command\Action; namespace Ratchet\Application\WebSocket\Command\Action;
use Ratchet\Command\ActionTemplate; use Ratchet\Resource\Command\ActionTemplate;
use Ratchet\SocketObserver; use Ratchet\ObserverInterface;
class Ping extends ActionTemplate { class Ping extends ActionTemplate {
public function execute(SocketObserver $scope = null) { public function execute(ObserverInterface $scope = null) {
} }
} }

View File

@ -1,9 +1,9 @@
<?php <?php
namespace Ratchet\Protocol\WebSocket\Command\Action; namespace Ratchet\Application\WebSocket\Command\Action;
use Ratchet\Command\ActionTemplate; use Ratchet\Resource\Command\ActionTemplate;
use Ratchet\SocketObserver; use Ratchet\ObserverInterface;
class Pong extends ActionTemplate { class Pong extends ActionTemplate {
public function execute(SocketObserver $scope = null) { public function execute(ObserverInterface $scope = null) {
} }
} }

View File

@ -1,5 +1,5 @@
<?php <?php
namespace Ratchet\Protocol\WebSocket\Util; namespace Ratchet\Application\WebSocket\Util;
/** /**
* A helper class for handling HTTP requests * A helper class for handling HTTP requests

View File

@ -1,5 +1,5 @@
<?php <?php
namespace Ratchet\Protocol\WebSocket\Version; namespace Ratchet\Application\WebSocket\Version;
/** /**
* The Hixie76 is currently implemented by Safari * The Hixie76 is currently implemented by Safari

View File

@ -1,6 +1,6 @@
<?php <?php
namespace Ratchet\Protocol\WebSocket\Version; namespace Ratchet\Application\WebSocket\Version;
use Ratchet\Protocol\WebSocket\Util\HTTP; use Ratchet\Application\WebSocket\Util\HTTP;
/** /**
* The HyBi-10 version, identified in the headers as version 8, is currently implemented by the latest Chrome and Firefix version * The HyBi-10 version, identified in the headers as version 8, is currently implemented by the latest Chrome and Firefix version

View File

@ -1,5 +1,5 @@
<?php <?php
namespace Ratchet\Protocol\WebSocket\Version; namespace Ratchet\Application\WebSocket\Version;
/** /**
* Despite the version iterations of WebInterface the actions they go through are similar * Despite the version iterations of WebInterface the actions they go through are similar

View File

@ -5,14 +5,21 @@ 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() * @todo Consider adding __construct(ObserverInterface $decorator = null) - on Server move Socket as parameter to run()
* @todo Does this belong in \Ratchet\Server\? * @todo Does this belong in \Ratchet\Server\?
*/ */
interface SocketObserver { interface ObserverInterface {
/**
* Decorator pattern
* @param ObserverInterface If nothing is passed it's the end of the line
* @throws UnexpectedValueException
*/
public function __construct(ObserverInterface $app = null);
/** /**
* 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 SocketInterface The socket/connection that just connected to your application * @param SocketInterface The socket/connection that just connected to your application
* @return Ratchet\Command\CommandInterface|null * @return Ratchet\Resource\Command\CommandInterface|null
*/ */
function onOpen(SocketInterface $conn); function onOpen(SocketInterface $conn);
@ -20,14 +27,14 @@ interface SocketObserver {
* Triggered when a client sends data through the socket * Triggered when a client sends data through the socket
* @param SocketInterface The socket/connection that sent the message to your application * @param SocketInterface The socket/connection that sent the message to your application
* @param string The message received * @param string The message received
* @return Ratchet\Command\CommandInterface|null * @return Ratchet\Resource\Command\CommandInterface|null
*/ */
function onRecv(SocketInterface $from, $msg); function onRecv(SocketInterface $from, $msg);
/** /**
* This is called before or after a socket is closed (depends on how it's closed). SendMessage to $conn will not result in an error if it has already been closed. * This is called before or after a socket is closed (depends on how it's closed). SendMessage to $conn will not result in an error if it has already been closed.
* @param SocketInterface The socket/connection that is closing/closed * @param SocketInterface The socket/connection that is closing/closed
* @return Ratchet\Command\CommandInterface|null * @return Ratchet\Resource\Command\CommandInterface|null
*/ */
function onClose(SocketInterface $conn); function onClose(SocketInterface $conn);
@ -36,7 +43,7 @@ interface SocketObserver {
* the Exception is sent back down the stack, handled by the Server and bubbled back up the application through this method * the Exception is sent back down the stack, handled by the Server and bubbled back up the application through this method
* @param SocketInterface * @param SocketInterface
* @param \Exception * @param \Exception
* @return Ratchet\Command\CommandInterface|null * @return Ratchet\Resource\Command\CommandInterface|null
*/ */
function onError(SocketInterface $conn, \Exception $e); function onError(SocketInterface $conn, \Exception $e);
} }

View File

@ -1,16 +1,16 @@
<?php <?php
namespace Ratchet\Command\Action; namespace Ratchet\Resource\Command\Action;
use Ratchet\Command\ActionTemplate; use Ratchet\Resource\Command\ActionTemplate;
use Ratchet\SocketObserver; use Ratchet\ObserverInterface;
use Ratchet\SocketInterface; use Ratchet\SocketInterface;
use Ratchet\Command\CommandInterface; use Ratchet\Resource\Command\CommandInterface;
use Ratchet\Command\Composite; use Ratchet\Resource\Command\Composite;
/** /**
* Close the connection to the sockets passed in the constructor * Close the connection to the sockets passed in the constructor
*/ */
class CloseConnection extends ActionTemplate { class CloseConnection extends ActionTemplate {
function execute(SocketObserver $scope = null) { function execute(ObserverInterface $scope = null) {
// All this code allows an application to have its onClose method executed before the socket is actually closed // All this code allows an application to have its onClose method executed before the socket is actually closed
$ret = $scope->onClose($this->getSocket()); $ret = $scope->onClose($this->getSocket());
@ -19,7 +19,7 @@ class CloseConnection extends ActionTemplate {
$comp->enqueue($ret); $comp->enqueue($ret);
$rt = new Runtime($this->getSocket()); $rt = new Runtime($this->getSocket());
$rt->setCommand(function(SocketInterface $socket, SocketObserver $scope) { $rt->setCommand(function(SocketInterface $socket, ObserverInterface $scope) {
$socket->close(); $socket->close();
}); });
$comp->enqueue($rt); $comp->enqueue($rt);

View File

@ -1,12 +1,12 @@
<?php <?php
namespace Ratchet\Command\Action; namespace Ratchet\Resource\Command\Action;
use Ratchet\Command\ActionTemplate; use Ratchet\Resource\Command\ActionTemplate;
use Ratchet\SocketObserver; use Ratchet\ObserverInterface;
/** /**
* Null pattern - execution does nothing, something needs to be passed back though * Null pattern - execution does nothing, something needs to be passed back though
*/ */
class Null extends ActionTemplate { class Null extends ActionTemplate {
public function execute(SocketObserver $scope = null) { public function execute(ObserverInterface $scope = null) {
} }
} }

View File

@ -1,7 +1,7 @@
<?php <?php
namespace Ratchet\Command\Action; namespace Ratchet\Resource\Command\Action;
use Ratchet\Command\ActionTemplate; use Ratchet\Resource\Command\ActionTemplate;
use Ratchet\SocketObserver; use Ratchet\ObserverInterface;
class Runtime extends ActionTemplate { class Runtime extends ActionTemplate {
/** /**
@ -10,14 +10,14 @@ class Runtime extends ActionTemplate {
protected $_command = null; protected $_command = null;
/** /**
* Your closure should accept two parameters (\Ratchet\SocketInterface, \Ratchet\SocketObserver) parameter and return a CommandInterface or NULL * Your closure should accept two parameters (\Ratchet\SocketInterface, \Ratchet\ObserverInterface) parameter and return a CommandInterface or NULL
* @param Closure Your closure/lambda to execute when the time comes * @param Closure Your closure/lambda to execute when the time comes
*/ */
public function setCommand(\Closure $callback) { public function setCommand(\Closure $callback) {
$this->_command = $callback; $this->_command = $callback;
} }
public function execute(SocketObserver $scope = null) { public function execute(ObserverInterface $scope = null) {
return call_user_func($this->_command, $this->getSocket(), $scope); return call_user_func($this->_command, $this->getSocket(), $scope);
} }
} }

View File

@ -1,7 +1,7 @@
<?php <?php
namespace Ratchet\Command\Action; namespace Ratchet\Resource\Command\Action;
use Ratchet\Command\ActionTemplate; use Ratchet\Resource\Command\ActionTemplate;
use Ratchet\SocketObserver; use Ratchet\ObserverInterface;
/** /**
* Send text back to the client end of the socket(s) * Send text back to the client end of the socket(s)
@ -33,7 +33,7 @@ class SendMessage extends ActionTemplate {
/** /**
* @throws \UnexpectedValueException if a message was not set with setMessage() * @throws \UnexpectedValueException if a message was not set with setMessage()
*/ */
public function execute(SocketObserver $scope = null) { public function execute(ObserverInterface $scope = null) {
if (empty($this->_message)) { if (empty($this->_message)) {
throw new \UnexpectedValueException("Message is empty"); throw new \UnexpectedValueException("Message is empty");
} }

View File

@ -1,5 +1,5 @@
<?php <?php
namespace Ratchet\Command; namespace Ratchet\Resource\Command;
use Ratchet\SocketInterface; use Ratchet\SocketInterface;
/** /**

View File

@ -1,5 +1,5 @@
<?php <?php
namespace Ratchet\Command; namespace Ratchet\Resource\Command;
use Ratchet\SocketInterface; use Ratchet\SocketInterface;
abstract class ActionTemplate implements ActionInterface { abstract class ActionTemplate implements ActionInterface {

View File

@ -1,6 +1,6 @@
<?php <?php
namespace Ratchet\Command; namespace Ratchet\Resource\Command;
use Ratchet\SocketObserver; use Ratchet\ObserverInterface;
/** /**
* Socket implementation of the Command Pattern * Socket implementation of the Command Pattern
@ -9,8 +9,8 @@ use Ratchet\SocketObserver;
interface CommandInterface { interface CommandInterface {
/** /**
* The Server class will call the execution * The Server class will call the execution
* @param Ratchet\SocketObserver Scope to execute the command under * @param Ratchet\ObserverInterface Scope to execute the command under
* @return CommandInterface|NULL * @return CommandInterface|NULL
*/ */
function execute(SocketObserver $scope = null); function execute(ObserverInterface $scope = null);
} }

View File

@ -1,6 +1,6 @@
<?php <?php
namespace Ratchet\Command; namespace Ratchet\Resource\Command;
use Ratchet\SocketObserver; use Ratchet\ObserverInterface;
class Composite extends \SplQueue implements CommandInterface { class Composite extends \SplQueue implements CommandInterface {
/** /**
@ -22,7 +22,7 @@ class Composite extends \SplQueue implements CommandInterface {
} }
} }
public function execute(SocketObserver $scope = null) { public function execute(ObserverInterface $scope = null) {
$this->setIteratorMode(static::IT_MODE_DELETE); $this->setIteratorMode(static::IT_MODE_DELETE);
$recursive = new self; $recursive = new self;

View File

@ -1,9 +1,9 @@
<?php <?php
namespace Ratchet\Command; namespace Ratchet\Resource\Command;
use Ratchet\SocketInterface; use Ratchet\SocketInterface;
/** /**
* A factory pattern class to easily create all the things in the Ratchet\Command interface * A factory pattern class to easily create all the things in the Ratchet\Resource\Command interface
*/ */
class Factory { class Factory {
protected $_paths = array(); protected $_paths = array();

View File

@ -1,5 +1,5 @@
<?php <?php
namespace Ratchet\Server; namespace Ratchet\Resource\Connection;
use Ratchet\SocketInterface; use Ratchet\SocketInterface;
/** /**

View File

@ -1,5 +1,5 @@
<?php <?php
namespace Ratchet\Server; namespace Ratchet\Resource\Connection;
use Ratchet\SocketInterface; use Ratchet\SocketInterface;
interface ConnectionInterface { interface ConnectionInterface {

View File

@ -1,10 +1,11 @@
<?php <?php
namespace Ratchet; namespace Ratchet;
use Ratchet\Protocol\ProtocolInterface; use Ratchet\Application\ProtocolInterface;
/** /**
* A wrapper for the PHP socket_ functions * A wrapper for the PHP socket_ functions
* @author Chris Boden <shout at chrisboden dot ca> * @author Chris Boden <shout at chrisboden dot ca>
* @todo Possibly move this into Ratchet\Resource - another concrete could use streams
*/ */
class Socket implements SocketInterface { class Socket implements SocketInterface {
/** /**
@ -110,7 +111,7 @@ class Socket implements SocketInterface {
} }
/** /**
* @param Ratchet\Protocol\ProtocolInterface * @param Ratchet\Application\ProtocolInterface
* @return Socket * @return Socket
* @throws Exception * @throws Exception
*/ */

View File

@ -1,11 +1,13 @@
<?php <?php
namespace Ratchet\Tests\Mock; namespace Ratchet\Tests\Mock;
use Ratchet\SocketObserver; use Ratchet\ObserverInterface;
use Ratchet\Server;
use Ratchet\Tests\Mock\Socket as MockSocket; use Ratchet\Tests\Mock\Socket as MockSocket;
use Ratchet\SocketInterface; use Ratchet\SocketInterface;
class Application implements SocketObserver { class Application implements ObserverInterface {
public function __construct(ObserverInterface $app = null) {
}
public function onOpen(SocketInterface $conn) { public function onOpen(SocketInterface $conn) {
} }

View File

@ -1,12 +1,12 @@
<?php <?php
namespace Ratchet\Tests\Mock; namespace Ratchet\Tests\Mock;
use Ratchet\SocketObserver; use Ratchet\ObserverInterface;
use Ratchet\Protocol\ProtocolInterface; use Ratchet\Application\ProtocolInterface;
use Ratchet\Server; use Ratchet\Server;
use Ratchet\SocketInterface; use Ratchet\SocketInterface;
class Protocol implements ProtocolInterface { class Protocol implements ProtocolInterface {
public function __construct(SocketObserver $application) { public function __construct(ObserverInterface $app = null) {
} }
public static function getDefaultConfig() { public static function getDefaultConfig() {

View File

@ -1,9 +1,9 @@
<?php <?php
namespace Ratchet\Tests\Protocol\WebSocket\Version; namespace Ratchet\Tests\Protocol\WebSocket\Version;
use Ratchet\Protocol\WebSocket\Version\Hixie76; use Ratchet\Application\WebSocket\Version\Hixie76;
/** /**
* @covers Ratchet\Protocol\WebSocket\Version\Hixie76 * @covers Ratchet\Application\WebSocket\Version\Hixie76
*/ */
class Hixie76Test extends \PHPUnit_Framework_TestCase { class Hixie76Test extends \PHPUnit_Framework_TestCase {
protected $_version; protected $_version;
@ -13,7 +13,7 @@ class Hixie76Test extends \PHPUnit_Framework_TestCase {
} }
public function testClassImplementsVersionInterface() { public function testClassImplementsVersionInterface() {
$constraint = $this->isInstanceOf('\\Ratchet\\Protocol\\WebSocket\\Version\\VersionInterface'); $constraint = $this->isInstanceOf('\\Ratchet\\Application\\WebSocket\\Version\\VersionInterface');
$this->assertThat($this->_version, $constraint); $this->assertThat($this->_version, $constraint);
} }

View File

@ -1,9 +1,9 @@
<?php <?php
namespace Ratchet\Tests\Protocol\WebSocket\Version; namespace Ratchet\Tests\Protocol\WebSocket\Version;
use Ratchet\Protocol\WebSocket\Version\HyBi10; use Ratchet\Application\WebSocket\Version\HyBi10;
/** /**
* @covers Ratchet\Protocol\WebSocket\Version\Hybi10 * @covers Ratchet\Application\WebSocket\Version\Hybi10
*/ */
class HyBi10Test extends \PHPUnit_Framework_TestCase { class HyBi10Test extends \PHPUnit_Framework_TestCase {
protected $_version; protected $_version;
@ -12,8 +12,11 @@ class HyBi10Test extends \PHPUnit_Framework_TestCase {
$this->_version = new HyBi10(); $this->_version = new HyBi10();
} }
/**
* Is this useful?
*/
public function testClassImplementsVersionInterface() { public function testClassImplementsVersionInterface() {
$constraint = $this->isInstanceOf('\\Ratchet\\Protocol\\WebSocket\\Version\\VersionInterface'); $constraint = $this->isInstanceOf('\\Ratchet\\Application\\WebSocket\\Version\\VersionInterface');
$this->assertThat($this->_version, $constraint); $this->assertThat($this->_version, $constraint);
} }

View File

@ -1,11 +1,11 @@
<?php <?php
namespace Ratchet\Tests\Protocol; namespace Ratchet\Tests\Protocol;
use Ratchet\Protocol\WebSocket; use Ratchet\Application\WebSocket\App as WebSocket;
use Ratchet\Tests\Mock\Socket; use Ratchet\Tests\Mock\Socket;
use Ratchet\Tests\Mock\Application; use Ratchet\Tests\Mock\Application;
/** /**
* @covers Ratchet\Protocol\WebSocket * @covers Ratchet\Application\WebSocket
*/ */
class WebSocketTest extends \PHPUnit_Framework_TestCase { class WebSocketTest extends \PHPUnit_Framework_TestCase {
protected $_ws; protected $_ws;
@ -15,12 +15,7 @@ class WebSocketTest extends \PHPUnit_Framework_TestCase {
} }
public function testServerImplementsServerInterface() { public function testServerImplementsServerInterface() {
$constraint = $this->isInstanceOf('\\Ratchet\\SocketObserver'); $constraint = $this->isInstanceOf('\\Ratchet\\ObserverInterface');
$this->assertThat($this->_ws, $constraint);
}
public function testServerImplementsProtocolInterface() {
$constraint = $this->isInstanceOf('\\Ratchet\\Protocol\ProtocolInterface');
$this->assertThat($this->_ws, $constraint); $this->assertThat($this->_ws, $constraint);
} }

View File

@ -1,6 +1,6 @@
<?php <?php
namespace Ratchet\Tests; namespace Ratchet\Tests;
use Ratchet\Server; use Ratchet\Application\Server\App as 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;
@ -15,7 +15,7 @@ class ServerTest extends \PHPUnit_Framework_TestCase {
public function setUp() { public function setUp() {
$this->_catalyst = new Socket; $this->_catalyst = new Socket;
$this->_app = new TestApp; $this->_app = new TestApp;
$this->_server = new Server($this->_catalyst, $this->_app); $this->_server = new Server($this->_app);
} }
protected function getPrivateProperty($class, $name) { protected function getPrivateProperty($class, $name) {
@ -26,30 +26,6 @@ class ServerTest extends \PHPUnit_Framework_TestCase {
return $property->getValue($class); return $property->getValue($class);
} }
public function testServerHasServerInterface() {
$constraint = $this->isInstanceOf('\\Ratchet\\SocketObserver');
$this->assertThat($this->_server, $constraint);
}
public function testIteration() {
$this->assertInstanceOf('\\Iterator', $this->_server->getIterator());
}
public function SKIPtestServerCanNotRunWithoutApplication() {
$this->setExpectedException('\\RuntimeException');
$this->_server->run();
}
/*
public function testAttatchedReceiverIsSet() {
$app = new TestApp();
$this->_server->attatchReceiver($app);
// todo, use proper assertions...can't look them up atm, no internet
$this->assertAttributeEquals(Array(spl_object_hash($app) => $app), '_receivers', $this->_server);
}
/**/
public function testBindToInvalidAddress() { public function testBindToInvalidAddress() {
return $this->markTestIncomplete(); return $this->markTestIncomplete();

View File

@ -23,12 +23,6 @@ class SocketTest extends \PHPUnit_Framework_TestCase {
$this->_socket = new Socket(); $this->_socket = new Socket();
} }
/*
public function testWhatGoesInConstructComesOut() {
$this->assertTrue(false);
}
*/
public function testGetDefaultConfigForConstruct() { public function testGetDefaultConfigForConstruct() {
$ref_conf = static::getMethod('getConfig'); $ref_conf = static::getMethod('getConfig');
$config = $ref_conf->invokeArgs($this->_socket, array()); $config = $ref_conf->invokeArgs($this->_socket, array());