diff --git a/Classes/Client/AbstractClient.php b/Classes/Client/AbstractClient.php index 0d0d7b7..8ac20c1 100644 --- a/Classes/Client/AbstractClient.php +++ b/Classes/Client/AbstractClient.php @@ -17,18 +17,43 @@ abstract class Client_AbstractClient { */ protected $group; + /** + * @var mixed Instance of Protocol_AbstractProtocolHandler + */ + protected $protocolHandler; + /** * Contains a reference to the ClientManager in order to change stuff on the fly. * @var Client_ClientManager */ protected $clientManager; + /** + * Injects ProtocolHandler + * @param unknown_type $protocolHandler + * @return void + */ + public function injectProtocolHandler($protocolHandler) { + $this->protocolHandler = $protocolHandler; + } + + /** + * Forwards incoming data to the ProtocolParser. + * Calls protected processData() + * @param string $rawData + * @return void + */ + public function putRawData($rawData) { + $contentObject = $this->protocolHandler->parse($rawData); + $this->processContentObject($contentObject); + } + /** * This function will be the main entry point of any client. * @param string $data * @return string */ - abstract public function processData($data); + abstract protected function processContentObject($contentObject); /** * This function will load the given config. @@ -50,7 +75,6 @@ abstract class Client_AbstractClient { $this->group = $group; } - /** * Injects ClientManager * @param Client_ClientManager $clientManager diff --git a/Classes/Client/ClientManager.php b/Classes/Client/ClientManager.php index 6865f58..1c5dbdd 100644 --- a/Classes/Client/ClientManager.php +++ b/Classes/Client/ClientManager.php @@ -178,6 +178,7 @@ class Client_ClientManager { $client->loadConfig($this->configPool[$connectionHandler->getID()]); } $client->injectClientManager($this); + $client->injectProtocolHandler(new Protocol_IrcProtocolHandler()); $client->setID($connectionHandler->getID()); $client->setGroup($connectionHandler->getGroup()); $this->clientPool[$connectionHandler->getID()] = $client; diff --git a/Classes/Client/IrcClient.php b/Classes/Client/IrcClient.php index cf91bf3..9b06ced 100644 --- a/Classes/Client/IrcClient.php +++ b/Classes/Client/IrcClient.php @@ -16,6 +16,7 @@ class Client_IrcClient extends Client_AbstractClient { /** * Default constructor. + * @return void */ function __construct() { $this->nick = "Serena"; @@ -31,7 +32,8 @@ class Client_IrcClient extends Client_AbstractClient { * @param string $data * @return string */ - public function processData($data) { + public function processContentObject($contentObject) { + $data = $contentObject->rawData; //echo "[RECV] ".$data; $this->clientManager->sendToGroup("srv", "[#".$this->ID."] ".$data."\r\n\r\n"); diff --git a/Classes/Protocol/AbstractProtocolContentObject.php b/Classes/Protocol/AbstractProtocolContentObject.php new file mode 100644 index 0000000..a9b203d --- /dev/null +++ b/Classes/Protocol/AbstractProtocolContentObject.php @@ -0,0 +1,26 @@ +rawData = $rawData; + } +} +?> \ No newline at end of file diff --git a/Classes/Protocol/AbstractProtocolHandler.php b/Classes/Protocol/AbstractProtocolHandler.php index fe5885c..cf87df6 100644 --- a/Classes/Protocol/AbstractProtocolHandler.php +++ b/Classes/Protocol/AbstractProtocolHandler.php @@ -11,7 +11,7 @@ abstract class Protocol_AbstractProtocolHandler { /** * Parses incoming data, returns a ProtocolObject * @param string $data - * @return Protocol_ProtocolObejct + * @return mixed instance of Protocol_AbstractProtocolContentObject */ abstract public function parse($data); diff --git a/Classes/Protocol/IrcProtocolContentObject.php b/Classes/Protocol/IrcProtocolContentObject.php new file mode 100644 index 0000000..e3d8335 --- /dev/null +++ b/Classes/Protocol/IrcProtocolContentObject.php @@ -0,0 +1,10 @@ + \ No newline at end of file diff --git a/Classes/Protocol/IrcProtocolHandler.php b/Classes/Protocol/IrcProtocolHandler.php new file mode 100644 index 0000000..c4e87b5 --- /dev/null +++ b/Classes/Protocol/IrcProtocolHandler.php @@ -0,0 +1,17 @@ + \ No newline at end of file