diff --git a/core/_bootstrap.php b/core/_bootstrap.php index ce620fd1..671abe6b 100644 --- a/core/_bootstrap.php +++ b/core/_bootstrap.php @@ -22,59 +22,26 @@ $tracer_enabled = constant('TRACE_FILE')!==null; // load base files $_tracer->begin("Bootstrap"); -$_tracer->begin("Opening core files"); -$_shm_files = array_merge( +require_all(array_merge( zglob("core/*.php"), zglob("core/{".ENABLED_MODS."}/*.php"), zglob("ext/*/info.php") -); -foreach ($_shm_files as $_shm_filename) { - if (basename($_shm_filename)[0] != "_") { - require_once $_shm_filename; - } -} -unset($_shm_files); -unset($_shm_filename); -$_tracer->end(); +)); -$_tracer->begin("Connecting to Cache"); $cache = new Cache(CACHE_DSN); -$_tracer->end(); - -$_tracer->begin("Connecting to DB"); -$database = new Database(); +$database = new Database(DATABASE_DSN); $config = new DatabaseConfig($database); -$_tracer->end(); -$_tracer->begin("Loading extension info"); ExtensionInfo::load_all_extension_info(); Extension::determine_enabled_extensions(); -$_tracer->end(); - -$_tracer->begin("Opening enabled extension files"); -$_shm_files = zglob("ext/{".Extension::get_enabled_extensions_as_string()."}/main.php"); -foreach ($_shm_files as $_shm_filename) { - if (basename($_shm_filename)[0] != "_") { - require_once $_shm_filename; - } -} -unset($_shm_files); -unset($_shm_filename); -$_tracer->end(); +require_all(zglob("ext/{".Extension::get_enabled_extensions_as_string()."}/main.php")); // load the theme parts -$_tracer->begin("Loading themelets"); -foreach (_get_themelet_files(get_theme()) as $themelet) { - require_once $themelet; -} -unset($themelet); +require_all(_get_themelet_files(get_theme())); $page = class_exists("CustomPage") ? new CustomPage() : new Page(); -$_tracer->end(); // hook up event handlers -$_tracer->begin("Loading event listeners"); _load_event_listeners(); -$_tracer->end(); if (AUTO_DB_UPGRADE) { send_event(new DatabaseUpgradeEvent()); diff --git a/core/_install.php b/core/_install.php index b3529efd..b1574960 100644 --- a/core/_install.php +++ b/core/_install.php @@ -92,10 +92,9 @@ function do_install() } define("CACHE_DSN", null); - define("DATABASE_KA", true); try { create_dirs(); - create_tables(new Database()); + create_tables(new Database(DATABASE_DSN)); write_config(); } catch (InstallerException $e) { print <<dsn = $dsn; + } + private function connect_db(): void { - $this->db = new PDO(DATABASE_DSN, [ + $this->db = new PDO($this->dsn, [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, ]); diff --git a/core/util.php b/core/util.php index 65f7241d..61cccc97 100644 --- a/core/util.php +++ b/core/util.php @@ -469,6 +469,14 @@ function get_debug_info(): string /** @privatesection */ +function require_all(array $files): void { + foreach ($files as $filename) { + if (basename($filename)[0] != "_") { + require_once $filename; + } + } +} + function _version_check(): void { if (MIN_PHP_VERSION) { diff --git a/index.php b/index.php index 51f3a7a7..42e6693f 100644 --- a/index.php +++ b/index.php @@ -60,7 +60,7 @@ if (!file_exists("vendor/")) { Shimmie Error - +
diff --git a/tests/bootstrap.php b/tests/bootstrap.php index d05d7818..d412a635 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -10,18 +10,6 @@ $_SERVER['QUERY_STRING'] = '/'; chdir(dirname(dirname(__FILE__))); require_once "core/_bootstrap.php"; -function create_user(string $name) -{ - if (is_null(User::by_name($name))) { - $userPage = new UserPage(); - $userPage->onUserCreation(new UserCreationEvent($name, $name, "")); - assert(!is_null(User::by_name($name)), "Creation of user $name failed"); - } -} - -create_user("demo"); -create_user("test"); - abstract class ShimmiePHPUnitTestCase extends \PHPUnit\Framework\TestCase { private $images = []; @@ -35,6 +23,9 @@ abstract class ShimmiePHPUnitTestCase extends \PHPUnit\Framework\TestCase $this->markTestSkipped("$class not supported with this database"); } + $this->create_user("demo"); + $this->create_user("test"); + // things to do after bootstrap and before request // log in as anon $this->log_out(); @@ -47,6 +38,15 @@ abstract class ShimmiePHPUnitTestCase extends \PHPUnit\Framework\TestCase } } + protected function create_user(string $name) + { + if (is_null(User::by_name($name))) { + $userPage = new UserPage(); + $userPage->onUserCreation(new UserCreationEvent($name, $name, "")); + assert(!is_null(User::by_name($name)), "Creation of user $name failed"); + } + } + protected function get_page($page_name, $args=null) { // use a fresh page diff --git a/tests/defines.php b/tests/defines.php index 4db8a105..0070f5a7 100644 --- a/tests/defines.php +++ b/tests/defines.php @@ -1,6 +1,5 @@