feat: add local room overrides
parent
53964f09d9
commit
d5cb336170
@ -0,0 +1,2 @@
|
||||
[room+1234]
|
||||
staff_count=4
|
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
require_once 'php/utils/logging.php';
|
||||
|
||||
/**
|
||||
* @var string $CONFIG_ROOT
|
||||
*/
|
||||
|
||||
class LocalConfig {
|
||||
private function __construct() {
|
||||
$this->room_overrides =
|
||||
LocalConfig::maybe_parse_ini_file(LocalConfig::ROOM_OVERRIDES_CONFIG)
|
||||
?? array();
|
||||
}
|
||||
|
||||
private const ROOM_OVERRIDES_CONFIG = "room-overrides.ini";
|
||||
|
||||
private readonly array $room_overrides;
|
||||
|
||||
private static function maybe_parse_ini_file(string $filename): array | null {
|
||||
global $CONFIG_ROOT;
|
||||
$file = "$CONFIG_ROOT/$filename";
|
||||
|
||||
if (!file_exists($file)) {
|
||||
log_warning("config file not found: $file");
|
||||
return null;
|
||||
}
|
||||
|
||||
return parse_ini_file($file, process_sections: true, scanner_mode: INI_SCANNER_RAW);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read local config from the filesystem.
|
||||
*/
|
||||
public static function read_from_files() {
|
||||
return new LocalConfig();
|
||||
}
|
||||
|
||||
private function get_room_override(string $room_id, string $override_key) {
|
||||
$room_overrides = $this->room_overrides[$room_id] ?? array();
|
||||
return $room_overrides[$override_key] ?? null;
|
||||
}
|
||||
|
||||
public function get_room_staff_count_override(string $room_id) {
|
||||
return $this->get_room_override($room_id, 'staff_count');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @var LocalConfig $LOCAL_CONFIG
|
||||
*/
|
||||
$LOCAL_CONFIG = LocalConfig::read_from_files();
|
||||
|
||||
?>
|
Loading…
Reference in New Issue