refactor: use singleton pattern for LocalConfig

main
gravel 3 months ago
parent b08e6ba6bd
commit 28798b1224
Signed by: gravel
GPG Key ID: C0538F3C906B308F

@ -405,9 +405,11 @@
* @return int * @return int
*/ */
function get_staff_count(): int { function get_staff_count(): int {
global $LOCAL_CONFIG; $room_id = $this->get_room_identifier();
return ( return (
$LOCAL_CONFIG->get_room_staff_count_override($this->get_room_identifier()) LocalConfig::get_instance()
->get_room_staff_count_override($room_id)
?? count($this->get_staff()) ?? count($this->get_staff())
); );
} }

@ -13,6 +13,16 @@ class LocalConfig {
?? array(); ?? array();
} }
private static LocalConfig | null $instance = null;
/**
* Get the canonical instance of LocalConfig.
* @return LocalConfig
*/
public static function get_instance(): LocalConfig {
return LocalConfig::$instance ??= LocalConfig::read_from_files();
}
private const ROOM_OVERRIDES_CONFIG = "room-overrides.ini"; private const ROOM_OVERRIDES_CONFIG = "room-overrides.ini";
private readonly array $room_overrides; private readonly array $room_overrides;
@ -32,7 +42,7 @@ class LocalConfig {
/** /**
* Read local config from the filesystem. * Read local config from the filesystem.
*/ */
public static function read_from_files() { private static function read_from_files() {
return new LocalConfig(); return new LocalConfig();
} }
@ -46,9 +56,4 @@ class LocalConfig {
} }
} }
/**
* @var LocalConfig $LOCAL_CONFIG
*/
$LOCAL_CONFIG = LocalConfig::read_from_files();
?> ?>

Loading…
Cancel
Save