PHP Class Wrench\Payload\Payload

Represents a WebSocket protocol payload, which may be made up of multiple frames.
Show file Open project: varspool/Wrench Class Usage Examples

Protected Properties

Property Type Description
$buffer String representation of the payload contents
$frames Wrench\Frame\Frame[] A payload may consist of one or more frames

Public Methods

Method Description
__toString ( ) : string
encode ( string $data, integer $type = Protocol::TYPE_TEXT, boolean $masked = false ) : Payload Encodes a payload
getPayload ( ) : string
getRemainingData ( ) : number | null Gets the number of remaining bytes before this payload will be complete
getType ( ) : integer Gets the type of the payload
isComplete ( ) : boolean Whether the payload is complete
isWaitingForData ( ) : boolean Whether this payload is waiting for more data
receiveData ( string $data ) : void Receive raw data into the payload
sendToSocket ( Socket $socket ) : boolean

Protected Methods

Method Description
getCurrentFrame ( ) : mixed Gets the current frame for the payload
getFrame ( ) : Wrench\Frame\Frame Get a frame object
getReceivingFrame ( ) : Wrench\Frame\Frame Gets the frame into which data should be receieved

Method Details

__toString() public method

public __toString ( ) : string
return string

encode() public method

Encodes a payload
public encode ( string $data, integer $type = Protocol::TYPE_TEXT, boolean $masked = false ) : Payload
$data string
$type integer
$masked boolean
return Payload

getCurrentFrame() protected method

Gets the current frame for the payload
protected getCurrentFrame ( ) : mixed
return mixed

getFrame() abstract protected method

Get a frame object
abstract protected getFrame ( ) : Wrench\Frame\Frame
return Wrench\Frame\Frame

getPayload() public method

public getPayload ( ) : string
return string

getReceivingFrame() protected method

Gets the frame into which data should be receieved
protected getReceivingFrame ( ) : Wrench\Frame\Frame
return Wrench\Frame\Frame

getRemainingData() public method

May return 0 (no more bytes required) or null (unknown number of bytes required).
public getRemainingData ( ) : number | null
return number | null

getType() public method

The type of a payload is taken from its first frame
public getType ( ) : integer
return integer

isComplete() public method

Whether the payload is complete
public isComplete ( ) : boolean
return boolean

isWaitingForData() public method

Whether this payload is waiting for more data
public isWaitingForData ( ) : boolean
return boolean

receiveData() public method

Receive raw data into the payload
public receiveData ( string $data ) : void
$data string
return void

sendToSocket() public method

public sendToSocket ( Socket $socket ) : boolean
$socket Wrench\Socket\Socket
return boolean

Property Details

$buffer protected property

String representation of the payload contents
protected $buffer

$frames protected property

A payload may consist of one or more frames
protected Frame[],Wrench\Frame $frames
return Wrench\Frame\Frame[]