mirror of
https://codeberg.org/vlw/wp.git
synced 2026-02-26 12:01:57 +01:00
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:
parent
cfe10401a3
commit
54d0df3f98
3 changed files with 27 additions and 14 deletions
|
|
@ -1,4 +0,0 @@
|
||||||
[mariadb]
|
|
||||||
host = ""
|
|
||||||
user = ""
|
|
||||||
pass = ""
|
|
||||||
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1,3 +1 @@
|
||||||
.env.ini
|
|
||||||
|
|
||||||
vendor
|
vendor
|
||||||
|
|
|
||||||
|
|
@ -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();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue