| 12345678910111213141516171819202122232425262728293031 |
- <?php
- namespace Libs;
- use Clue\React\SQLite\Factory as SqliteFactory;
- use Clue\React\SQLite\DatabaseInterface;
- class ModelFactory
- {
- private static ?DatabaseInterface $adb = null;
- private static function getDbPath(): string
- {
- // Prefer env var if present, else default to project-root/mail.db
- $dbFile = $_ENV['DB_FILE'] ?? 'mail.db';
- if ($dbFile && $dbFile[0] === '/') {
- return $dbFile;
- }
- return dirname(__DIR__) . DIRECTORY_SEPARATOR . $dbFile;
- }
- public static function adb(): DatabaseInterface
- {
- if (!self::$adb) {
- $factory = new SqliteFactory();
- // For clue/reactphp-sqlite ^1.7, pass filename (not DSN) and options
- self::$adb = $factory->openLazy(self::getDbPath(), null, ['idle' => 300]);
- }
- return self::$adb;
- }
- }
|