diff --git a/src/Messaging/Protocol/DataInterface.php b/src/Messaging/Protocol/DataInterface.php index 8d67774..2b0c675 100644 --- a/src/Messaging/Protocol/DataInterface.php +++ b/src/Messaging/Protocol/DataInterface.php @@ -25,4 +25,10 @@ interface DataInterface { * @return string */ function getContents(); + + /** + * Should return the unmasked payload received from peer + * @return string + */ + function __toString(); } diff --git a/src/Messaging/Protocol/Frame.php b/src/Messaging/Protocol/Frame.php index 88aa818..aaf8e0e 100644 --- a/src/Messaging/Protocol/Frame.php +++ b/src/Messaging/Protocol/Frame.php @@ -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 diff --git a/src/Messaging/Protocol/Message.php b/src/Messaging/Protocol/Message.php index 1b1ed17..b06e4b4 100644 --- a/src/Messaging/Protocol/Message.php +++ b/src/Messaging/Protocol/Message.php @@ -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 */