mirror of
https://github.com/Shadowss/TravianZ.git
synced 2026-06-28 00:24:23 +00:00
Incremental Refactor Market/Message/Profile
Incremental Refactor Market/Message/Profile
This commit is contained in:
+28
-15
@@ -6,6 +6,7 @@
|
||||
## Project: TravianZ ##
|
||||
## Filename autoloader.php ##
|
||||
## Developed by: Dzoki ##
|
||||
## Refactored by: Shadow ##
|
||||
## License: TravianZ Project ##
|
||||
## Copyright: TravianZ (c) 2010-2026. All rights reserved. ##
|
||||
## URLs: http://travian.shadowss.ro ##
|
||||
@@ -13,25 +14,37 @@
|
||||
## ##
|
||||
#################################################################################
|
||||
|
||||
function autoloadClass($class) {
|
||||
// strip the App classname's namespace
|
||||
$clazz = str_replace(['App\\', '\\'], ['', '/'], $class);
|
||||
function autoloadClass($class) {
|
||||
|
||||
// search for class
|
||||
$class_found = false;
|
||||
// go max 5 levels up - we don't have folders that go deeper than that
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$autoprefix = str_repeat('../', $i);
|
||||
if (file_exists($autoprefix.'src/' . $clazz . '.php')) {
|
||||
$class_found = true;
|
||||
include_once $autoprefix.'src/' . $clazz . '.php';
|
||||
break;
|
||||
}
|
||||
$clazz = str_replace(['App\\', '\\'], ['', '/'], $class);
|
||||
|
||||
$class_found = false;
|
||||
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$autoprefix = str_repeat('../', $i);
|
||||
|
||||
// 1. default path (actual)
|
||||
$path1 = $autoprefix . 'src/' . $clazz . '.php';
|
||||
|
||||
// 2. fallback GameEngine (YOUR CASE)
|
||||
$path2 = $autoprefix . 'GameEngine/' . $clazz . '.php';
|
||||
|
||||
if (file_exists($path1)) {
|
||||
include_once $path1;
|
||||
$class_found = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!$class_found) {
|
||||
throw new Exception('Unable to find class ' . $clazz . '.');
|
||||
if (file_exists($path2)) {
|
||||
include_once $path2;
|
||||
$class_found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$class_found) {
|
||||
throw new Exception('Unable to find class ' . $clazz . '.');
|
||||
}
|
||||
}
|
||||
|
||||
spl_autoload_register('autoloadClass');
|
||||
Reference in New Issue
Block a user