[TASK] Moved the project to namespaces.
[TASK] Removed all the protocol handlers. [TASK] Clients are no longer part of the SocketFramework itself. [TASK] The Framework provides an "interface" to external clients - the ClientDispatcher. [TASK] Added the Core package and added a better ClassLoader. [TASK] Created a bootstrap module to include in other projects. [TASK] Cleaned up comments, reformatted them.
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
namespace JPT\SocketFramework\Core;
|
||||
|
||||
/**
|
||||
* Simple class to capsule the classloader so more than one autoload function can be used.
|
||||
*
|
||||
* @author JPT
|
||||
*/
|
||||
class ClassLoader {
|
||||
|
||||
/**
|
||||
* 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";
|
||||
|
||||
if(file_exists($fileName) === TRUE) {
|
||||
require_once($fileName);
|
||||
} else {
|
||||
throw new \Exception("Could not load class: '" . $className . "' - File does not exist: '" . $fileName . "'!", 1289659295);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple function that registers loadClass as an autoloader.
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception in case spl_autoload_register fails.
|
||||
*/
|
||||
public function initialize() {
|
||||
spl_autoload_register(array($this, 'loadClass'), TRUE, TRUE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user