From fddb18d412e6fae1dc131c0772863475c39cb63a Mon Sep 17 00:00:00 2001 From: slawkens Date: Sun, 16 Mar 2025 08:41:46 +0100 Subject: [PATCH] Move ->load into App.php and other fixes --- system/init.php | 5 +---- system/migrations/28.php | 2 -- system/src/App/App.php | 19 ++++++++++++------- system/src/Services/RouterService.php | 7 ++++++- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/system/init.php b/system/init.php index d13f1336..8237e030 100644 --- a/system/init.php +++ b/system/init.php @@ -46,8 +46,6 @@ if(isset($config['gzip_output']) && $config['gzip_output'] && isset($_SERVER['HT // event system $hooks = app()->get('hooks'); -$hooks->load(); -$hooks->trigger(HOOK_INIT); // twig require_once SYSTEM . 'twig.php'; @@ -151,8 +149,7 @@ if (!isset($configDatabaseAutoMigrate) || $configDatabaseAutoMigrate) { } // settings -$settings = Settings::getInstance(); -$settings->load(); +$settings = app()->get('settings'); // csrf protection $token = getSession('csrf_token'); diff --git a/system/migrations/28.php b/system/migrations/28.php index 18032926..21527f83 100644 --- a/system/migrations/28.php +++ b/system/migrations/28.php @@ -3,8 +3,6 @@ * @var OTS_DB_MySQL $db */ -use MyAAC\Cache\Cache; - $up = function () use ($db) { $db->dropTable(TABLE_PREFIX . 'hooks'); diff --git a/system/src/App/App.php b/system/src/App/App.php index 2fe38587..c083ea67 100644 --- a/system/src/App/App.php +++ b/system/src/App/App.php @@ -34,9 +34,7 @@ class App $loginService = new LoginService(); $checkLogin = $loginService->checkLogin(); - $logged = $checkLogin['logged']; - $account_logged = $checkLogin['account']; - $this->accountLogged = $account_logged; + $this->accountLogged = $checkLogin['account']; $statusService = new StatusService(); $status = $statusService->checkStatus(); @@ -81,8 +79,9 @@ class App global $template_path, $template_index; $title_full = (isset($title) ? $title . ' - ' : '') . $config['lua']['serverName']; - $logged = $this->isLoggedIn; - $accountLogged = $this->accountLogged; + global $logged, $account_logged; + $logged = $checkLogin['logged']; + $account_logged = $checkLogin['account']; require $template_path . '/' . $template_index; @@ -136,11 +135,16 @@ class App break; case 'hooks': - $this->instances[$what] = new Hooks(); + $this->instances[$what] = $hooks = new Hooks(); + $hooks->load(); + $hooks->trigger(HOOK_INIT); + break; case 'settings': - $this->instances[$what] = Settings::getInstance(); + $this->instances[$what] = $settings = Settings::getInstance(); + $settings->load(); + break; case 'twig': @@ -150,6 +154,7 @@ class App 'auto_reload' => $dev_mode, 'debug' => $dev_mode )); + break; case 'twig-loader': diff --git a/system/src/Services/RouterService.php b/system/src/Services/RouterService.php index f703021c..c98cfac3 100644 --- a/system/src/Services/RouterService.php +++ b/system/src/Services/RouterService.php @@ -9,7 +9,12 @@ class RouterService { public function handleRouting(): array { - global $content, $logged, $db, $twig, $template_path, $template; + global $content, $template_path, $template; + + $db = app()->get('database'); + $twig = app()->get('twig'); + $logged = app()->isLoggedIn(); + $account_logged = app()->getAccountLogged(); if(!isset($content[0])) { $content = '';