refactor: set site_url from method instead of static property (#13)

`site_url` is not needed for every operation, let's make it a method that can be called as needed instead of always setting it as static property on the `Database` class.

Reviewed-on: https://codeberg.org/vlw/wp/pulls/13
This commit is contained in:
Victor Westerlund 2026-02-22 11:03:54 +01:00
parent 1b0a9f385f
commit 1296208866

View file

@ -9,7 +9,6 @@
class Database extends DatabaseFramework { class Database extends DatabaseFramework {
public static string $name = ""; public static string $name = "";
public static string $site_url = "";
private static string $prefix = "wp"; private static string $prefix = "wp";
private static string $hostname = ""; private static string $hostname = "";
@ -71,8 +70,6 @@
$database $database
); );
$this->set_site_url();
parent::__construct(); parent::__construct();
} }
@ -90,11 +87,11 @@
} }
/** /**
* Fetch and set the WordPress siteurl from the options table * Fetch the WordPress siteurl from the options table
* *
* @return void * @return void
*/ */
public function set_site_url() { public function site_url() {
$query = new DatabaseFramework() $query = new DatabaseFramework()
->from(static::$prefix . "_options") ->from(static::$prefix . "_options")
->where(["option_name" => "siteurl"]) ->where(["option_name" => "siteurl"])
@ -105,6 +102,6 @@
throw new Exception("Failed to fetch siteurl from options table"); throw new Exception("Failed to fetch siteurl from options table");
} }
self::$site_url = $query->fetch_assoc()["option_value"]; return $query->fetch_assoc()["option_value"];
} }
} }