Completed
Push — rework ( 4a412c...251618 )
by Markus
02:36
created

Config::__get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
namespace SSpkS;
4
5
use \Symfony\Component\Yaml\Yaml;
6
use \Symfony\Component\Yaml\Exception\ParseException;
7
8
/**
9
 * Configuration class
10
 *
11
 * @property array $site Site properties
12
 * @property array $paths Different paths
13
 * @property array excludedSynoServices Synology services to exclude from package list
14
 */
15
class Config
16
{
17
    private $basePath;
18
    private $cfgFile;
19
    private $config;
20
21
    public function __construct($basePath, $cfgFile = 'conf/sspks.yaml')
22
    {
23
        $this->basePath = $basePath;
24
        $this->cfgFile  = $this->basePath . DIRECTORY_SEPARATOR . $cfgFile;
25
26
        if (!file_exists($this->cfgFile)) {
27
            throw new \Exception('Config file "' . $this->cfgFile . '" not found!');
28
        }
29
30
        try {
31
            /** @var array $config */
32
            $config = Yaml::parse(file_get_contents($this->cfgFile));
33
        } catch (ParseException $e) {
34
            throw new \Exception($e->getMessage());
35
        }
36
37
        $this->config = $config;
38
    }
39
40
    /**
41
     * Getter magic method.
42
     *
43
     * @param string $name Name of requested value.
44
     * @return mixed Requested value.
45
     */
46
    public function __get($name)
47
    {
48
        return $this->config[$name];
49
    }
50
51
    /**
52
     * Isset feature magic method.
53
     *
54
     * @param string $name Name of requested value.
55
     * @return bool TRUE if value exists, FALSE otherwise.
56
     */
57
    public function __isset($name)
58
    {
59
        return isset($this->config[$name]);
60
    }
61
}
62