parent
016c97c875
commit
5acd182215
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace jrosset\EnvReader;
|
||||
|
||||
use Exception;
|
||||
use jrosset\ArrayClasses\InsensitiveCaseArrayClass;
|
||||
|
||||
abstract class IniConfig extends GenericConfig implements IExternalConfigFile {
|
||||
use TMultiLevelProperties;
|
||||
|
||||
/**
|
||||
* Parse an INI level to properties
|
||||
*
|
||||
* @param array $iniLevelData The INI level
|
||||
* @param InsensitiveCaseArrayClass $properties [OUT] The out properties list
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private static function parseIniLevel (array $iniLevelData, InsensitiveCaseArrayClass $properties): void {
|
||||
foreach ($iniLevelData as $iniKey => $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);
|
||||
}
|
||||
}
|
@ -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
|
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/** @noinspection PhpIllegalPsrClassPathInspection */
|
||||
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use jrosset\EnvReader\IniConfig;
|
||||
|
||||
class Ini extends IniConfig {
|
||||
public function getConfigFilePath (): string {
|
||||
return __DIR__ . '/initialisation.ini';
|
||||
}
|
||||
}
|
||||
|
||||
//var_dump(Ini::getInstance()->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'));
|
||||
}
|
Loading…
Reference in New Issue