1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the PhpMob package. |
5
|
|
|
* |
6
|
|
|
* (c) Ishmael Doss <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace PhpMob\Settings\Schema; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @author Ishmael Doss <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
class SettingSchemaRegistry implements SettingSchemaRegistryInterface |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var Section[] |
23
|
|
|
*/ |
24
|
|
|
private $schemas = []; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var array |
28
|
|
|
*/ |
29
|
|
|
private $types = [ |
30
|
|
|
'globals' => [], |
31
|
|
|
'owners' => [], |
32
|
|
|
]; |
33
|
|
|
|
34
|
9 |
|
public function __construct(array $sections = []) |
35
|
|
|
{ |
36
|
9 |
|
foreach ($sections as $section => $data) { |
37
|
9 |
|
$this->add($section, $data); |
38
|
|
|
} |
39
|
9 |
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* {@inheritdoc} |
43
|
|
|
*/ |
44
|
9 |
|
public function add($section, array $data): void |
45
|
|
|
{ |
46
|
9 |
|
$this->schemas[$section] = new Section($section, $data); |
47
|
|
|
|
48
|
9 |
|
if ($data['owner_aware']) { |
49
|
4 |
|
$this->types['owners'][$section] = $this->schemas[$section]; |
50
|
|
|
} else { |
51
|
9 |
|
$this->types['globals'][$section] = $this->schemas[$section]; |
52
|
|
|
} |
53
|
9 |
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* {@inheritdoc} |
57
|
|
|
*/ |
58
|
1 |
|
public function get($section, $key): SettingSchema |
59
|
|
|
{ |
60
|
1 |
|
return $this->getSection($section)->getSetting($key); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* {@inheritdoc} |
65
|
|
|
*/ |
66
|
4 |
|
public function getSection($section): Section |
67
|
|
|
{ |
68
|
4 |
|
if (!array_key_exists($section, $this->schemas)) { |
69
|
1 |
|
throw new \InvalidArgumentException("No section name `$section`."); |
70
|
|
|
} |
71
|
|
|
|
72
|
3 |
|
return $this->schemas[$section]; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* {@inheritdoc} |
77
|
|
|
*/ |
78
|
3 |
|
public function getGlobals(): array |
79
|
|
|
{ |
80
|
3 |
|
return array_values($this->types['globals']); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* {@inheritdoc} |
85
|
|
|
*/ |
86
|
4 |
|
public function getOwners(): array |
87
|
|
|
{ |
88
|
4 |
|
return array_values($this->types['owners']); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* {@inheritdoc} |
93
|
|
|
*/ |
94
|
1 |
|
public function getAll(): array |
95
|
|
|
{ |
96
|
1 |
|
return array_values($this->schemas); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|