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 SettingSchema implements \JsonSerializable |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var array |
23
|
|
|
*/ |
24
|
|
|
private $data = []; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var Section |
28
|
|
|
*/ |
29
|
|
|
private $section; |
30
|
|
|
|
31
|
9 |
|
public function __construct(Section $section, $key, array $schema) |
32
|
|
|
{ |
33
|
9 |
|
$this->section = $section; |
34
|
9 |
|
$this->data['section'] = $section->getName(); |
|
|
|
|
35
|
9 |
|
$this->data['key'] = $key; |
36
|
|
|
|
37
|
9 |
|
foreach ($schema as $key => $value) { |
38
|
9 |
|
$this->data[$key] = 'blueprint' === $key ? new Blueprint($value) : $value; |
39
|
|
|
} |
40
|
9 |
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @return bool |
44
|
|
|
*/ |
45
|
|
|
public function isEnabled(): bool |
46
|
|
|
{ |
47
|
|
|
return $this->data['enabled']; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return string |
52
|
|
|
*/ |
53
|
|
|
public function getLabel(): string |
54
|
|
|
{ |
55
|
|
|
return $this->data['label']; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return string|null |
60
|
|
|
*/ |
61
|
|
|
public function getDescription(): ?string |
62
|
|
|
{ |
63
|
|
|
return $this->data['description']; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return string |
68
|
|
|
*/ |
69
|
4 |
|
public function getKey() |
70
|
|
|
{ |
71
|
4 |
|
return $this->data['key']; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return string |
76
|
|
|
*/ |
77
|
3 |
|
public function getValue() |
78
|
|
|
{ |
79
|
3 |
|
return (string) $this->data['value']; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return string |
84
|
|
|
*/ |
85
|
|
|
public function getType() |
86
|
|
|
{ |
87
|
|
|
return $this->data['type']; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return string |
92
|
|
|
*/ |
93
|
|
|
public function getSectionName() |
94
|
|
|
{ |
95
|
|
|
return $this->data['section']; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @return Blueprint |
100
|
|
|
*/ |
101
|
|
|
public function getBlueprint() |
102
|
|
|
{ |
103
|
|
|
return $this->data['blueprint']; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @return Section |
108
|
|
|
*/ |
109
|
3 |
|
public function getSection() |
110
|
|
|
{ |
111
|
3 |
|
return $this->section; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* {@inheritdoc} |
116
|
|
|
*/ |
117
|
|
|
public function jsonSerialize() |
118
|
|
|
{ |
119
|
|
|
return $this->data; |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|