Folder restructure

Just reorganized the folders.  Namespacing broken, unit tests broken, nothing works.
This commit is contained in:
Chris Boden 2011-11-12 14:29:10 -05:00
parent 021a185753
commit 5386b4c066
26 changed files with 80 additions and 2 deletions

View File

@ -4,6 +4,7 @@ use Ratchet\Protocol\WebSocket\Version\VersionInterface;
/**
* A representation of a Socket connection of the user on the other end of the socket
* @todo Replace this with Resource\Connection\ConnectionInterface
*/
class Client {
/**

View File

@ -6,6 +6,7 @@ namespace Ratchet;
* @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 adding __construct(SocketObserver $decorator = null) - on Server move Socket as parameter to run()
* @todo Does this belong in \Ratchet\Server\?
*/
interface SocketObserver {
/**

View File

@ -0,0 +1,39 @@
<?php
namespace Ratchet\Server;
use Ratchet\SocketInterface;
/**
* @todo Should I build the commands into this class? They'd be executed by the Server...
*/
class Connection implements ConnectionInterface {
/**
* @var int
*/
protected $_id;
protected $_data = array();
public function __construct(SocketInterface $socket) {
$this->_id = (string)$socket->getResource();
$this->_id = (int)substr($this->_id, strrpos($this->_id, '#') + 1);
}
/**
* @return int
*/
public function getID() {
return $this->_id;
}
public function set($name, $val) {
$this->_data[$name] = $val;
}
public function get($name) {
if (!isset($this->_data[$name])) {
throw new \UnexpectedValueException("Attribute '{$name}' not found in Connection {$this->getID()}");
}
return $this->_data[$name];
}
}

View File

@ -0,0 +1,30 @@
<?php
namespace Ratchet\Server;
use Ratchet\SocketInterface;
interface ConnectionInterface {
/**
* The socket this representative connection is tied to
* @param Ratchet\SocketInterface
*/
function __construct(SocketInterface $socket);
/**
* @return scalar
*/
function getID();
/**
* Set an attribute to the connection
* @param string
* @param mixed
*/
function set($name, $val);
/**
* Get a previously set attribute bound to the connection
* @return mixed
* @throws \UnexpectedValueException
*/
function get($name);
}

View File

@ -5,6 +5,11 @@ namespace Ratchet;
* An object-oriented container for a single socket connection
*/
interface SocketInterface {
/**
* @return resource
*/
public function getResource();
/**
* Send text to the client on the other end of the socket
* @param string
@ -14,9 +19,11 @@ interface SocketInterface {
/**
* Called when the client sends data to the server through the socket
* @param string
* @param int
* @param string Variable to write data to
* @param int Number of bytes to read
* @param int
* @return int Number of bytes received
* @throws Exception
*/
function recv(&$buf, $len, $flags);