Interface change

Changed onRecv to onMessage in Interface to match a standard api
Removed Frame::__toString methods - could imply different return expectation
This commit is contained in:
Chris Boden 2011-11-20 14:46:15 -05:00
parent 923b936e42
commit 02ffd6f782
11 changed files with 20 additions and 27 deletions

View File

@ -58,7 +58,7 @@ class Chat implements ApplicationInterface {
$this->_clients->attach($conn);
}
public function onRecv(Connection $from, $msg) {
public function onMessage(Connection $from, $msg) {
$commands = new Cmds;
foreach ($this->_clients as $client) {

View File

@ -23,7 +23,7 @@ interface ApplicationInterface {
* @param string The message received
* @return Ratchet\Resource\Command\CommandInterface|null
*/
function onRecv(Connection $from, $msg);
function onMessage(Connection $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.

View File

@ -110,7 +110,7 @@ class App implements ApplicationInterface {
}
*/
$res = $this->onRecv($conn, $data);
$res = $this->onMessage($conn, $data);
} else {
$res = $this->onClose($conn);
}
@ -144,8 +144,8 @@ class App implements ApplicationInterface {
return $this->_app->onOpen($new_connection);
}
public function onRecv(Connection $from, $msg) {
return $this->_app->onRecv($from, $msg);
public function onMessage(Connection $from, $msg) {
return $this->_app->onMessage($from, $msg);
}
public function onClose(Connection $conn) {

View File

@ -66,7 +66,7 @@ class App implements ApplicationInterface, ConfiguratorInterface {
$conn->WebSocket->headers = '';
}
public function onRecv(Connection $from, $msg) {
public function onMessage(Connection $from, $msg) {
if (true !== $from->WebSocket->handshake) {
if (!isset($from->WebSocket->version)) {
try {
@ -125,7 +125,7 @@ class App implements ApplicationInterface, ConfiguratorInterface {
}
if ($from->WebSocket->message->isCoalesced()) {
$cmds = $this->prepareCommand($this->_app->onRecv($from, (string)$from->WebSocket->message));
$cmds = $this->prepareCommand($this->_app->onMessage($from, (string)$from->WebSocket->message));
unset($from->WebSocket->message);
return $cmds;

View File

@ -2,11 +2,6 @@
namespace Ratchet\Application\WebSocket\Version;
interface FrameInterface {
/**
* @alias getPayload
*/
function __toString();
/**
* Dunno if I'll use this
* Thinking could be used if a control frame?

View File

@ -12,10 +12,6 @@ class Frame implements FrameInterface {
*/
protected $_data = '';
public function __toString() {
return $this->getPayload();
}
public function isCoalesced() {
return (boolean)($this->_data[0] == chr(0) && substr($this->_data, -1) == chr(255));
}

View File

@ -27,10 +27,6 @@ class Frame implements FrameInterface {
*/
protected $_pay_check = -1;
public function __toString() {
return (string)$this->getPayload();
}
public function isCoalesced() {
try {
$payload_length = $this->getPayloadLength();

View File

@ -55,7 +55,7 @@ class Message implements MessageInterface {
$buffer = '';
foreach ($this->_frames as $frame) {
$buffer .= (string)$frame;
$buffer .= $frame->getPayload();
}
return $buffer;

View File

@ -21,7 +21,7 @@ interface ObserverInterface {
* @param string The message received
* @return Ratchet\Resource\Command\CommandInterface|null
*/
function onRecv(SocketInterface $from, $msg);
function onMessage(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.

View File

@ -1,6 +1,7 @@
<?php
namespace Ratchet\Tests\Application\WebSocket\Version;
use Ratchet\Application\WebSocket\Version\HyBi10;
use Ratchet\Application\WebSocket\Version\HyBi10\Frame;
/**
* @covers Ratchet\Application\WebSocket\Version\Hybi10
@ -38,8 +39,11 @@ class HyBi10Test extends \PHPUnit_Framework_TestCase {
* @dataProvider UnframeMessageProvider
*/
public function testUnframeMessage($message, $framed) {
$decoded = $this->_version->unframe(base64_decode($framed));
$this->assertEquals($message, $decoded['payload']);
// $decoded = $this->_version->unframe(base64_decode($framed));
$frame = new Frame;
$frame->addBuffer(base64_decode($framed));
$this->assertEquals($message, $frame->getPayload());
}
public static function UnframeMessageProvider() {
@ -54,8 +58,10 @@ class HyBi10Test extends \PHPUnit_Framework_TestCase {
public function testUnframeMatchesPreFraming() {
$string = 'Hello World!';
$framed = $this->_version->frame($string);
$unframed = $this->_version->unframe($framed);
$this->assertEquals($string, $unframed['payload']);
$frame = new Frame;
$frame->addBuffer($framed);
$this->assertEquals($string, $frame->getPayload());
}
}

View File

@ -26,7 +26,7 @@ class Application implements ApplicationInterface {
$this->_conn_open = $conn;
}
public function onRecv(Connection $from, $msg) {
public function onMessage(Connection $from, $msg) {
$this->_conn_recv = $from;
$this->_msg_recv = $msg;
}