2014-06-17 21:46:32 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace ManiaControl;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ManiaControl AutoLoader
|
|
|
|
*
|
|
|
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
2016-05-04 09:57:31 +02:00
|
|
|
* @copyright 2014-2016 ManiaControl Team
|
2014-06-17 21:46:32 +02:00
|
|
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
|
|
|
*/
|
2014-06-20 15:17:52 +02:00
|
|
|
abstract class AutoLoader {
|
2014-06-17 21:46:32 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Register the Auto Loader
|
|
|
|
*/
|
|
|
|
public static function register() {
|
|
|
|
spl_autoload_register(array(get_class(), 'autoload'));
|
2014-06-20 14:29:17 +02:00
|
|
|
}
|
2014-06-20 15:17:52 +02:00
|
|
|
|
2014-06-17 21:46:32 +02:00
|
|
|
/**
|
|
|
|
* Try to autoload the Class with the given Name
|
|
|
|
*
|
|
|
|
* @param string $className
|
|
|
|
*/
|
|
|
|
public static function autoload($className) {
|
|
|
|
$classPath = str_replace('\\', DIRECTORY_SEPARATOR, $className);
|
|
|
|
|
|
|
|
// Core file
|
2014-08-08 14:38:45 +02:00
|
|
|
$coreClassPath = preg_replace('/ManiaControl/', 'core', $classPath, 1);
|
2014-08-08 14:41:58 +02:00
|
|
|
$coreFilePath = MANIACONTROL_PATH . $coreClassPath . '.php';
|
2014-08-08 14:38:45 +02:00
|
|
|
if (file_exists($coreFilePath)) {
|
|
|
|
include_once $coreFilePath;
|
2014-06-17 21:46:32 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-01 03:52:14 +02:00
|
|
|
// Other file
|
|
|
|
$paths = array('plugins', 'libs', 'libs' . DIRECTORY_SEPARATOR . 'curl-easy');
|
|
|
|
foreach ($paths as $path) {
|
|
|
|
$filePath = MANIACONTROL_PATH . $path . DIRECTORY_SEPARATOR . $classPath . '.php';
|
|
|
|
if (file_exists($filePath)) {
|
|
|
|
include_once $filePath;
|
|
|
|
return;
|
|
|
|
}
|
2014-06-17 21:46:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|