Refactor autoload path creation in autoload.php
In this commit, code in autoload.php has been refactored to improve readability by using DIRECTORY_SEPARATOR for creating file paths. This ensures cross-platform compatibility. Additionally, added 'function' directory to class autoload procedure to facilitate future function based autoloads.
This commit is contained in:
parent
a9265dc4d8
commit
38c0e292ac
@ -9,13 +9,14 @@ const GAME_VERSION = 'alpha-7.4';
|
|||||||
require_once 'mysql_override.php';
|
require_once 'mysql_override.php';
|
||||||
|
|
||||||
spl_autoload_register(function (string $className) {
|
spl_autoload_register(function (string $className) {
|
||||||
$rootdir = $_SERVER['DOCUMENT_ROOT'] . '/_incl_data';
|
$rootdir = $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '_incl_data' . DIRECTORY_SEPARATOR;
|
||||||
# 1 with namespaces
|
# 1 with namespaces
|
||||||
# 2 without
|
# 2 without
|
||||||
$fileName = [
|
$fileName = [
|
||||||
$rootdir . '/class/' . str_replace('\\', DIRECTORY_SEPARATOR, $className . '.php'),
|
$rootdir . 'class' . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $className . '.php'),
|
||||||
$rootdir . '/class/' . $className . '.php',
|
$rootdir . 'class' . DIRECTORY_SEPARATOR . $className . '.php',
|
||||||
$rootdir . '/vendor/' . $className . '.php',
|
$rootdir . 'function' . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $className . '.php'),
|
||||||
|
$rootdir . 'vendor' . DIRECTORY_SEPARATOR . $className . '.php',
|
||||||
];
|
];
|
||||||
foreach ($fileName as $file) {
|
foreach ($fileName as $file) {
|
||||||
if (file_exists($file)) {
|
if (file_exists($file)) {
|
||||||
@ -26,7 +27,7 @@ spl_autoload_register(function (string $className) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
spl_autoload_register(function (string $classname) {
|
spl_autoload_register(function (string $classname) {
|
||||||
$rootdir = $_SERVER['DOCUMENT_ROOT'] . '/_incl_data';
|
$rootdir = $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '_incl_data';
|
||||||
$classMap = [
|
$classMap = [
|
||||||
'NewCombats' => $rootdir . '/class/',
|
'NewCombats' => $rootdir . '/class/',
|
||||||
'Insallah' => $rootdir . '/class/Insallah/',
|
'Insallah' => $rootdir . '/class/Insallah/',
|
||||||
|
Loading…
Reference in New Issue
Block a user