From b1c6894fbc581a04c8b5900b662c081595558769 Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 16 Dec 2023 00:37:40 +0000 Subject: [PATCH] cleaner extension loading --- core/util.php | 26 +++++++++++--------------- index.php | 4 +--- tests/bootstrap.php | 9 +++------ 3 files changed, 15 insertions(+), 24 deletions(-) diff --git a/core/util.php b/core/util.php index 2e0e197e..8a59321e 100644 --- a/core/util.php +++ b/core/util.php @@ -565,11 +565,20 @@ function _load_core_files() )); } +function _load_extension_files() +{ + ExtensionInfo::load_all_extension_info(); + Extension::determine_enabled_extensions(); + require_all(zglob("ext/{".Extension::get_enabled_extensions_as_string()."}/main.php")); +} + function _load_theme_files() { $theme = get_theme(); - $files = _get_themelet_files($theme); - require_all($files); + require_once('themes/'.$theme.'/page.class.php'); + require_once('themes/'.$theme.'/themelet.class.php'); + require_all(zglob("ext/{".Extension::get_enabled_extensions_as_string()."}/theme.php")); + require_all(zglob('themes/'.$theme.'/{'.Extension::get_enabled_extensions_as_string().'}.theme.php')); } function _set_up_shimmie_environment(): void @@ -595,19 +604,6 @@ function _set_up_shimmie_environment(): void } -function _get_themelet_files(string $_theme): array -{ - $base_themelets = []; - $base_themelets[] = 'themes/'.$_theme.'/page.class.php'; - $base_themelets[] = 'themes/'.$_theme.'/themelet.class.php'; - - $ext_themelets = zglob("ext/{".Extension::get_enabled_extensions_as_string()."}/theme.php"); - $custom_themelets = zglob('themes/'.$_theme.'/{'.Extension::get_enabled_extensions_as_string().'}.theme.php'); - - return array_merge($base_themelets, $ext_themelets, $custom_themelets); -} - - /** * Used to display fatal errors to the web user. */ diff --git a/index.php b/index.php index 7aebad1c..5b7cbb96 100644 --- a/index.php +++ b/index.php @@ -50,9 +50,7 @@ _load_core_files(); $cache = loadCache(CACHE_DSN); $database = new Database(DATABASE_DSN); $config = new DatabaseConfig($database); -ExtensionInfo::load_all_extension_info(); -Extension::determine_enabled_extensions(); -require_all(zglob("ext/{".Extension::get_enabled_extensions_as_string()."}/main.php")); +_load_extension_files(); _load_theme_files(); $page = new Page(); _load_event_listeners(); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 808539b4..cf1d7c45 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -26,18 +26,15 @@ $_tracer = new \EventTracer(); $_tracer->begin("bootstrap"); _load_core_files(); $cache = loadCache(CACHE_DSN); -$dsn = getenv("TEST_DSN"); -$database = new Database($dsn ? $dsn : "sqlite::memory:"); +$database = new Database(getenv("TEST_DSN") ?: "sqlite::memory:"); create_dirs(); create_tables($database); $config = new DatabaseConfig($database); -ExtensionInfo::load_all_extension_info(); -Extension::determine_enabled_extensions(); -require_all(zglob("ext/{".Extension::get_enabled_extensions_as_string()."}/main.php")); +_load_extension_files(); _load_theme_files(); $page = new Page(); _load_event_listeners(); -$config->set_string("thumb_engine", "static"); # GD has less overhead per-call +$config->set_string("thumb_engine", "static"); $config->set_bool("nice_urls", true); send_event(new DatabaseUpgradeEvent()); send_event(new InitExtEvent());