[TASK] Introducing the ProtocolHandler
This commit is contained in:
parent
f3b1354aa2
commit
bdd9f671ad
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
/**
|
||||
* The abstract ContentObject that will contain
|
||||
* "parsed data" from the ProtocolHandler
|
||||
* @author JPT
|
||||
* @abstract
|
||||
* @package Protocol
|
||||
*/
|
||||
abstract class Protocol_AbstractProtocolContentObject {
|
||||
|
||||
/**
|
||||
* Contains the raw data.
|
||||
* @var string
|
||||
*/
|
||||
public $rawData;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
* Sets the rawData field.
|
||||
* @return void
|
||||
*/
|
||||
function __construct($rawData) {
|
||||
$this->rawData = $rawData;
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
/**
|
||||
* ContentObject for IRC Protocol
|
||||
* @author JPT
|
||||
* @package Protocol
|
||||
*/
|
||||
class Protocol_IrcProtocolContentObject extends Protocol_AbstractProtocolContentObject {
|
||||
|
||||
}
|
||||
?>
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
/**
|
||||
* The ProtocolHandler for the IRC Protocol.
|
||||
* @author JPT
|
||||
* @package Protocol
|
||||
*/
|
||||
class IrcProtocolHandler extends Protocol_AbstractProtocolHandler {
|
||||
|
||||
/**
|
||||
* @param string $data
|
||||
* @return Protocol_IrcProtocolContentObject
|
||||
*/
|
||||
public function parse($data) {
|
||||
return new Protocol_IrcProtocolContentObject($data);
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Reference in New Issue