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
*/
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');
}
$payload = substr($this->data, $this->getPayloadStartingByte(), $this->getPayloadLength());
if ($this->isMasked()) {
$payload = $this->applyMask($this->getMaskingKey(), $payload);
}
return $payload;
return $this->__toString();
}
/**
@ -446,6 +440,16 @@ class Frame implements FrameInterface {
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
* 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');
}
$buffer = '';
foreach ($this->_frames as $frame) {
$buffer .= $frame->getPayload();
}
return $buffer;
return $this->__toString();
}
/**
@ -104,6 +98,16 @@ class Message implements \IteratorAggregate, MessageInterface {
return $buffer;
}
public function __toString() {
$buffer = '';
foreach ($this->_frames as $frame) {
$buffer .= $frame->getPayload();
}
return $buffer;
}
/**
* @return boolean
*/