From 26c1fa07c912547f7d55c19f34aad0912e5f3f29 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Thu, 18 Apr 2024 09:55:42 +0000 Subject: Reduce some global state and add some docs --- Zotlabs/Module/Setup.php | 6 ++--- Zotlabs/Web/Controller.php | 56 +++++++++++++++++++++++++++++++++++++++++----- Zotlabs/Web/Router.php | 33 ++++++++++++++------------- Zotlabs/Web/WebServer.php | 12 +++++----- boot.php | 18 ++++++++++++--- 5 files changed, 92 insertions(+), 33 deletions(-) diff --git a/Zotlabs/Module/Setup.php b/Zotlabs/Module/Setup.php index 74b10de25..65d4ec471 100644 --- a/Zotlabs/Module/Setup.php +++ b/Zotlabs/Module/Setup.php @@ -1,5 +1,4 @@ controller = new $modname; - App::$module_loaded = true; + $this->module_loaded = true; } } } @@ -70,15 +71,15 @@ class Router { // legacy plugins - this can be removed when they have all been converted - if(! (App::$module_loaded)) { + if(! ($this->module_loaded)) { if(is_array(App::$plugins) && in_array($module, App::$plugins) && file_exists("addon/{$module}/{$module}.php")) { include_once("addon/{$module}/{$module}.php"); if(class_exists($modname)) { $this->controller = new $modname; - App::$module_loaded = true; + $this->module_loaded = true; } elseif(function_exists($module . '_module')) { - App::$module_loaded = true; + $this->module_loaded = true; } } } @@ -88,40 +89,40 @@ class Router { * Otherwise, look for the standard program module */ - if(! (App::$module_loaded)) { + if(! ($this->module_loaded)) { try { $filename = 'Zotlabs/SiteModule/'. ucfirst($module). '.php'; if(file_exists($filename)) { // This won't be picked up by the autoloader, so load it explicitly require_once($filename); $this->controller = new $modname; - App::$module_loaded = true; + $this->module_loaded = true; } else { $filename = 'Zotlabs/Module/'. ucfirst($module). '.php'; if(file_exists($filename)) { $this->controller = new $modname; - App::$module_loaded = true; + $this->module_loaded = true; } } - if(! App::$module_loaded) + if(! $this->module_loaded) throw new Exception('Module not found'); } catch(Exception $e) { if(file_exists("mod/site/{$module}.php")) { include_once("mod/site/{$module}.php"); - App::$module_loaded = true; + $this->module_loaded = true; } elseif(file_exists("mod/{$module}.php")) { include_once("mod/{$module}.php"); - App::$module_loaded = true; + $this->module_loaded = true; } } } $x = [ 'module' => $module, - 'installed' => App::$module_loaded, + 'installed' => $this->module_loaded, 'controller' => $this->controller ]; /** @@ -138,7 +139,7 @@ class Router { */ call_hooks('module_loaded', $x); if($x['installed']) { - App::$module_loaded = true; + $this->module_loaded = true; $this->controller = $x['controller']; } @@ -146,7 +147,7 @@ class Router { * The URL provided does not resolve to a valid module. */ - if(! (App::$module_loaded)) { + if(! ($this->module_loaded)) { // undo the setting of a letsencrypt acme-challenge rewrite rule // which blocks access to our .well-known routes. @@ -162,7 +163,7 @@ class Router { $x = [ 'module' => $module, - 'installed' => App::$module_loaded, + 'installed' => $this->module_loaded, 'controller' => $this->controller ]; call_hooks('page_not_found',$x); @@ -189,7 +190,7 @@ class Router { // pretend this is a module so it will initialise the theme App::$module = '404'; - App::$module_loaded = true; + $this->module_loaded = true; App::$error = true; } } @@ -205,7 +206,7 @@ class Router { * Call module functions */ - if(App::$module_loaded) { + if($this->module_loaded) { App::$page['page_title'] = App::$module; $placeholder = ''; diff --git a/Zotlabs/Web/WebServer.php b/Zotlabs/Web/WebServer.php index f43ae10a4..6f8a4b956 100644 --- a/Zotlabs/Web/WebServer.php +++ b/Zotlabs/Web/WebServer.php @@ -13,11 +13,11 @@ class WebServer { require_once('boot.php'); - sys_boot(); + $installed = sys_boot(); \App::$language = get_best_language(); - load_translation_table(\App::$language,\App::$install); + load_translation_table(\App::$language, !$installed); /** @@ -56,7 +56,7 @@ class WebServer { load_translation_table(\App::$language); } - if((x($_GET,'zid')) && (! \App::$install)) { + if (x($_GET,'zid') && $installed) { \App::$query_string = strip_zids(\App::$query_string); if(! local_channel()) { if (!isset($_SESSION['my_address']) || $_SESSION['my_address'] != $_GET['zid']) { @@ -69,14 +69,14 @@ class WebServer { } } - if((x($_GET,'zat')) && (! \App::$install)) { + if (x($_GET,'zat') && $installed) { \App::$query_string = strip_zats(\App::$query_string); if(! local_channel()) { zat_init(); } } - if((x($_REQUEST,'owt')) && (! \App::$install)) { + if (x($_REQUEST,'owt') && $installed) { $token = $_REQUEST['owt']; \App::$query_string = strip_query_param(\App::$query_string,'owt'); owt_init($token); @@ -85,7 +85,7 @@ class WebServer { if((x($_SESSION, 'authenticated')) || (x($_POST, 'auth-params')) || (\App::$module === 'login')) require('include/auth.php'); - if(\App::$install) { + if (!$installed) { /* Allow an exception for the view module so that pcss will be interpreted during installation */ if(\App::$module != 'view') \App::$module = 'setup'; diff --git a/boot.php b/boot.php index dcdcdda01..862079276 100644 --- a/boot.php +++ b/boot.php @@ -602,8 +602,19 @@ define('DBTYPE_MYSQL', 0); define('DBTYPE_POSTGRES', 1); -function sys_boot() { - +/** + * Boot the app. + * + * Detects if the system is installed, and if it is, reads the basic configuration + * in `.htconfig`, conects to the database, and loads the system configuration stored + * in the db. + * + * As a side effect it also sets the App::$install flag to true if the system is _not_ + * installed yet. + * + * @return True if the system is installed, false otherwise. + */ +function sys_boot(): bool { // our central App object @@ -686,6 +697,8 @@ function sys_boot() { */ call_hooks('init_1'); } + + return !App::$install; } @@ -766,7 +779,6 @@ class App { public static $langsave; public static $rtl = false; public static $plugins_admin; - public static $module_loaded = false; public static $query_string; public static $page; public static $profile; -- cgit v1.2.3