From 9915f66b0b30bf12a673ed8142a3e7c5ebaf158a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20Schro=CC=88der?= Date: Sat, 15 Feb 2014 16:09:22 +0100 Subject: [PATCH] improved autoload to support namespace-based file hierarchy in plugins directory --- application/ManiaControl.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/application/ManiaControl.php b/application/ManiaControl.php index bd032986..d3a22b5f 100644 --- a/application/ManiaControl.php +++ b/application/ManiaControl.php @@ -58,10 +58,20 @@ function logMessage($message) { // 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'; + + // Core file + $classDirectoryPath = preg_replace('/ManiaControl/', 'core', $classPath, 1); + $filePath = ManiaControlDir . DIRECTORY_SEPARATOR . $classDirectoryPath . '.php'; if (file_exists($filePath)) { require_once $filePath; + return; + } + + // Plugin file + $filePath = ManiaControlDir . DIRECTORY_SEPARATOR . 'plugins/' . $classPath . '.php'; + if (file_exists($filePath)) { + require_once $filePath; + return; } });