From 742e6692d572891c0acb5c913d0785d8a2ce66f8 Mon Sep 17 00:00:00 2001 From: Pavel Shevaev Date: Tue, 25 Feb 2025 15:41:22 +0300 Subject: [PATCH] Adding check_junk optional support during normalization --- cache.inc.php | 10 +++++++--- parse.inc.php | 6 ++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/cache.inc.php b/cache.inc.php index 6521d66..8826d13 100644 --- a/cache.inc.php +++ b/cache.inc.php @@ -154,6 +154,7 @@ class ConfigFetchParams public bool $verbose = false; public ?int $max_workers = null; public bool $touch_files_with_includes = true; + public bool $check_junk = false; function __construct(ConfigGlobals $globals, ConfigScanResult $scanned, bool $force_stale = false, bool $verbose = false, ?int $max_workers = null) @@ -350,7 +351,9 @@ function _config_merge_fetch_results(ConfigFetchParams $params, array $results_b return $result; } -function _config_invalidate_cache(ConfigFetchParams $params, string $base_dir, string $file, string $cache_file, ?int &$parser_type = null) : ConfigCacheEntry +function _config_invalidate_cache( + ConfigFetchParams $params, string $base_dir, string $file, + string $cache_file, ?int &$parser_type = null) : ConfigCacheEntry { list($conf_id, $conf_strid) = config_ensure_header($base_dir, $file); if(!$conf_id) @@ -363,14 +366,15 @@ function _config_invalidate_cache(ConfigFetchParams $params, string $base_dir, s $pres = config_parse($params->globals->base_dirs, $file); if($pres->error !== 0) - throw new Exception("Error({$pres->error}) while parsing {$file}:\n" . $pres->error_descr); + throw new Exception("Parse error({$pres->error}):\n" . $pres->error_descr); $parser_type = $pres->parser_type; $parsed_arr = $pres->parsed_arr; //TODO: these hardcoded keys below probably shouldn't be part of data? $parsed_arr['id'] = $conf_id; $parsed_arr['strid'] = $conf_strid; - list($class, $class_id, $normalized_data) = config_apply_class_normalization($parsed_arr); + list($class, $class_id, $normalized_data) + = config_apply_class_normalization($parsed_arr, $params->check_junk); $cache_payload_file = config_get_cache_payload_path($params->globals, $file); diff --git a/parse.inc.php b/parse.inc.php index 4b7d3c5..dc59f2a 100644 --- a/parse.inc.php +++ b/parse.inc.php @@ -143,11 +143,13 @@ function config_ensure_header(string $conf_dir, string $file, bool $force = fals } } -function config_apply_class_normalization(array $kv_data) : array +function config_apply_class_normalization(array $kv_data, bool $check_junk = false) : array { $class = $kv_data['class']; $norm_data = array(); - call_user_func_array([$class, 'normalize'], array(&$kv_data, &$norm_data)); + unset($kv_data['class']); + call_user_func_array([$class, 'normalize'], + array(&$kv_data, &$norm_data, true, $check_junk)); return array($class, $class::CLASS_ID, $norm_data); }