8e32f35edf
[TASK] Made createBuffer function protected in ProtocolHandler classes.
75 lines
1.8 KiB
PHP
75 lines
1.8 KiB
PHP
<?php
|
|
/**
|
|
* Abstract ProtocolHandler with the basic api.
|
|
* The ProtocolHandler contains two buffers for incoming and outgoing data.
|
|
* It will store the data and provide functions to add incoming and get outgoing data.
|
|
* @author jpt
|
|
* @abstract
|
|
* @package Protocol
|
|
* TODO: finish this shit
|
|
* TODO: Move the buffers here, they will be more useful.
|
|
*/
|
|
abstract class Protocol_AbstractProtocolHandler {
|
|
|
|
/**
|
|
* Buffer for data that was received by the Client.
|
|
* @var Misc_Buffer
|
|
*/
|
|
protected $bufferIncoming;
|
|
|
|
/**
|
|
* Buffer for data that will be sent by the Client.
|
|
* @var Misc_Buffer
|
|
*/
|
|
protected $bufferOutgoing;
|
|
|
|
/**
|
|
* This function will be called by the constructor.
|
|
* It will create the necessary instances of Misc_Buffer and
|
|
* put them in $bufferIncoming and $bufferOutgoing.
|
|
* @return void
|
|
*/
|
|
abstract protected function createBuffers();
|
|
|
|
/**
|
|
* General constructor.
|
|
* Calls createBuffers()
|
|
* @return void
|
|
*/
|
|
public function __construct() {
|
|
$this->createBuffers();
|
|
}
|
|
|
|
/**
|
|
* Returns whether work() can be called or not.
|
|
* Depends on the protocol and its implementation.
|
|
* @return boolean
|
|
*/
|
|
abstract public function canWork();
|
|
|
|
/**
|
|
* Main worker function of the ProtocolHandler.
|
|
* Will fetch data from the bufferIncoming, process it,
|
|
* and create a ProtocolContentObject out of it that will be returned to the client.
|
|
* @return mixed instance of Protocol_AbstractProtocolContentObject
|
|
*/
|
|
abstract public function work();
|
|
|
|
/**
|
|
* Adds the incoming data to the internal buffer.
|
|
* @param string $rawData
|
|
* @return void
|
|
*/
|
|
public function pushRawData($rawData) {
|
|
$this->bufferIncoming->addData($rawData);
|
|
}
|
|
|
|
/**
|
|
* Returns all outgoing data of the internal buffer.
|
|
* @return string
|
|
*/
|
|
public function getRawData() {
|
|
return $this->bufferOutgoing->getAllBufferContents();
|
|
}
|
|
}
|
|
?>
|