fix: import Database from scaffolding lib and remove instances from .env.ini (#1)

This PR fixes instancing issues with `Database` due to not being able to locate its parent class from the scaffolding library. This is definitely kind of strange and should probably be investigated further. It might be because we're not autoloading these files from the library itself.

We also remove loading of Database credentials from `.env.ini` as that does not make any sense for a bundled library. Database credentials are now provided to the constructor of the `Database` class.

Reviewed-on: https://codeberg.org/vlw/wp/pulls/1
This commit is contained in:
Victor Westerlund 2026-02-12 15:27:00 +01:00
parent cfe10401a3
commit 6d1fa852b5
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

View file

@ -5,11 +5,16 @@
use Exception;
use vlw\Scaffold\Database as DatabaseFramework;
require_once dirname(__DIR__, 2) . "/scaffold/src/Database/Database.php";
class Database extends DatabaseFramework {
public static string $name = "";
public static string $site_url = "";
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
@ -27,7 +32,13 @@
* @return 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|null $table_prefix
*/
public function __construct(string $database, ?string $table_prefix = null) {
$env = parse_ini_file(dirname(__DIR__, 1) . "/.env.ini", process_sections: true);
public function __construct(
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;
if ($table_prefix) {
@ -46,10 +65,10 @@
}
Database::set_credentials(
$env["mariadb"]["host"],
$env["mariadb"]["user"],
$env["mariadb"]["pass"],
self::$name
$hostname,
$username,
$password,
$database
);
$this->set_site_url();