Skip to content

Commit

Permalink
cleaner extension loading
Browse files Browse the repository at this point in the history
  • Loading branch information
shish committed Dec 16, 2023
1 parent dba8ace commit b1c6894
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 24 deletions.
26 changes: 11 additions & 15 deletions core/util.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
*/
Expand Down
4 changes: 1 addition & 3 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@
$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();
Expand Down
9 changes: 3 additions & 6 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,15 @@
$_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());
Expand Down

0 comments on commit b1c6894

Please sign in to comment.