diff --git a/php/servers/servers-rooms.php b/php/servers/servers-rooms.php index d2ecaad..7a5da5a 100644 --- a/php/servers/servers-rooms.php +++ b/php/servers/servers-rooms.php @@ -405,9 +405,11 @@ * @return int */ function get_staff_count(): int { - global $LOCAL_CONFIG; + $room_id = $this->get_room_identifier(); + 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()) ); } diff --git a/php/utils/read-config.php b/php/utils/read-config.php index db0bd8a..dc4374b 100644 --- a/php/utils/read-config.php +++ b/php/utils/read-config.php @@ -13,6 +13,16 @@ class LocalConfig { ?? 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 readonly array $room_overrides; @@ -32,7 +42,7 @@ class LocalConfig { /** * Read local config from the filesystem. */ - public static function read_from_files() { + private static function read_from_files() { return new LocalConfig(); } @@ -46,9 +56,4 @@ class LocalConfig { } } -/** - * @var LocalConfig $LOCAL_CONFIG - */ -$LOCAL_CONFIG = LocalConfig::read_from_files(); - ?>