From c7ae27716dc3c80a52daf04e89b1fc2d7dab471c Mon Sep 17 00:00:00 2001 From: pezcurrel Date: Thu, 31 Oct 2024 22:39:44 +0100 Subject: [PATCH] First commit --- lib/getconf.php | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 lib/getconf.php diff --git a/lib/getconf.php b/lib/getconf.php new file mode 100644 index 0000000..3189ae8 --- /dev/null +++ b/lib/getconf.php @@ -0,0 +1,43 @@ +$val) { + if ($conf[$key]['required'] && !array_key_exists($key,$nconf)) + $errors[]="«{$key}» is not defined"; + if (array_key_exists($key,$nconf)) + $conf[$key]=$nconf[$key]; + else + $conf[$key]=$conf[$key]['default']; + } + $errorsCount=count($errors); + if ($errorsCount>0) { + fwrite(STDERR,"Sorry, there are errors in configuration file «{$confFP}»:\n"); + for ($i=1; $i<=$errorsCount; $i++) + fwrite(STDERR," {$i}. {$errors[$i-1]}\n"); + fwrite(STDERR,"Use «-h» or «--help» to display help.\n"); + exit(1); + } +} + +?>