1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Jalle19\StatusManager\Configuration; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class Configuration |
7
|
|
|
* @package Jalle19\StatusManager\Configuration |
8
|
|
|
* @copyright Copyright © Sam Stenvall 2015- |
9
|
|
|
* @license https://www.gnu.org/licenses/gpl.html The GNU General Public License v2.0 |
10
|
|
|
*/ |
11
|
|
|
class Configuration |
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @var string the database path |
16
|
|
|
*/ |
17
|
|
|
private $_databasePath; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var string the log file path |
21
|
|
|
*/ |
22
|
|
|
private $_logPath; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var Instance[] the instances |
26
|
|
|
*/ |
27
|
|
|
private $_instances; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var string the access token used by clients |
31
|
|
|
*/ |
32
|
|
|
private $_accessToken; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var float the status update interval (in seconds) |
36
|
|
|
*/ |
37
|
|
|
private $_updateInterval; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var string the address to listen on |
41
|
|
|
*/ |
42
|
|
|
private $_listenAddress; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var int the port for the WebSocket server to listen on |
46
|
|
|
*/ |
47
|
|
|
private $_listenPort; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var int the port for the HTTP server to listen on |
51
|
|
|
*/ |
52
|
|
|
private $_httpListenPort; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @var string |
56
|
|
|
*/ |
57
|
|
|
private $_httpUsername; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @var string |
61
|
|
|
*/ |
62
|
|
|
private $_httpPassword; |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return string |
67
|
|
|
*/ |
68
|
1 |
|
public function getDatabasePath() |
69
|
|
|
{ |
70
|
1 |
|
return $this->_databasePath; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @param string $databasePath |
76
|
|
|
* |
77
|
|
|
* @return Configuration |
78
|
|
|
*/ |
79
|
1 |
|
public function setDatabasePath($databasePath) |
80
|
|
|
{ |
81
|
1 |
|
$this->_databasePath = $databasePath; |
82
|
|
|
|
83
|
1 |
|
return $this; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return string |
89
|
|
|
*/ |
90
|
1 |
|
public function getLogPath() |
91
|
|
|
{ |
92
|
1 |
|
return $this->_logPath; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @param string $logPath |
98
|
|
|
* |
99
|
|
|
* @return Configuration |
100
|
|
|
*/ |
101
|
1 |
|
public function setLogPath($logPath) |
102
|
|
|
{ |
103
|
1 |
|
$this->_logPath = $logPath; |
104
|
|
|
|
105
|
1 |
|
return $this; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @return Instance[] |
111
|
|
|
*/ |
112
|
3 |
|
public function getInstances() |
113
|
|
|
{ |
114
|
3 |
|
return $this->_instances; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @param Instance[] $instances |
120
|
|
|
* |
121
|
|
|
* @return Configuration |
122
|
|
|
*/ |
123
|
1 |
|
public function setInstances(array $instances) |
124
|
|
|
{ |
125
|
1 |
|
$this->_instances = $instances; |
126
|
|
|
|
127
|
1 |
|
return $this; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @return string |
133
|
|
|
*/ |
134
|
4 |
|
public function getAccessToken() |
135
|
|
|
{ |
136
|
4 |
|
return $this->_accessToken; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @param string $accessToken |
142
|
|
|
* |
143
|
|
|
* @return Configuration |
144
|
|
|
*/ |
145
|
1 |
|
public function setAccessToken($accessToken) |
146
|
|
|
{ |
147
|
1 |
|
$this->_accessToken = $accessToken; |
148
|
|
|
|
149
|
1 |
|
return $this; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @param string $name |
155
|
|
|
* |
156
|
|
|
* @return Instance|null |
157
|
|
|
*/ |
158
|
1 |
|
public function getInstanceByName($name) |
159
|
|
|
{ |
160
|
1 |
|
foreach ($this->_instances as $instance) |
161
|
1 |
|
if ($instance->getName() === $name) |
162
|
1 |
|
return $instance; |
163
|
|
|
|
164
|
1 |
|
return null; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @return float |
170
|
|
|
*/ |
171
|
1 |
|
public function getUpdateInterval() |
172
|
|
|
{ |
173
|
1 |
|
return $this->_updateInterval; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @param $updateInterval |
179
|
|
|
* |
180
|
|
|
* @return Configuration |
181
|
|
|
*/ |
182
|
1 |
|
public function setUpdateInterval($updateInterval) |
183
|
|
|
{ |
184
|
1 |
|
$this->_updateInterval = $updateInterval; |
185
|
|
|
|
186
|
1 |
|
return $this; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* @return string |
192
|
|
|
*/ |
193
|
1 |
|
public function getListenAddress() |
194
|
|
|
{ |
195
|
1 |
|
return $this->_listenAddress; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* @param string $listenAddress |
201
|
|
|
* |
202
|
|
|
* @return Configuration |
203
|
|
|
*/ |
204
|
1 |
|
public function setListenAddress($listenAddress) |
205
|
|
|
{ |
206
|
1 |
|
$this->_listenAddress = $listenAddress; |
207
|
|
|
|
208
|
1 |
|
return $this; |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* @return int |
214
|
|
|
*/ |
215
|
1 |
|
public function getListenPort() |
216
|
|
|
{ |
217
|
1 |
|
return $this->_listenPort; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* @param int $listenPort |
223
|
|
|
* |
224
|
|
|
* @return Configuration |
225
|
|
|
*/ |
226
|
1 |
|
public function setListenPort($listenPort) |
227
|
|
|
{ |
228
|
1 |
|
$this->_listenPort = $listenPort; |
229
|
|
|
|
230
|
1 |
|
return $this; |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
|
234
|
|
|
/** |
235
|
|
|
* @return int |
236
|
|
|
*/ |
237
|
1 |
|
public function getHttpListenPort() |
238
|
|
|
{ |
239
|
1 |
|
return $this->_httpListenPort; |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
|
243
|
|
|
/** |
244
|
|
|
* @param int $httpListenPort |
245
|
|
|
* |
246
|
|
|
* @return Configuration |
247
|
|
|
*/ |
248
|
1 |
|
public function setHttpListenPort($httpListenPort) |
249
|
|
|
{ |
250
|
1 |
|
$this->_httpListenPort = $httpListenPort; |
251
|
|
|
|
252
|
1 |
|
return $this; |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
|
256
|
|
|
/** |
257
|
|
|
* @return string |
258
|
|
|
*/ |
259
|
1 |
|
public function getHttpUsername() |
260
|
|
|
{ |
261
|
1 |
|
return $this->_httpUsername; |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
|
265
|
|
|
/** |
266
|
|
|
* @param string $httpUsername |
267
|
|
|
* |
268
|
|
|
* @return Configuration |
269
|
|
|
*/ |
270
|
1 |
|
public function setHttpUsername($httpUsername) |
271
|
|
|
{ |
272
|
1 |
|
$this->_httpUsername = $httpUsername; |
273
|
|
|
|
274
|
1 |
|
return $this; |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
|
278
|
|
|
/** |
279
|
|
|
* @return string |
280
|
|
|
*/ |
281
|
1 |
|
public function getHttpPassword() |
282
|
|
|
{ |
283
|
1 |
|
return $this->_httpPassword; |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
|
287
|
|
|
/** |
288
|
|
|
* @param string $httpPassword |
289
|
|
|
* |
290
|
|
|
* @return Configuration |
291
|
|
|
*/ |
292
|
1 |
|
public function setHttpPassword($httpPassword) |
293
|
|
|
{ |
294
|
1 |
|
$this->_httpPassword = $httpPassword; |
295
|
|
|
|
296
|
1 |
|
return $this; |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
} |
300
|
|
|
|