From 5ee8c4c753d1878b7877a53cd73d7b8be1df5c67 Mon Sep 17 00:00:00 2001 From: Thomas Rubini <74205383+ThomasRubini@users.noreply.github.com> Date: Sun, 22 Jan 2023 22:26:20 +0100 Subject: [PATCH] add autoloaded "Modules" directory --- Kernel/Constants.php | 6 ++++ Kernel/Session.php | 84 -------------------------------------------- Modules/AutoLoad.php | 28 +++++++++++++++ index.php | 1 + 4 files changed, 35 insertions(+), 84 deletions(-) delete mode 100644 Kernel/Session.php create mode 100644 Modules/AutoLoad.php diff --git a/Kernel/Constants.php b/Kernel/Constants.php index ac075eb..f42583d 100644 --- a/Kernel/Constants.php +++ b/Kernel/Constants.php @@ -14,6 +14,8 @@ final class Constants const CONTROLLERS_DIR = '/Controllers/'; + const MODULES_DIR = '/Modules/'; + public static function rootDir() { return realpath(__DIR__ . '/../'); @@ -39,4 +41,8 @@ final class Constants return self::rootDir() . self::CONTROLLERS_DIR; } + public static function modulesDir() { + return self::rootDir() . self::MODULES_DIR; + } + } diff --git a/Kernel/Session.php b/Kernel/Session.php deleted file mode 100644 index 8712087..0000000 --- a/Kernel/Session.php +++ /dev/null @@ -1,84 +0,0 @@ -isUserActive($_SESSION["ID"]); - return $B_userActive; - } - - public static function set_login($I_id){ - self::start_session(); - $_SESSION["ID"] = $I_id; - } - - public static function login_or_die() - { - if (!self::is_login()) { - header("Location: /user/login?return_uri=".$_SERVER["REQUEST_URI"]); - die(); - } - } - - public static function is_admin(){ - if (!self::is_login()) return false; - - $O_userModel = new UserModel(); - return $O_userModel->isUserAdmin($_SESSION["ID"]); - } - - public static function admin_or_die(){ - Session::login_or_die(); - - if (!self::is_admin()) { - header("Location: /"); - die(); - } - } - -} diff --git a/Modules/AutoLoad.php b/Modules/AutoLoad.php new file mode 100644 index 0000000..9645721 --- /dev/null +++ b/Modules/AutoLoad.php @@ -0,0 +1,28 @@ +load();