42 lines
887 B
PHP
42 lines
887 B
PHP
<?php
|
|
|
|
/*
|
|
The app container exists to be a dependency container for the game.
|
|
*/
|
|
|
|
class App
|
|
{
|
|
public static Database $db;
|
|
private static string $dbPath;
|
|
public static Request $req;
|
|
public static Auth $auth;
|
|
public static array $s = []; // game settings
|
|
|
|
public function __construct(string $dbPath)
|
|
{
|
|
self::$req = new Request(); // the current request
|
|
self::$db = new Database($dbPath); // the database
|
|
self::$dbPath = $dbPath; // the database path
|
|
|
|
// load game settings
|
|
$s = self::$db->q('SELECT * FROM settings WHERE id = 1;');
|
|
self::$s = $s ? $s->fetch() : [];
|
|
|
|
// init authentication
|
|
self::$auth = new Auth();
|
|
}
|
|
|
|
public static function performDatabaseReset(): void
|
|
{
|
|
if (file_exists(self::$dbPath)) {
|
|
unlink(self::$dbPath);
|
|
self::$db = new Database(self::$dbPath);
|
|
}
|
|
}
|
|
|
|
public static function auth(): bool
|
|
{
|
|
return self::$auth->good();
|
|
}
|
|
}
|