|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
require_once 'php/utils/logging.php';
|
|
|
|
|
require_once 'php/utils/utils.php';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var string $CONFIG_ROOT
|
|
|
|
@ -23,6 +24,17 @@ function config_requiring_type(
|
|
|
|
|
throw new Error("Unexpected configuration option type: $realtype");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function remove_trailing_key_slashes(array $array): array {
|
|
|
|
|
return $array;
|
|
|
|
|
$newarray = array();
|
|
|
|
|
foreach ($array as $key => $value) {
|
|
|
|
|
if (str_ends_with($key, "/")) {
|
|
|
|
|
$newarray[substring($key, 0, -1)] = $value;
|
|
|
|
|
} else $newarray[$key] = $value;
|
|
|
|
|
}
|
|
|
|
|
return $newarray;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Provides custom configuration values.
|
|
|
|
|
*/
|
|
|
|
@ -37,9 +49,10 @@ class LocalConfig {
|
|
|
|
|
});
|
|
|
|
|
$this->room_overrides = $room_overrides;
|
|
|
|
|
$this->room_overrides_computed = array();
|
|
|
|
|
$this->known_servers =
|
|
|
|
|
$this->known_servers = remove_trailing_key_slashes(
|
|
|
|
|
LocalConfig::maybe_parse_ini_file(LocalConfig::KNOWN_SERVERS_CONFIG)
|
|
|
|
|
?? array();
|
|
|
|
|
?? array()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static LocalConfig | null $instance = null;
|
|
|
|
@ -80,7 +93,7 @@ class LocalConfig {
|
|
|
|
|
return new LocalConfig();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function get_room_overrides(CommunityRoom $room) {
|
|
|
|
|
private function get_room_overrides(CommunityRoom $room): array {
|
|
|
|
|
$room_id = $room->get_room_identifier();
|
|
|
|
|
|
|
|
|
|
if (isset($this->room_overrides_computed[$room_id])) {
|
|
|
|
@ -98,6 +111,12 @@ class LocalConfig {
|
|
|
|
|
return $this->room_overrides_computed[$room_id] = $room_overrides;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function get_server_overrides(CommunityServer $server): array {
|
|
|
|
|
$server_base_url = $server->get_base_url();
|
|
|
|
|
|
|
|
|
|
return $this->known_servers[$server_base_url] ?? array();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function get_room_staff_count_override(CommunityRoom $room): int | null {
|
|
|
|
|
return config_requiring_type(
|
|
|
|
|
$this->get_room_overrides($room)['staff_count'],
|
|
|
|
@ -133,6 +152,10 @@ class LocalConfig {
|
|
|
|
|
public function get_known_servers(): array {
|
|
|
|
|
return $this->known_servers;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function get_server_icon_room(CommunityServer $server): ?string {
|
|
|
|
|
return $this->get_server_overrides($server)['icon'] ?? null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class RoomSafety {
|
|
|
|
|