Не грузило классы из глубоких вложенных папок.

This commit is contained in:
Ivor Barhansky 2023-04-15 22:18:08 +03:00
parent f92aa003ac
commit bdda3d24a0

View File

@ -9,11 +9,12 @@ require_once 'mysql_override.php';
require_once 'class/Insallah/Config.php';
spl_autoload_register(function (string $className) {
$rootdir = getcwd() . '/_incl_data';
# 1 with namespaces
# 2 without
$fileName = [
__DIR__ . '/class/' . str_replace('\\', DIRECTORY_SEPARATOR, $className . '.php'),
__DIR__ . '/class/' . $className . '.php'
$rootdir . '/class/' . str_replace('\\', DIRECTORY_SEPARATOR, $className . '.php'),
$rootdir . '/class/' . $className . '.php'
];
foreach ($fileName as $file) {
if (file_exists($file)) {
@ -24,10 +25,11 @@ spl_autoload_register(function (string $className) {
});
spl_autoload_register(function (string $classname) {
$rootdir = getcwd() . '/_incl_data';
$classMap = [
'NewCombats' => __DIR__ . '/class/',
'Insallah' => __DIR__ . '/class/Insallah/',
'DarksLight2' => __DIR__ . '/class/DarksLight2/',
'NewCombats' => $rootdir . '/class/',
'Insallah' => $rootdir . '/class/Insallah/',
'DarksLight2' => $rootdir . '/class/DarksLight2/',
];
$parts = explode('\\', $classname);
$namespace = array_shift($parts);