Added __toString fn to DataInterface

This commit is contained in:
Chris Boden 2015-12-25 13:14:15 -05:00
parent 01ed6ecf72
commit 31d2618057
3 changed files with 28 additions and 14 deletions

View File

@ -25,4 +25,10 @@ interface DataInterface {
* @return string * @return string
*/ */
function getContents(); function getContents();
/**
* Should return the unmasked payload received from peer
* @return string
*/
function __toString();
} }

View File

@ -429,13 +429,7 @@ class Frame implements FrameInterface {
throw call_user_func($this->ufeg, 'Can not return partial message'); throw call_user_func($this->ufeg, 'Can not return partial message');
} }
$payload = substr($this->data, $this->getPayloadStartingByte(), $this->getPayloadLength()); return $this->__toString();
if ($this->isMasked()) {
$payload = $this->applyMask($this->getMaskingKey(), $payload);
}
return $payload;
} }
/** /**
@ -446,6 +440,16 @@ class Frame implements FrameInterface {
return substr($this->data, 0, $this->getPayloadStartingByte() + $this->getPayloadLength()); return substr($this->data, 0, $this->getPayloadStartingByte() + $this->getPayloadLength());
} }
public function __toString() {
$payload = (string)substr($this->data, $this->getPayloadStartingByte(), $this->getPayloadLength());
if ($this->isMasked()) {
$payload = $this->applyMask($this->getMaskingKey(), $payload);
}
return $payload;
}
/** /**
* Sometimes clients will concatenate more than one frame over the wire * Sometimes clients will concatenate more than one frame over the wire
* This method will take the extra bytes off the end and return them * This method will take the extra bytes off the end and return them

View File

@ -78,13 +78,7 @@ class Message implements \IteratorAggregate, MessageInterface {
throw new \UnderflowException('Message has not been put back together yet'); throw new \UnderflowException('Message has not been put back together yet');
} }
$buffer = ''; return $this->__toString();
foreach ($this->_frames as $frame) {
$buffer .= $frame->getPayload();
}
return $buffer;
} }
/** /**
@ -104,6 +98,16 @@ class Message implements \IteratorAggregate, MessageInterface {
return $buffer; return $buffer;
} }
public function __toString() {
$buffer = '';
foreach ($this->_frames as $frame) {
$buffer .= $frame->getPayload();
}
return $buffer;
}
/** /**
* @return boolean * @return boolean
*/ */