From 5acd182215f6f2eee1156646a5235f3c1704c3d4 Mon Sep 17 00:00:00 2001 From: Julien Rosset Date: Wed, 19 Oct 2022 11:05:29 +0200 Subject: [PATCH] Add INI format with an example --- src/EnvReader/IniConfig.php | 43 +++++++++++++++++++++++++++++++++++++ tests/initialisation.ini | 18 ++++++++++++++++ tests/test_ini.php | 19 ++++++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 src/EnvReader/IniConfig.php create mode 100644 tests/initialisation.ini create mode 100644 tests/test_ini.php diff --git a/src/EnvReader/IniConfig.php b/src/EnvReader/IniConfig.php new file mode 100644 index 0000000..817ebda --- /dev/null +++ b/src/EnvReader/IniConfig.php @@ -0,0 +1,43 @@ + $iniValue) { + if (is_array($iniValue)) { + self::parseIniLevel($iniValue, $subProperties = new InsensitiveCaseArrayClass()); + $iniValue = $subProperties; + } + + $properties->set($iniKey, $iniValue); + } + } + /** + * @inheritDoc + */ + protected function readConfig (): void { + $configFile = $this->getConfigFilePath(); + if (!file_exists($configFile)) { + throw new Exception('Unable to find configuration file "' . $configFile . '"'); + } + + if (($iniData = parse_ini_file($configFile, true, INI_SCANNER_RAW)) === false) { + throw new Exception('Unable to read configuration file "' . $configFile . '"'); + } + self::parseIniLevel($iniData, $this->properties); + } +} \ No newline at end of file diff --git a/tests/initialisation.ini b/tests/initialisation.ini new file mode 100644 index 0000000..9462702 --- /dev/null +++ b/tests/initialisation.ini @@ -0,0 +1,18 @@ +SAVE_DIR_ROOT = ./output + +[FTP_1] +HOST = test.solulog.fr +USER = test1 +PASS = test1-test1 + +[FTP_2] +HOST = test.solulog.fr +USER = test2 +PASS = test2-test2 + +[RECIPIENTS] +1[NAME] = Test 1 +1[MAIL] = test1@solulog.fr + +2[NAME] = Test 2 +2[MAIL] = test2@solulog.fr \ No newline at end of file diff --git a/tests/test_ini.php b/tests/test_ini.php new file mode 100644 index 0000000..5ed4dc1 --- /dev/null +++ b/tests/test_ini.php @@ -0,0 +1,19 @@ +getProperties()); +var_dump(Ini::getInstance()->getProperty('save_dir_root')); +var_dump(Ini::getInstance()->getProperty('FTP_2')); +foreach (Ini::getInstance()->getProperty('recipients') as $recipient) { + var_dump($recipient->get('mail')); +} \ No newline at end of file