Adding base config class configurable validation
This commit is contained in:
parent
db01d08320
commit
8313da0e2d
|
@ -5,6 +5,7 @@ use Exception;
|
||||||
$GLOBALS['CONFIG_BASE_DIRS'] = array();
|
$GLOBALS['CONFIG_BASE_DIRS'] = array();
|
||||||
$GLOBALS['CONFIG_INIT_WORKER_FUNC'] = null;
|
$GLOBALS['CONFIG_INIT_WORKER_FUNC'] = null;
|
||||||
$GLOBALS['CONFIG_FILTER_FN'] = null;
|
$GLOBALS['CONFIG_FILTER_FN'] = null;
|
||||||
|
$GLOBALS['CONFIG_BASE_CLASS'] = '\ConfBase';
|
||||||
|
|
||||||
task('config_worker', function(array $args)
|
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))
|
if(!class_exists($klass))
|
||||||
throw new Exception("No such class '$klass'");
|
throw new Exception("No such class '$klass'");
|
||||||
$cnf = new $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);
|
$cnf->import($arr, true);
|
||||||
}
|
}
|
||||||
catch(Exception $e)
|
catch(Exception $e)
|
||||||
|
|
Loading…
Reference in New Issue