1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace SKien\Config; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Class for config component getting data from INI file. |
8
|
|
|
* Lines begin with semikolon are ignored as comments. |
9
|
|
|
* The begin of a section have to be set in square brackets. |
10
|
|
|
* A section is active until next section begins or to the end of file. |
11
|
|
|
* |
12
|
|
|
* #### History |
13
|
|
|
* - *2021-01-01* initial version |
14
|
|
|
* |
15
|
|
|
* @package SKien/Config |
16
|
|
|
* @version 1.0.0 |
17
|
|
|
* @author Stefanius <[email protected]> |
18
|
|
|
* @copyright MIT License - see the LICENSE file for details |
19
|
|
|
*/ |
20
|
|
|
class INIConfig extends AbstractConfig |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* Get the boolean value specified by path. |
24
|
|
|
* Accepted values are (case insensitiv): <ul> |
25
|
|
|
* <li> true, on, yes, 1 </li> |
26
|
|
|
* <li> false, off, no, none, 0 </li></ul> |
27
|
|
|
* for all other values the default is returned! |
28
|
|
|
* @param string $strPath |
29
|
|
|
* @param bool $bDefault |
30
|
|
|
* @return bool |
31
|
|
|
*/ |
32
|
|
|
public function getBool(string $strPath, bool $bDefault = false) : bool |
33
|
|
|
{ |
34
|
|
|
$value = (string) $this->getValue($strPath, $bDefault); |
35
|
|
|
if ($this->isTrue($value)) { |
36
|
|
|
return true; |
37
|
|
|
} else if ($this->isFalse($value)) { |
38
|
|
|
return false; |
39
|
|
|
} else { |
40
|
|
|
return $bDefault; |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Parse the given file an add all settings to the internal configuration. |
46
|
|
|
* @param string $strConfigFile |
47
|
|
|
*/ |
48
|
|
|
protected function parseFile(string $strConfigFile) : array |
49
|
|
|
{ |
50
|
|
|
if (!file_exists($strConfigFile)) { |
51
|
|
|
trigger_error('Config File (' . $strConfigFile . ') does not exist!', E_USER_WARNING); |
52
|
|
|
return []; |
53
|
|
|
} |
54
|
|
|
$aINI = parse_ini_file($strConfigFile, TRUE); |
55
|
|
|
if ($aINI === false) { |
56
|
|
|
$aINI = []; |
57
|
|
|
} |
58
|
|
|
return $aINI; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|