query("SELECT COUNT(*) FROM sqlite_master WHERE type = 'table'")->fetchColumn() > 0; if ($database_exists) { return $pdo; } foreach (scandir(__DIR__) as $file) { if (preg_match("/.*\.sql$/i", $file)) { $content = file_get_contents(__DIR__ . "/" . $file); $pdo->exec($content); } } init_database($pdo); return $pdo; } function init_database(PDO $pdo): void { $accounts = new AccountGateway(new Connection($pdo)); $defaultAccounts = ["maxime", "mael", "yanis", "vivien"]; foreach ($defaultAccounts as $name) { $email = "$name@mail.com"; $id = $accounts->insertAccount($name, $email, AuthModel::generateToken(), password_hash("123456", PASSWORD_DEFAULT), "https://cdn.pixabay.com/photo/2015/10/05/22/37/blank-profile-picture-973460_960_720.png"); $accounts->setIsAdmin($id, true); } }