From 4105ad80e0f5ece945f652ad29440430ea9c1698 Mon Sep 17 00:00:00 2001 From: Pavel Shevaev Date: Fri, 26 May 2023 17:15:51 +0300 Subject: [PATCH] Adding support for setting global config filtering function; A bit improving logs --- config.inc.php | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/config.inc.php b/config.inc.php index 11ce465..95737be 100644 --- a/config.inc.php +++ b/config.inc.php @@ -4,6 +4,7 @@ use Exception; $GLOBALS['CONFIG_BASE_DIRS'] = array(); $GLOBALS['CONFIG_INIT_WORKER_FUNC'] = null; +$GLOBALS['CONFIG_FILTER_FN'] = null; task('config_worker', function(array $args) { @@ -55,9 +56,10 @@ function config_map_base_dir($file, $normalized = false, $strict = true, $dirs = return null; } -function config_real_path($rel_path, $strict = true) +function config_real_path($rel_path, $strict = true, $dirs = null) { - $dirs = config_base_dirs(); + if(!is_array($dirs)) + $dirs = config_base_dirs(); foreach($dirs as $dir) if(is_file($dir . '/' . $rel_path)) return $dir . '/' . $rel_path; @@ -80,7 +82,22 @@ function config_set_worker_init_fn($fn) function config_scan_files() { - return scan_files_rec(config_base_dirs(), array('conf.js')); + $files = scan_files_rec(config_base_dirs(), array('conf.js')); + return config_filter_files($files); +} + +function config_filter_files(array $files) +{ + global $CONFIG_FILTER_FN; + if($CONFIG_FILTER_FN != null) + $files = call_user_func($CONFIG_FILTER_FN, $files); + return $files; +} + +function config_set_files_filter_fn(callable $fn) +{ + global $CONFIG_FILTER_FN; + $CONFIG_FILTER_FN = $fn; } function config_pack_bundle(array $cache_entries, $use_lz4 = false, $use_config_refs = false) @@ -338,7 +355,7 @@ function config_fetch_ex( list($result, $total_stales) = _config_fetch_cache_ex($results_by_job); if($verbose) - echo "Miss/Hit: $total_stales/" . sizeof($result->all) . "\n"; + echo "Miss/All: $total_stales/" . sizeof($result->all) . "\n"; config_save_includes_map($includes_map, $includes_map_file);