autoload function

This commit is contained in:
Steffen Schröder 2014-01-27 09:07:25 +01:00
parent 82089b6ea0
commit dfe07ae8dc

View File

@ -48,6 +48,7 @@ function logMessage($message) {
/** /**
* Get the prefix for the given error level * Get the prefix for the given error level
*
* @param int $errorLevel * @param int $errorLevel
* @return string * @return string
*/ */
@ -91,7 +92,17 @@ set_error_handler(
return false; return false;
}, -1); }, -1);
// Autoload Function that loads ManiaControl Class Files on Demand
spl_autoload_register(
function ($className) {
$classPath = str_replace('\\', DIRECTORY_SEPARATOR, $className);
$classPath = preg_replace('/ManiaControl/', 'core', $classPath, 1);
$filePath = ManiaControlDir . DIRECTORY_SEPARATOR . $classPath . '.php';
if (file_exists($filePath)) {
require_once $filePath;
}
});
// Start ManiaControl // Start ManiaControl
require_once __DIR__ . '/core/ManiaControl.php'; $maniaControl = new \ManiaControl\ManiaControl();
$maniaControl = new ManiaControl\ManiaControl();
$maniaControl->run(); $maniaControl->run();