diff --git a/TODO.md b/TODO.md index fb749aa..fa3c6b0 100644 --- a/TODO.md +++ b/TODO.md @@ -57,6 +57,8 @@ - [x] Update Dispatcher to render full pages (head + header + view + footer) instead of requiring bootstrap - [x] Ensure admin/index.php bootstraps its own path (not affected by front controller) +- [x] Fix config/config.php path mess — inline getDatabasePath() into Database.php, delete config/config.php + ### Phase 3: Server config - [ ] Update router.php — route all PHP requests to Dispatcher - [ ] Update nginx config — point all public routes to index.php via try_files diff --git a/app/src/Database.php b/app/src/Database.php index 9b74da2..bc604f4 100644 --- a/app/src/Database.php +++ b/app/src/Database.php @@ -1,7 +1,5 @@ config.php settings + * Determine database path. + * Priority: explicit override → DB_ENV env-var → sapi auto-detect. + * APP_ROOT is defined by bootstrap.php before any controller loads Database. */ - private function determineDatabasePath($customPath = null) { - // Allow explicit override + private function determineDatabasePath($customPath = null): string { if ($customPath !== null && file_exists($customPath)) { return $customPath; } - // Use centralized configuration - return getDatabasePath(); + $root = defined('APP_ROOT') ? APP_ROOT : __DIR__ . '/..'; + $testDb = $root . '/storage/test.db'; + $prodDb = $root . '/storage/posterg.db'; + + $env = getenv('DB_ENV'); + if ($env === 'test') return $testDb; + if ($env === 'prod') return $prodDb; + + // php -S (dev server) → test DB; everything else (nginx/fpm) → prod DB + return php_sapi_name() === 'cli-server' ? $testDb : $prodDb; } /** diff --git a/app/storage/test.db b/app/storage/test.db index b66f21a..6215a6b 100644 Binary files a/app/storage/test.db and b/app/storage/test.db differ diff --git a/config/config.php b/config/config.php deleted file mode 100644 index 1cce3ac..0000000 --- a/config/config.php +++ /dev/null @@ -1,49 +0,0 @@ -