|
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 implements \Iterator |
|
16
|
|
|
{ |
|
17
|
|
|
private $iterPos; |
|
18
|
|
|
private $basePath; |
|
19
|
|
|
private $cfgFile; |
|
20
|
|
|
private $config; |
|
21
|
|
|
|
|
22
|
3 |
|
public function __construct($basePath, $cfgFile = 'conf/sspks.yaml') |
|
23
|
|
|
{ |
|
24
|
3 |
|
$this->iterPos = 0; |
|
25
|
3 |
|
$this->basePath = $basePath; |
|
26
|
3 |
|
$this->cfgFile = $this->basePath . DIRECTORY_SEPARATOR . $cfgFile; |
|
27
|
|
|
|
|
28
|
3 |
|
if (!file_exists($this->cfgFile)) { |
|
29
|
1 |
|
throw new \Exception('Config file "' . $this->cfgFile . '" not found!'); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
try { |
|
33
|
|
|
/** @var array $config */ |
|
34
|
2 |
|
$config = Yaml::parse(file_get_contents($this->cfgFile)); |
|
35
|
2 |
|
} catch (ParseException $e) { |
|
36
|
1 |
|
throw new \Exception($e->getMessage()); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
1 |
|
$this->config = $config; |
|
40
|
1 |
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Getter magic method. |
|
44
|
|
|
* |
|
45
|
|
|
* @param string $name Name of requested value. |
|
46
|
|
|
* @return mixed Requested value. |
|
47
|
|
|
*/ |
|
48
|
1 |
|
public function __get($name) |
|
49
|
|
|
{ |
|
50
|
1 |
|
return $this->config[$name]; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Isset feature magic method. |
|
55
|
|
|
* |
|
56
|
|
|
* @param string $name Name of requested value. |
|
57
|
|
|
* @return bool TRUE if value exists, FALSE otherwise. |
|
58
|
|
|
*/ |
|
59
|
|
|
public function __isset($name) |
|
60
|
|
|
{ |
|
61
|
|
|
return isset($this->config[$name]); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
1 |
|
public function rewind() |
|
65
|
|
|
{ |
|
66
|
1 |
|
$this->iterPos = 0; |
|
67
|
1 |
|
} |
|
68
|
|
|
|
|
69
|
1 |
|
public function current() |
|
70
|
|
|
{ |
|
71
|
1 |
|
return $this->config[array_keys($this->config)[$this->iterPos]]; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
1 |
|
public function key() |
|
75
|
|
|
{ |
|
76
|
|
|
return array_keys($this->config)[$this->iterPos]; |
|
77
|
1 |
|
} |
|
78
|
|
|
|
|
79
|
1 |
|
public function next() |
|
80
|
|
|
{ |
|
81
|
1 |
|
$this->iterPos++; |
|
82
|
1 |
|
} |
|
83
|
|
|
|
|
84
|
1 |
|
public function valid() |
|
85
|
|
|
{ |
|
86
|
1 |
|
return isset(array_keys($this->config)[$this->iterPos]); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|