[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:
Jan Philipp Timme
2011-12-03 20:58:08 +01:00
parent 16ff75eb1d
commit e702124895
7 changed files with 90 additions and 54 deletions
+37 -6
View File
@@ -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 {