You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
sessioncommunities.online/php/utils/read-config.php

60 lines
1.4 KiB
PHP

<?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 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;
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.
*/
private 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');
}
}
?>