fix: import Database from scaffolding lib and remove instances from .env.ini

This commit is contained in:
Victor Westerlund 2026-02-12 15:15:44 +01:00
parent cfe10401a3
commit e9e5604c32
Signed by: vlw
GPG key ID: D0AD730E1057DFC6
3 changed files with 27 additions and 14 deletions

View file

@ -1,4 +0,0 @@
[mariadb]
host = ""
user = ""
pass = ""

2
.gitignore vendored
View file

@ -1,3 +1 @@
.env.ini
vendor vendor

View file

@ -5,11 +5,16 @@
use Exception; use Exception;
use vlw\Scaffold\Database as DatabaseFramework; use vlw\Scaffold\Database as DatabaseFramework;
require_once dirname(__DIR__, 2) . "/scaffold/src/Database/Database.php";
class Database extends DatabaseFramework { class Database extends DatabaseFramework {
public static string $name = ""; public static string $name = "";
public static string $site_url = ""; public static string $site_url = "";
private static string $prefix = "wp"; private static string $prefix = "wp";
private static string $hostname = "";
private static string $username = "";
private static string $password = "";
/** /**
* Get a prefixed table name from the database * Get a prefixed table name from the database
@ -27,7 +32,13 @@
* @return static * @return static
*/ */
public static function current(): static { public static function current(): static {
return new static(self::$name, self::$prefix); return new static(
self::$hostname,
self::$username,
self::$password,
self::$name,
self::$prefix
);
} }
/** /**
@ -36,9 +47,17 @@
* @param string $database * @param string $database
* @param string|null $table_prefix * @param string|null $table_prefix
*/ */
public function __construct(string $database, ?string $table_prefix = null) { public function __construct(
$env = parse_ini_file(dirname(__DIR__, 1) . "/.env.ini", process_sections: true); string $hostname,
string $username,
string $password,
string $database,
?string $table_prefix = null
) {
self::$hostname = $hostname;
self::$username = $username;
self::$password = $password;
self::$password = $password;
self::$name = $database; self::$name = $database;
if ($table_prefix) { if ($table_prefix) {
@ -46,10 +65,10 @@
} }
Database::set_credentials( Database::set_credentials(
$env["mariadb"]["host"], $hostname,
$env["mariadb"]["user"], $username,
$env["mariadb"]["pass"], $password,
self::$name $database
); );
$this->set_site_url(); $this->set_site_url();