ircbot/Classes/Protocol/BotProtocolHandler.php
Jan Philipp Timme 8e32f35edf [TASK] Introduced addLine() to the buffer class.
[TASK] Made createBuffer function protected in ProtocolHandler classes.
2011-06-26 14:03:32 +00:00

52 lines
1.3 KiB
PHP

<?php
/**
* A 1:1 passthrough handler
* @author JPT
* @package Protocol
*/
class Protocol_BotProtocolHandler extends Protocol_AbstractProtocolHandler {
/**
* Is called by the constructor.
* Shall create the two buffers and set them up.
* @return void
*/
protected function createBuffers() {
$linebreak = "\r\n";
$this->bufferIncoming = new Misc_Buffer($linebreak);
$this->bufferOutgoing = new Misc_Buffer($linebreak);
}
/**
* Main worker function. It will be called in a loop.
* The returned ContentObject will be passed to the client.
* @return Protocol_BotProtocolContentObject
*/
public function work() {
$data = $this->bufferIncoming->getNextLine();
return new Protocol_BotProtocolContentObject($data);
}
/**
* Returns whether there is work to be done.
* Important in order to assure that a ContentObject is created and passed to the Client.
* @return boolean
*/
public function canWork() {
return $this->bufferIncoming->hasLines();
}
/**
* Will put raw data into the outgoing buffer.
* This function will be removed soon.
* The ProtocolHandler shall take care of this directly.
* @deprecated
* @param string $data
* @return void
*/
public function sendRaw($data) {
$this->bufferOutgoing->addLine($data);
}
}
?>