extra array config fucnt
This commit is contained in:
@@ -15,7 +15,7 @@ $TARGET_EXTENSIONS = read_config_json("target_extensions");
|
||||
$LIST_FILTER_TYPE = read_config_json_string("list_filter_type");
|
||||
$EXTENSION_FILTER_LIST = read_config_json("extension_filter_list");
|
||||
$BLACKLISTED_TERMS = read_config_json("blacklisted_terms");
|
||||
$PREPEND_EXTENSIONS = read_config_json("prepend_extensions");
|
||||
$PREPEND_EXTENSIONS = read_config_json_object_list("prepend_extensions");
|
||||
|
||||
function main(): void {
|
||||
global $TARGET_EXTENSIONS;
|
||||
@@ -171,20 +171,12 @@ function pull_mac_list(): array {
|
||||
|
||||
|
||||
function read_config_json_file($path){
|
||||
if (!is_file($path)) {
|
||||
throw new RuntimeException("Config file not found: {$path}");
|
||||
}
|
||||
$json = file_get_contents($path);
|
||||
$data = json_decode($json, true);
|
||||
|
||||
$raw = file_get_contents($path);
|
||||
if ($raw === false) {
|
||||
throw new RuntimeException("Unable to read config file: {$path}");
|
||||
if ($data === null && json_last_error() !== JSON_ERROR_NONE) {
|
||||
throw new RuntimeException("JSON decode error: " . json_last_error_msg());
|
||||
}
|
||||
|
||||
$data = json_decode($raw, true);
|
||||
if (!is_array($data)) {
|
||||
throw new RuntimeException("Invalid JSON in config file: {$path}");
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
@@ -216,6 +208,23 @@ function read_config_json_string($key) {
|
||||
return strtolower(trim((string)$value));
|
||||
}
|
||||
|
||||
function read_config_json_object_list($key) {
|
||||
global $CONFIG;
|
||||
$value = $CONFIG[$key] ?? [];
|
||||
|
||||
if (!is_array($value)) return [];
|
||||
|
||||
$out = [];
|
||||
foreach ($value as $row) {
|
||||
if (is_array($row) && isset($row['name'], $row['extension'])) {
|
||||
$out[] = [
|
||||
'name' => (string)$row['name'],
|
||||
'extension' => (string)$row['extension'],
|
||||
];
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
function pull_xml_file($file): DOMDocument {
|
||||
if (!file_exists($file)) {
|
||||
|
||||
Reference in New Issue
Block a user