2010-11-21 23:48:11 +01:00
< ? php
/**
* Abstract class that implements the basic api for any client .
* @ author jpt
* @ abstract
* @ package Client
*/
abstract class Client_AbstractClient {
/**
* @ var int
*/
protected $ID ;
/**
* @ var string
*/
protected $group ;
2010-11-28 01:04:35 +01:00
/**
* @ var mixed Instance of Protocol_AbstractProtocolHandler
*/
protected $protocolHandler ;
2010-11-21 23:48:11 +01:00
/**
* Contains a reference to the ClientManager in order to change stuff on the fly .
* @ var Client_ClientManager
*/
protected $clientManager ;
2010-11-28 01:04:35 +01:00
/**
* Injects ProtocolHandler
2010-11-28 02:15:20 +01:00
* @ param mixed $protocolHandler instance of Protocol_AbstractProtocolHandler
2010-11-28 01:04:35 +01:00
* @ return void
2010-12-01 00:25:15 +01:00
* @ throws Exception_WrongDatatypeException
2010-11-28 01:04:35 +01:00
*/
public function injectProtocolHandler ( $protocolHandler ) {
2010-12-01 00:25:15 +01:00
if ( ! $protocolHandler instanceof Protocol_AbstractProtocolHandler ) {
throw new Exception_WrongDatatypeException ( " Cannot inject ProtocolHandler! Expected an instance of Protocol_AbstractProtocolHandler, ' " . get_type ( $protocolHandler ) . " ' given. " , 1291156562 );
}
2010-11-28 01:04:35 +01:00
$this -> protocolHandler = $protocolHandler ;
}
/**
2010-12-02 23:34:12 +01:00
* Forwards incoming data to the ProtocolHandler
* Let ' s the ProtocolHandler do all the work and forward its results to the Clients .
* Return resulting raw data .
2010-11-28 01:04:35 +01:00
* @ param string $rawData
2010-11-28 02:24:16 +01:00
* @ return string
2010-11-28 01:04:35 +01:00
*/
2010-11-28 02:15:20 +01:00
public function processRawData ( $rawData ) {
2010-12-02 23:34:12 +01:00
$this -> protocolHandler -> pushRawData ( $rawData );
while ( $this -> protocolHandler -> canWork ()) {
$this -> processContentObject ( $this -> protocolHandler -> work ());
}
return $this -> protocolHandler -> getRawData ();
2010-11-28 01:04:35 +01:00
}
2010-11-21 23:48:11 +01:00
/**
* This function will be the main entry point of any client .
* @ param string $data
* @ return string
*/
2010-11-28 01:04:35 +01:00
abstract protected function processContentObject ( $contentObject );
2010-11-21 23:48:11 +01:00
/**
* This function will load the given config .
* @ param array $config
*/
abstract public function loadConfig ( $config );
2010-11-28 17:38:03 +01:00
/**
* Will reset the connectionStatus of the client .
* Implementation depends on the client .
* Should be used to reset internal variables .
* @ return void
*/
public function resetConnectionStatus () {
}
2010-11-21 23:48:11 +01:00
/**
* @ param int $id
*/
public function setID ( $id ) {
$this -> ID = $id ;
}
/**
* @ param string $group
*/
public function setGroup ( $group ) {
$this -> group = $group ;
}
/**
* Injects ClientManager
* @ param Client_ClientManager $clientManager
2010-12-01 00:25:15 +01:00
* @ throws Exception_WrongDatatypeException
2010-11-21 23:48:11 +01:00
*/
public function injectClientManager ( $clientManager ) {
2010-12-01 00:25:15 +01:00
if ( ! $clientManager instanceof Client_ClientManager ) {
throw new Exception_WrongDatatypeException ( " Cannot inject ClientManager! Expected an instance of Client_ClientManager, ' " . get_type ( $clientManager ) . " ' given. " , 1291156565 );
}
2010-11-21 23:48:11 +01:00
$this -> clientManager = $clientManager ;
}
}
?>