[TASK] Finalized modifications on ClientManager.
[TASK] Added support for further class paths to ClassLoader. [TASK] Started to implement the irc client dispatcher. (partially works now)
This commit is contained in:
@@ -47,7 +47,9 @@ abstract class AbstractClientDispatcher implements \JPT\SocketFramework\Client\C
|
||||
* @param array $config
|
||||
* @return void
|
||||
*/
|
||||
abstract public function loadConfig($config);
|
||||
public function loadConfig($config) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Will reset the connectionStatus of the client.
|
||||
|
||||
@@ -26,7 +26,7 @@ interface ClientDispatcherInterface {
|
||||
* @param array $config
|
||||
* @return void
|
||||
*/
|
||||
abstract public function loadConfig($config);
|
||||
public function loadConfig($config);
|
||||
|
||||
/**
|
||||
* Will reset the connectionStatus of the client.
|
||||
|
||||
@@ -99,7 +99,7 @@ class ClientManager {
|
||||
foreach($this->connectionPool->getConnectionHandlers() AS $connectionHandler) {
|
||||
if(isset($this->clientDispatcherPool[$connectionHandler->getID()])) continue;
|
||||
//new connections might need a client, so we'll create one here.
|
||||
$this->addClientForConnectionHandler($connectionHandler);
|
||||
$this->addClientDispatcherForConnectionHandler($connectionHandler);
|
||||
//allow client to send initial stuff right after connecting to the server.
|
||||
$this->initializeClientForConnectionHandler($connectionHandler);
|
||||
}
|
||||
@@ -120,7 +120,7 @@ class ClientManager {
|
||||
}
|
||||
//handle accepted sockets, adopt them and treat them with care :-)
|
||||
if($connectionHandler->isListening() === TRUE) {
|
||||
$this->addClientForConnectionHandler($connectionHandler);
|
||||
$this->addClientDispatcherForConnectionHandler($connectionHandler);
|
||||
$this->initializeClientForConnectionHandler($connectionHandler);
|
||||
}
|
||||
|
||||
@@ -233,7 +233,7 @@ class ClientManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls Connection_Pool.
|
||||
* Calls \JPT\SocketFramework\Connection\ConnectionPool.
|
||||
*
|
||||
* @see \JPT\SocketFramework\Connection\ConnectionPool
|
||||
* @param string $group
|
||||
@@ -254,8 +254,8 @@ class ClientManager {
|
||||
*/
|
||||
protected function createClientDispatcherForProtocol($protocolIdentifier) {
|
||||
//look for the protocol
|
||||
if(!in_array($protocolIdentifier, $this->registeredClientDispatchers)) {
|
||||
throw new \JPT\SocketFramework\Exception\GeneralException("No client dispatcher is registered for protocol: '" . $protocol . "'!", 1290271651);
|
||||
if(isset($this->registeredClientDispatchers[$protocolIdentifier]) === FALSE) {
|
||||
throw new \JPT\SocketFramework\Exception\GeneralException("No client dispatcher is registered for protocol: '" . $protocolIdentifier . "'!", 1290271651);
|
||||
}
|
||||
$className = $this->registeredClientDispatchers[$protocolIdentifier];
|
||||
//look for the class
|
||||
@@ -265,7 +265,7 @@ class ClientManager {
|
||||
if(!$clientDispatcher instanceof \JPT\SocketFramework\Client\AbstractClientDispatcher) throw new \JPT\SocketFramework\Exception\GeneralException("Class '" . $className . "' does not implement the AbstractClientDispatcher-API!", 1294837055);
|
||||
return $clientDispatcher;
|
||||
} else {
|
||||
throw new \JPT\SocketFramework\Exception\GeneralException("Registered class name '" . $className . "' does not exist for protocol: '" . $protocol . "'!", 1290271773);
|
||||
throw new \JPT\SocketFramework\Exception\GeneralException("Registered class name '" . $className . "' does not exist for protocol: '" . $protocolIdentifier . "'!", 1290271773);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -277,6 +277,7 @@ class ClientManager {
|
||||
* @return void
|
||||
*/
|
||||
protected function initializeClientForConnectionHandler($connectionHandler) {
|
||||
if(!isset($this->clientDispatcherPool[$connectionHandler->getID()])) return;
|
||||
$this->clientDispatcherPool[$connectionHandler->getID()]->initializeConnection();
|
||||
//after initializing, have it process an empty string in order to get stuff to write. >.<
|
||||
$result = $this->clientDispatcherPool[$connectionHandler->getID()]->processRawData("");
|
||||
@@ -315,7 +316,7 @@ class ClientManager {
|
||||
* @return void
|
||||
*/
|
||||
protected function addClientDispatcherForConnectionHandler($connectionHandler) {
|
||||
$protocolIdentifier = $this->registeredProtocols[$connectionHandler->getProtocol()];
|
||||
$protocolIdentifier = $connectionHandler->getProtocol();
|
||||
//do not try this for "RAW" connections - might or might not be useful.
|
||||
if($protocolIdentifier === "RAW") return;
|
||||
$clientDispatcher = $this->createClientDispatcherForProtocol($protocolIdentifier);
|
||||
|
||||
@@ -8,20 +8,51 @@ namespace JPT\SocketFramework\Core;
|
||||
*/
|
||||
class ClassLoader {
|
||||
|
||||
/**
|
||||
* Contains class name prefix and path prefix for all class paths it shall handle
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $classNameMapping = array();
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
* Registers the main class path for the socket framework.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->classNameMapping = array(
|
||||
'JPT\SocketFramework' => 'SocketFramework' . \DIRECTORY_SEPARATOR . 'Classes'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a new class path for the autoloader
|
||||
*
|
||||
* @param string $classNamePrefix
|
||||
* @param string $pathPrefix
|
||||
*/
|
||||
public function addClassPathMapping($classNamePrefix, $pathPrefix) {
|
||||
$this->classNameMapping[$classNamePrefix] = $pathPrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Autoloader function.
|
||||
* All classes will be in Classes/$Package$/$ClassName$.php
|
||||
*
|
||||
* @throws \Exception
|
||||
* @param string $className
|
||||
* @return void
|
||||
*/
|
||||
public function loadClass($className) {
|
||||
if(substr($className, 0, 19) !== "JPT\\SocketFramework") return;
|
||||
$className = substr($className, 20);
|
||||
$fileName = "SocketFramework" . \DIRECTORY_SEPARATOR . "Classes";
|
||||
$fileName .= \DIRECTORY_SEPARATOR . str_replace("\\", \DIRECTORY_SEPARATOR, $className) . ".php";
|
||||
|
||||
$matchingClassNamePrefix = FALSE;
|
||||
foreach($this->classNameMapping AS $classNamePrefix => $pathPrefix) {
|
||||
if(substr($className, 0, strlen($classNamePrefix)) !== $classNamePrefix) continue;
|
||||
$matchingClassNamePrefix = TRUE;
|
||||
$classNameSuffix = substr($className, strlen($classNamePrefix), strlen($className));
|
||||
$fileName = $this->classNameMapping[$classNamePrefix];
|
||||
$fileName .= \DIRECTORY_SEPARATOR . str_replace('\\', \DIRECTORY_SEPARATOR, $classNameSuffix) . ".php";
|
||||
break;
|
||||
}
|
||||
if($matchingClassNamePrefix === FALSE) return;
|
||||
if(file_exists($fileName) === TRUE) {
|
||||
require_once($fileName);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user