From 51a65506c1fc9bab685f62fe696354f6608cdd72 Mon Sep 17 00:00:00 2001 From: Valithor Obsidion Date: Fri, 15 Aug 2025 02:50:16 -0400 Subject: [PATCH] Throw extension if required ext is missing --- public/index.php | 16 ++++++++++++++-- src/DragonKnight/functions.php | 15 ++++++++++----- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/public/index.php b/public/index.php index 6e98024..113ffd5 100644 --- a/public/index.php +++ b/public/index.php @@ -31,8 +31,20 @@ if (! $autoloader = require file_exists(__DIR__.'/../vendor/autoload.php') ? __D throw new \Exception('Composer autoloader not found. Run `composer install` and try again.'); } -if (! extension_loaded('sqlite3')) { - throw new \Exception('The SQLite3 extension is required but not loaded. Please enable it in your PHP configuration.'); +// Check required extensions +$requiredExtensions = [ + 'sqlite3', + 'gd', + 'imap', + 'redis', + 'mongodb' +]; + +if ($missing = array_filter($requiredExtensions, fn($ext) => !extension_loaded($ext))) { + throw new \Exception( + 'Required PHP extensions missing: ' . implode(', ', $missing) . + '. Please enable them in your PHP configuration.' + ); } $uri = explode('/', trim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/')); diff --git a/src/DragonKnight/functions.php b/src/DragonKnight/functions.php index 375a64c..a84b0ec 100644 --- a/src/DragonKnight/functions.php +++ b/src/DragonKnight/functions.php @@ -21,11 +21,16 @@ function index(): string|false { $page = false; - if (user()->currentaction === 'In Town') { + if (! $user = user()) { + error_log('User not found in index() function.'); + return $page; + } + + if ($user->currentaction === 'In Town') { $page = Towns::town(); - } elseif (user()->currentaction === 'Exploring') { + } elseif ($user->currentaction === 'Exploring') { $page = Explore::explore(); - } elseif (user()->currentaction === 'Fighting') { + } elseif ($user->currentaction === 'Fighting') { redirect('/fight'); } @@ -158,7 +163,7 @@ function render(string $path_to_base_view, array $data = []): string|false { ob_start(); extract($data); - require __DIR__."/../templates/$path_to_base_view.php"; + require __DIR__."/../../templates/$path_to_base_view.php"; return ob_get_clean(); } @@ -676,7 +681,7 @@ function is_post(): bool /** * Get the current page title per updates. Optionally set a new title. */ -function page_title(string $new_title = ''): string +function page_title(?string $new_title = null): string { if ($new_title) { return $GLOBALS['state']['new-page-title'] = $new_title;