From 6d1fa852b5a652df8fcf26e954302622a4c4cbd7 Mon Sep 17 00:00:00 2001 From: Victor Westerlund Date: Thu, 12 Feb 2026 15:27:00 +0100 Subject: [PATCH] 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 --- .env.example.ini | 4 ---- .gitignore | 2 -- src/Database.php | 35 +++++++++++++++++++++++++++-------- 3 files changed, 27 insertions(+), 14 deletions(-) delete mode 100644 .env.example.ini diff --git a/.env.example.ini b/.env.example.ini deleted file mode 100644 index 77e81ba..0000000 --- a/.env.example.ini +++ /dev/null @@ -1,4 +0,0 @@ -[mariadb] -host = "" -user = "" -pass = "" diff --git a/.gitignore b/.gitignore index 76bfadb..22d0d82 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1 @@ -.env.ini - vendor diff --git a/src/Database.php b/src/Database.php index dc84268..2e9a007 100644 --- a/src/Database.php +++ b/src/Database.php @@ -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();