Folder restructure
Just reorganized the folders. Namespacing broken, unit tests broken, nothing works.
This commit is contained in:
parent
021a185753
commit
5386b4c066
@ -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 {
|
||||
/**
|
@ -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 {
|
||||
/**
|
39
lib/Ratchet/Resource/Connection/Connection.php
Normal file
39
lib/Ratchet/Resource/Connection/Connection.php
Normal 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];
|
||||
}
|
||||
}
|
30
lib/Ratchet/Resource/Connection/ConnectionInterface.php
Normal file
30
lib/Ratchet/Resource/Connection/ConnectionInterface.php
Normal 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);
|
||||
}
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user