1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace AlecRabbit\Spinner\Settings; |
4
|
|
|
|
5
|
|
|
use AlecRabbit\Spinner\Core\Sentinel; |
6
|
|
|
use AlecRabbit\Spinner\Settings\Contracts\Defaults; |
7
|
|
|
use AlecRabbit\Spinner\Settings\Contracts\S; |
8
|
|
|
use AlecRabbit\Spinner\Settings\Contracts\SettingsInterface; |
9
|
|
|
|
10
|
|
|
class Settings implements SettingsInterface |
11
|
|
|
{ |
12
|
|
|
/** @var Property[] */ |
13
|
|
|
protected $properties; |
14
|
|
|
|
15
|
45 |
|
public function __construct() |
16
|
|
|
{ |
17
|
45 |
|
$this->properties = $this->initialize(); |
18
|
45 |
|
} |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @return Property[] |
22
|
|
|
*/ |
23
|
45 |
|
private function initialize(): array |
24
|
|
|
{ |
25
|
45 |
|
$properties = []; |
26
|
45 |
|
foreach (Defaults::DEFAULT_SETTINGS as $name => $value) { |
27
|
45 |
|
$properties[$name] = new Property($value); |
28
|
|
|
} |
29
|
45 |
|
return $properties; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** {@inheritDoc} */ |
33
|
30 |
|
public function getInterval(): float |
34
|
|
|
{ |
35
|
|
|
return |
36
|
30 |
|
$this->properties[S::INTERVAL]->getValue(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** {@inheritDoc} */ |
40
|
28 |
|
public function setInterval(float $interval): self |
41
|
|
|
{ |
42
|
28 |
|
$this->properties[S::INTERVAL]->setValue($interval); |
43
|
28 |
|
return $this; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** {@inheritDoc} */ |
47
|
28 |
|
public function isHideCursor(): bool |
48
|
|
|
{ |
49
|
|
|
return |
50
|
28 |
|
$this->properties[S::HIDE_CURSOR]->getValue(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** {@inheritDoc} */ |
54
|
1 |
|
public function setHideCursor($value = true): self |
55
|
|
|
{ |
56
|
1 |
|
$this->properties[S::HIDE_CURSOR]->setValue($value); |
57
|
1 |
|
return $this; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** {@inheritDoc} */ |
61
|
28 |
|
public function isEnabled(): bool |
62
|
|
|
{ |
63
|
|
|
return |
64
|
28 |
|
$this->properties[S::ENABLED]->getValue(); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** {@inheritDoc} */ |
68
|
1 |
|
public function setEnabled(bool $enabled = true): self |
69
|
|
|
{ |
70
|
1 |
|
$this->properties[S::ENABLED]->setValue($enabled); |
71
|
1 |
|
return $this; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** {@inheritDoc} */ |
75
|
31 |
|
public function getMessage(): ?string |
76
|
|
|
{ |
77
|
|
|
return |
78
|
31 |
|
$this->properties[S::MESSAGE]->getValue(); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** {@inheritDoc} */ |
82
|
26 |
|
public function setMessage(?string $message): self |
83
|
|
|
{ |
84
|
26 |
|
$this->properties[S::MESSAGE]->setValue($message); |
85
|
26 |
|
return $this; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** {@inheritDoc} */ |
89
|
2 |
|
public function setMessageSuffix(string $suffix): self |
90
|
|
|
{ |
91
|
2 |
|
$this->properties[S::MESSAGE_SUFFIX]->setValue($suffix); |
92
|
2 |
|
return $this; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** {@inheritDoc} */ |
96
|
28 |
|
public function getMessageSuffix(): string |
97
|
|
|
{ |
98
|
|
|
return |
99
|
28 |
|
$this->properties[S::MESSAGE_SUFFIX]->getValue(); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** {@inheritDoc} */ |
103
|
30 |
|
public function getInlineSpacer(): string |
104
|
|
|
{ |
105
|
|
|
return |
106
|
30 |
|
$this->properties[S::INLINE_SPACER]->getValue(); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** {@inheritDoc} */ |
110
|
3 |
|
public function setInlineSpacer(string $inlineSpacer): self |
111
|
|
|
{ |
112
|
3 |
|
$this->properties[S::INLINE_SPACER]->setValue($inlineSpacer); |
113
|
3 |
|
return $this; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** {@inheritDoc} */ |
117
|
30 |
|
public function getFrames(): array |
118
|
|
|
{ |
119
|
|
|
return |
120
|
30 |
|
$this->properties[S::FRAMES]->getValue(); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** {@inheritDoc} */ |
124
|
40 |
|
public function setFrames(array $frames): self |
125
|
|
|
{ |
126
|
40 |
|
Sentinel::assertFrames($frames); |
127
|
28 |
|
$this->properties[S::FRAMES]->setValue($frames); |
128
|
28 |
|
return $this; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** {@inheritDoc} */ |
132
|
30 |
|
public function getStyles(): array |
133
|
|
|
{ |
134
|
|
|
return |
135
|
30 |
|
$this->properties[S::STYLES]->getValue(); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** {@inheritDoc} */ |
139
|
28 |
|
public function setStyles(array $styles): self |
140
|
|
|
{ |
141
|
28 |
|
$this->properties[S::STYLES]->setValue($styles); |
142
|
28 |
|
return $this; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** {@inheritDoc} */ |
146
|
3 |
|
public function getSpacer(): string |
147
|
|
|
{ |
148
|
|
|
return |
149
|
3 |
|
$this->properties[S::SPACER]->getValue(); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** {@inheritDoc} */ |
153
|
1 |
|
public function setSpacer(string $spacer): self |
154
|
|
|
{ |
155
|
1 |
|
$this->properties[S::SPACER]->setValue($spacer); |
156
|
1 |
|
return $this; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** {@inheritDoc} */ |
160
|
6 |
|
public function merge(self $settings): self |
161
|
|
|
{ |
162
|
6 |
|
$keys = array_keys($this->properties); |
163
|
6 |
|
foreach ($keys as $key) { |
164
|
6 |
|
if ($settings->properties[$key]->isNotDefault()) { |
165
|
5 |
|
$this->properties[$key] = $settings->properties[$key]; |
166
|
|
|
} |
167
|
|
|
} |
168
|
6 |
|
return $this; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** {@inheritDoc} */ |
172
|
12 |
|
public function getInitialPercent(): ?float |
173
|
|
|
{ |
174
|
12 |
|
return $this->properties[S::INITIAL_PERCENT]->getValue(); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** {@inheritDoc} */ |
178
|
12 |
|
public function setInitialPercent(?float $percent): self |
179
|
|
|
{ |
180
|
12 |
|
$this->properties[S::INITIAL_PERCENT]->setValue($percent); |
181
|
12 |
|
return $this; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** {@inheritDoc} */ |
185
|
28 |
|
public function getJugglersOrder(): array |
186
|
|
|
{ |
187
|
28 |
|
return $this->properties[S::JUGGLERS_ORDER]->getValue(); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** {@inheritDoc} */ |
191
|
3 |
|
public function setJugglersOrder(array $order): self |
192
|
|
|
{ |
193
|
3 |
|
$order = array_unique($order); |
194
|
3 |
|
Sentinel::assertJugglersOrder($order); |
195
|
1 |
|
$this->properties[S::JUGGLERS_ORDER]->setValue($order); |
196
|
1 |
|
return $this; |
197
|
|
|
} |
198
|
|
|
} |
199
|
|
|
|