AutoLoader Class

This commit is contained in:
Steffen Schröder
2014-06-17 21:46:32 +02:00
parent 83aa2246c7
commit 2ff88c230b
2 changed files with 47 additions and 19 deletions

View File

@ -98,25 +98,9 @@ checkRequirements();
// Make sure garbage collection is enabled
gc_enable();
// Autoload Function that loads ManiaControl Class Files on Demand
spl_autoload_register(function ($className) {
$classPath = str_replace('\\', DIRECTORY_SEPARATOR, $className);
// Core file
$classDirectoryPath = preg_replace('/ManiaControl/', 'core', $classPath, 1);
$filePath = ManiaControlDir . $classDirectoryPath . '.php';
if (file_exists($filePath)) {
require_once $filePath;
return;
}
// Plugin file
$filePath = ManiaControlDir . 'plugins' . DIRECTORY_SEPARATOR . $classPath . '.php';
if (file_exists($filePath)) {
include_once $filePath;
return;
}
});
// Register AutoLoader
require_once ManiaControlDir . 'core' . DIRECTORY_SEPARATOR . 'AutoLoader.php';
\ManiaControl\AutoLoader::register();
// Start ManiaControl
$maniaControl = new \ManiaControl\ManiaControl();