From 38c0e292aca261d768867bf3a51e7d143b482af6 Mon Sep 17 00:00:00 2001 From: Ivor Barhansky Date: Sat, 9 Dec 2023 15:51:08 +0200 Subject: [PATCH] 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. --- _incl_data/autoload.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/_incl_data/autoload.php b/_incl_data/autoload.php index bf013444..865c3f24 100644 --- a/_incl_data/autoload.php +++ b/_incl_data/autoload.php @@ -9,13 +9,14 @@ const GAME_VERSION = 'alpha-7.4'; require_once 'mysql_override.php'; 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 # 2 without $fileName = [ - $rootdir . '/class/' . str_replace('\\', DIRECTORY_SEPARATOR, $className . '.php'), - $rootdir . '/class/' . $className . '.php', - $rootdir . '/vendor/' . $className . '.php', + $rootdir . 'class' . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $className . '.php'), + $rootdir . 'class' . DIRECTORY_SEPARATOR . $className . '.php', + $rootdir . 'function' . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $className . '.php'), + $rootdir . 'vendor' . DIRECTORY_SEPARATOR . $className . '.php', ]; foreach ($fileName as $file) { if (file_exists($file)) { @@ -26,7 +27,7 @@ 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 = [ 'NewCombats' => $rootdir . '/class/', 'Insallah' => $rootdir . '/class/Insallah/',