INIConfig::parseFile()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
c 0
b 0
f 0
dl 0
loc 7
rs 10
cc 3
nc 4
nop 1
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
 * @package Config
13
 * @author Stefanius <[email protected]>
14
 * @copyright MIT License - see the LICENSE file for details
15
 */
16
class INIConfig extends AbstractConfig
17
{
18
    /**
19
     * The constructor expects an valid filename/path to the JSON file.
20
     * @param string $strConfigFile
21
     */
22
    public function __construct(string $strConfigFile)
23
    {
24
        $this->aConfig = $this->parseFile($strConfigFile);
25
    }
26
27
    /**
28
     * Parse the given file an add all settings to the internal configuration.
29
     * @param string $strConfigFile
30
     * @return array<mixed>
31
     */
32
    protected function parseFile(string $strConfigFile) : array
33
    {
34
        if (!file_exists($strConfigFile)) {
35
            trigger_error('Config File (' . $strConfigFile . ') does not exist!', E_USER_WARNING);
36
        }
37
        $aINI = parse_ini_file($strConfigFile, TRUE);
38
        return ($aINI !== false) ? $aINI : [];
39
    }
40
}
41