[TASK] Removed the linebreak from the buffers in the ConnectionHandler.
[TASK] Added a WrongDatatypeException [TASK] Started to implement the ProtocolHandler in a different way. [TASK] Started to put buffers into the ProtocolHandler. [!!!] Committing broken code.
This commit is contained in:
parent
5cb0714834
commit
c382cfe756
@ -32,8 +32,12 @@ abstract class Client_AbstractClient {
|
|||||||
* Injects ProtocolHandler
|
* Injects ProtocolHandler
|
||||||
* @param mixed $protocolHandler instance of Protocol_AbstractProtocolHandler
|
* @param mixed $protocolHandler instance of Protocol_AbstractProtocolHandler
|
||||||
* @return void
|
* @return void
|
||||||
|
* @throws Exception_WrongDatatypeException
|
||||||
*/
|
*/
|
||||||
public function injectProtocolHandler($protocolHandler) {
|
public function injectProtocolHandler($protocolHandler) {
|
||||||
|
if(!$protocolHandler instanceof Protocol_AbstractProtocolHandler) {
|
||||||
|
throw new Exception_WrongDatatypeException("Cannot inject ProtocolHandler! Expected an instance of Protocol_AbstractProtocolHandler, '" . get_type($protocolHandler) . "' given.", 1291156562);
|
||||||
|
}
|
||||||
$this->protocolHandler = $protocolHandler;
|
$this->protocolHandler = $protocolHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,8 +48,8 @@ abstract class Client_AbstractClient {
|
|||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function processRawData($rawData) {
|
public function processRawData($rawData) {
|
||||||
$contentObject = $this->protocolHandler->parse($rawData);
|
$contentObject = $this->protocolHandler->pushRawData($rawData);
|
||||||
return $this->processContentObject($contentObject);
|
return $this->processContentObject($this->protocolHandler->);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -88,8 +92,12 @@ abstract class Client_AbstractClient {
|
|||||||
/**
|
/**
|
||||||
* Injects ClientManager
|
* Injects ClientManager
|
||||||
* @param Client_ClientManager $clientManager
|
* @param Client_ClientManager $clientManager
|
||||||
|
* @throws Exception_WrongDatatypeException
|
||||||
*/
|
*/
|
||||||
public function injectClientManager($clientManager) {
|
public function injectClientManager($clientManager) {
|
||||||
|
if(!$clientManager instanceof Client_ClientManager) {
|
||||||
|
throw new Exception_WrongDatatypeException("Cannot inject ClientManager! Expected an instance of Client_ClientManager, '" . get_type($clientManager) . "' given.", 1291156565);
|
||||||
|
}
|
||||||
$this->clientManager = $clientManager;
|
$this->clientManager = $clientManager;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,7 @@ class Client_IrcClient extends Client_AbstractClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Processes the resulting ContentObject from a ProtocolHandler.
|
||||||
* Does all the hard work.
|
* Does all the hard work.
|
||||||
* @param string $data
|
* @param string $data
|
||||||
* @return string
|
* @return string
|
||||||
|
@ -13,6 +13,7 @@ class Connection_ConnectionHandler {
|
|||||||
/**
|
/**
|
||||||
* Buffer that contains incoming data.
|
* Buffer that contains incoming data.
|
||||||
* Contents were received from the SocketHandler.
|
* Contents were received from the SocketHandler.
|
||||||
|
* This buffer does not use a linebreak, it's a temporary store for data.
|
||||||
* @var Misc_Buffer
|
* @var Misc_Buffer
|
||||||
*/
|
*/
|
||||||
protected $buffer_incoming;
|
protected $buffer_incoming;
|
||||||
@ -20,6 +21,7 @@ class Connection_ConnectionHandler {
|
|||||||
/**
|
/**
|
||||||
* Buffer that contains outgoing data.
|
* Buffer that contains outgoing data.
|
||||||
* Contents will be sent to the SocketHandler.
|
* Contents will be sent to the SocketHandler.
|
||||||
|
* This buffer does not use a linebreak, it's a temporary store for data.
|
||||||
* @var Misc_Buffer
|
* @var Misc_Buffer
|
||||||
*/
|
*/
|
||||||
protected $buffer_outgoing;
|
protected $buffer_outgoing;
|
||||||
@ -85,9 +87,9 @@ class Connection_ConnectionHandler {
|
|||||||
* @param $linebreak
|
* @param $linebreak
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function __construct($socket, $id, $group = "", $protocol = "", $linebreak = "\r\n") {
|
function __construct($socket, $id, $group = "", $protocol = "") {
|
||||||
$this->buffer_incoming = new Misc_Buffer($linebreak);
|
$this->buffer_incoming = new Misc_Buffer();
|
||||||
$this->buffer_outgoing = new Misc_Buffer($linebreak);
|
$this->buffer_outgoing = new Misc_Buffer();
|
||||||
$this->socketHandler = new Socket_SocketHandler($socket);
|
$this->socketHandler = new Socket_SocketHandler($socket);
|
||||||
$this->id = $id;
|
$this->id = $id;
|
||||||
$this->group = $group;
|
$this->group = $group;
|
||||||
@ -202,12 +204,10 @@ class Connection_ConnectionHandler {
|
|||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function writeFromBuffer() {
|
public function writeFromBuffer() {
|
||||||
while($this->buffer_outgoing->hasLines()) {
|
$result = $this->socketHandler->write($this->buffer_outgoing->getAllBufferContents());
|
||||||
$result = $this->socketHandler->write($this->buffer_outgoing->getNextLine());
|
if($result === FALSE) {
|
||||||
if($result === FALSE) {
|
$this->shutdown();
|
||||||
$this->shutdown();
|
return FALSE;
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@ -226,7 +226,7 @@ class Connection_ConnectionHandler {
|
|||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function canRead() {
|
public function canRead() {
|
||||||
return $this->buffer_incoming->hasLines();
|
return $this->buffer_incoming->hasData();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -234,7 +234,7 @@ class Connection_ConnectionHandler {
|
|||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function canWrite() {
|
public function canWrite() {
|
||||||
return $this->buffer_outgoing->hasLines();
|
return $this->buffer_outgoing->hasData();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -243,7 +243,7 @@ class Connection_ConnectionHandler {
|
|||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function read() {
|
public function read() {
|
||||||
return $this->buffer_incoming->getNextLine();
|
return $this->buffer_incoming->getAllBufferContents();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
9
Classes/Exception/WrongDatatypeException.php
Normal file
9
Classes/Exception/WrongDatatypeException.php
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* WrongDatatypeException
|
||||||
|
* @author jpt
|
||||||
|
* @package Exception
|
||||||
|
* @exception
|
||||||
|
*/
|
||||||
|
class Exception_WrongDatatypeException extends Exception_GeneralException {}
|
||||||
|
?>
|
@ -94,5 +94,24 @@ class Misc_Buffer {
|
|||||||
return (trim(strstr($this->buffer, $this->linebreak, TRUE)) !== "") ? TRUE : FALSE;
|
return (trim(strstr($this->buffer, $this->linebreak, TRUE)) !== "") ? TRUE : FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns TRUE when there is data in the buffer.
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function hasData() {
|
||||||
|
return (strlen($this->buffer) > 0) ? TRUE : FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the full buffer contents.
|
||||||
|
* Also truncates the buffer.
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getAllBufferContents() {
|
||||||
|
$return = $this->buffer;
|
||||||
|
$this->buffer = "";
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
Loading…
x
Reference in New Issue
Block a user