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");
|
$LIST_FILTER_TYPE = read_config_json_string("list_filter_type");
|
||||||
$EXTENSION_FILTER_LIST = read_config_json("extension_filter_list");
|
$EXTENSION_FILTER_LIST = read_config_json("extension_filter_list");
|
||||||
$BLACKLISTED_TERMS = read_config_json("blacklisted_terms");
|
$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 {
|
function main(): void {
|
||||||
global $TARGET_EXTENSIONS;
|
global $TARGET_EXTENSIONS;
|
||||||
@@ -171,20 +171,12 @@ function pull_mac_list(): array {
|
|||||||
|
|
||||||
|
|
||||||
function read_config_json_file($path){
|
function read_config_json_file($path){
|
||||||
if (!is_file($path)) {
|
$json = file_get_contents($path);
|
||||||
throw new RuntimeException("Config file not found: {$path}");
|
$data = json_decode($json, true);
|
||||||
}
|
|
||||||
|
|
||||||
$raw = file_get_contents($path);
|
if ($data === null && json_last_error() !== JSON_ERROR_NONE) {
|
||||||
if ($raw === false) {
|
throw new RuntimeException("JSON decode error: " . json_last_error_msg());
|
||||||
throw new RuntimeException("Unable to read config file: {$path}");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = json_decode($raw, true);
|
|
||||||
if (!is_array($data)) {
|
|
||||||
throw new RuntimeException("Invalid JSON in config file: {$path}");
|
|
||||||
}
|
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,6 +208,23 @@ function read_config_json_string($key) {
|
|||||||
return strtolower(trim((string)$value));
|
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 {
|
function pull_xml_file($file): DOMDocument {
|
||||||
if (!file_exists($file)) {
|
if (!file_exists($file)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user