From 8313da0e2df5af86b2b8a3e94c8e7734e9e6df04 Mon Sep 17 00:00:00 2001 From: Pavel Shevaev Date: Fri, 1 Dec 2023 15:07:10 +0300 Subject: [PATCH] Adding base config class configurable validation --- config.inc.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/config.inc.php b/config.inc.php index 5b82d0e..f00b2f4 100644 --- a/config.inc.php +++ b/config.inc.php @@ -5,6 +5,7 @@ use Exception; $GLOBALS['CONFIG_BASE_DIRS'] = array(); $GLOBALS['CONFIG_INIT_WORKER_FUNC'] = null; $GLOBALS['CONFIG_FILTER_FN'] = null; +$GLOBALS['CONFIG_BASE_CLASS'] = '\ConfBase'; task('config_worker', function(array $args) { @@ -870,6 +871,9 @@ function config_load_ex($conf_dir, $file, array $arr, $id = null) if(!class_exists($klass)) throw new Exception("No such class '$klass'"); $cnf = new $klass; + if(!is_a($cnf, $GLOBALS['CONFIG_BASE_CLASS'])) + throw new Exception("Class '$klass' must inherit from '{$GLOBALS['CONFIG_BASE_CLASS']}'"); + $cnf->import($arr, true); } catch(Exception $e)