From dfe07ae8dc2471abbf8d773ed1f4325a5696ffbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20Schro=CC=88der?= Date: Mon, 27 Jan 2014 09:07:25 +0100 Subject: [PATCH] autoload function --- application/ManiaControl.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/application/ManiaControl.php b/application/ManiaControl.php index 25fce25e..71406a10 100644 --- a/application/ManiaControl.php +++ b/application/ManiaControl.php @@ -48,6 +48,7 @@ function logMessage($message) { /** * Get the prefix for the given error level + * * @param int $errorLevel * @return string */ @@ -91,7 +92,17 @@ set_error_handler( return false; }, -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 -require_once __DIR__ . '/core/ManiaControl.php'; -$maniaControl = new ManiaControl\ManiaControl(); +$maniaControl = new \ManiaControl\ManiaControl(); $maniaControl->run();