|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace AlecRabbit\Spinner\Core; |
|
4
|
|
|
|
|
5
|
|
|
use AlecRabbit\Spinner\Contracts\SettingsInterface; |
|
6
|
|
|
|
|
7
|
|
|
class Settings implements SettingsInterface |
|
8
|
|
|
{ |
|
9
|
|
|
/** @var float */ |
|
10
|
|
|
protected $interval; |
|
11
|
|
|
/** @var null|int */ |
|
12
|
|
|
protected $erasingShift; |
|
13
|
|
|
/** @var null|string */ |
|
14
|
|
|
protected $message; |
|
15
|
|
|
/** @var null|string */ |
|
16
|
|
|
protected $prefix; |
|
17
|
|
|
/** @var null|string */ |
|
18
|
|
|
protected $suffix; |
|
19
|
|
|
/** @var null|string */ |
|
20
|
|
|
protected $inlinePaddingStr; |
|
21
|
|
|
|
|
22
|
|
|
/** @var null|array */ |
|
23
|
|
|
protected $symbols; |
|
24
|
|
|
|
|
25
|
|
|
/** @var array */ |
|
26
|
|
|
protected $styles; |
|
27
|
|
|
|
|
28
|
10 |
|
public function __construct() |
|
29
|
|
|
{ |
|
30
|
10 |
|
$this->defaults(); |
|
31
|
10 |
|
} |
|
32
|
|
|
|
|
33
|
10 |
|
public function defaults(): Settings |
|
34
|
|
|
{ |
|
35
|
|
|
return |
|
36
|
|
|
$this |
|
37
|
10 |
|
->setSuffix(null) |
|
38
|
10 |
|
->setSymbols(null) |
|
39
|
10 |
|
->setStyles(null) |
|
40
|
10 |
|
->setMessage(null) |
|
41
|
10 |
|
->setPrefix(null) |
|
42
|
10 |
|
->setInterval(null) |
|
43
|
10 |
|
->setErasingShift(null) |
|
44
|
10 |
|
->setInlinePaddingStr(null); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @return float |
|
49
|
|
|
*/ |
|
50
|
|
|
public function getInterval(): float |
|
51
|
|
|
{ |
|
52
|
|
|
return $this->interval; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @param null|float $interval |
|
57
|
|
|
* @return Settings |
|
58
|
|
|
*/ |
|
59
|
10 |
|
public function setInterval(?float $interval): Settings |
|
60
|
|
|
{ |
|
61
|
10 |
|
$this->interval = $interval ?? SettingsInterface::DEFAULT_INTERVAL; |
|
62
|
10 |
|
return $this; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @return null|int |
|
67
|
|
|
*/ |
|
68
|
|
|
public function getErasingShift(): ?int |
|
69
|
|
|
{ |
|
70
|
|
|
return $this->erasingShift; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @param null|int $erasingShift |
|
75
|
|
|
* @return Settings |
|
76
|
|
|
*/ |
|
77
|
10 |
|
public function setErasingShift(?int $erasingShift): Settings |
|
78
|
|
|
{ |
|
79
|
10 |
|
$this->erasingShift = $erasingShift ?? SettingsInterface::DEFAULT_ERASING_SHIFT; |
|
80
|
10 |
|
return $this; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @return string |
|
85
|
|
|
*/ |
|
86
|
10 |
|
public function getMessage(): string |
|
87
|
|
|
{ |
|
88
|
10 |
|
return $this->message; |
|
|
|
|
|
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @param null|string $message |
|
93
|
|
|
* @return Settings |
|
94
|
|
|
*/ |
|
95
|
10 |
|
public function setMessage(?string $message): Settings |
|
96
|
|
|
{ |
|
97
|
10 |
|
$this->message = $message ?? SettingsInterface::EMPTY; |
|
98
|
10 |
|
if (SettingsInterface::EMPTY === $this->message) { |
|
99
|
10 |
|
$this->setSuffix(SettingsInterface::EMPTY); |
|
100
|
|
|
} else { |
|
101
|
9 |
|
$this->setSuffix(SettingsInterface::DEFAULT_SUFFIX); |
|
102
|
|
|
} |
|
103
|
10 |
|
return $this; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* @return string |
|
108
|
|
|
*/ |
|
109
|
10 |
|
public function getPrefix(): string |
|
110
|
|
|
{ |
|
111
|
10 |
|
return $this->prefix; |
|
|
|
|
|
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @param null|string $prefix |
|
116
|
|
|
* @return Settings |
|
117
|
|
|
*/ |
|
118
|
10 |
|
public function setPrefix(?string $prefix): Settings |
|
119
|
|
|
{ |
|
120
|
10 |
|
$this->prefix = $prefix ?? SettingsInterface::ONE_SPACE_SYMBOL; |
|
121
|
10 |
|
return $this; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* @return string |
|
126
|
|
|
*/ |
|
127
|
10 |
|
public function getSuffix(): string |
|
128
|
|
|
{ |
|
129
|
10 |
|
return $this->suffix; |
|
|
|
|
|
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* @param null|string $suffix |
|
134
|
|
|
* @return Settings |
|
135
|
|
|
*/ |
|
136
|
10 |
|
public function setSuffix(?string $suffix): Settings |
|
137
|
|
|
{ |
|
138
|
10 |
|
$this->suffix = $suffix ?? SettingsInterface::DEFAULT_SUFFIX; |
|
139
|
10 |
|
return $this; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* @return string |
|
144
|
|
|
*/ |
|
145
|
10 |
|
public function getInlinePaddingStr(): string |
|
146
|
|
|
{ |
|
147
|
10 |
|
return $this->inlinePaddingStr; |
|
|
|
|
|
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* @param null|string $inlinePaddingStr |
|
152
|
|
|
* @return Settings |
|
153
|
|
|
*/ |
|
154
|
10 |
|
public function setInlinePaddingStr(?string $inlinePaddingStr): Settings |
|
155
|
|
|
{ |
|
156
|
10 |
|
$this->inlinePaddingStr = $inlinePaddingStr ?? SettingsInterface::EMPTY; |
|
157
|
10 |
|
return $this; |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* @return array |
|
162
|
|
|
*/ |
|
163
|
10 |
|
public function getSymbols(): array |
|
164
|
|
|
{ |
|
165
|
10 |
|
return $this->symbols; |
|
|
|
|
|
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* @param null|array $symbols |
|
170
|
|
|
* @return Settings |
|
171
|
|
|
*/ |
|
172
|
10 |
|
public function setSymbols(?array $symbols): Settings |
|
173
|
|
|
{ |
|
174
|
10 |
|
$this->symbols = $symbols ?? static::DEFAULT_SYMBOLS; |
|
175
|
10 |
|
return $this; |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
/** |
|
179
|
|
|
* @return array |
|
180
|
|
|
*/ |
|
181
|
10 |
|
public function getStyles(): array |
|
182
|
|
|
{ |
|
183
|
10 |
|
return $this->styles; |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
/** |
|
187
|
|
|
* @param null|array $styles |
|
188
|
|
|
* @return Settings |
|
189
|
|
|
*/ |
|
190
|
10 |
|
public function setStyles(?array $styles): Settings |
|
191
|
|
|
{ |
|
192
|
10 |
|
$this->styles = array_merge(static::DEFAULT_STYLES, $styles ?? []); |
|
193
|
10 |
|
return $this; |
|
194
|
|
|
} |
|
195
|
|
|
} |
|
196
|
|
|
|