Completed
Push — master ( 3c24ea...404feb )
by Sam
02:45
created

Configuration::getAccessToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Jalle19\StatusManager\Configuration;
4
5
/**
6
 * Class Configuration
7
 * @package   Jalle19\StatusManager\Configuration
8
 * @copyright Copyright &copy; 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
	const SECTION_TYPE_INSTANCE = 'instance';
15
16
	const OPTION_UPDATE_INTERVAL = 'updateInterval';
17
	const OPTION_LISTEN_ADDRESS  = 'listenAddress';
18
	const OPTION_LISTEN_PORT     = 'listenPort';
19
20
	const DEFAULT_UPDATE_INTERVAL = 2;
21
	const DEFAULT_LISTEN_ADDRESS  = '0.0.0.0';
22
	const DEFAULT_LISTEN_PORT     = 9333;
23
24
	/**
25
	 * @var string the database path
26
	 */
27
	private $_databasePath;
28
29
	/**
30
	 * @var string the log file path
31
	 */
32
	private $_logPath;
33
34
	/**
35
	 * @var Instance[] the instances
36
	 */
37
	private $_instances;
38
39
	/**
40
	 * @var string the access token used by clients
41
	 */
42
	private $_accessToken;
43
44
	/**
45
	 * @var float the status update interval (in seconds)
46
	 */
47
	private $_updateInterval = self::DEFAULT_UPDATE_INTERVAL;
48
49
	/**
50
	 * @var string the address to listen on
51
	 */
52
	private $_listenAddress = self::DEFAULT_LISTEN_ADDRESS;
53
54
	/**
55
	 * @var int the port to listen on
56
	 */
57
	private $_listenPort = self::DEFAULT_LISTEN_PORT;
58
59
60
	/**
61
	 * @param string     $databasePath
62
	 * @param Instance[] $_instances
63
	 * @param string     $accessToken
64
	 */
65
	public function __construct($databasePath, array $_instances, $accessToken)
66
	{
67
		$this->_databasePath = $databasePath;
68
		$this->_instances    = $_instances;
69
		$this->_accessToken  = $accessToken;
70
	}
71
72
73
	/**
74
	 * @return string
75
	 */
76
	public function getDatabasePath()
77
	{
78
		return $this->_databasePath;
79
	}
80
81
82
	/**
83
	 * @return string
84
	 */
85
	public function getLogPath()
86
	{
87
		return $this->_logPath;
88
	}
89
90
91
	/**
92
	 * @param string $logPath
93
	 */
94
	public function setLogPath($logPath)
95
	{
96
		$this->_logPath = $logPath;
97
	}
98
99
100
	/**
101
	 * @return Instance[]
102
	 */
103 2
	public function getInstances()
104
	{
105 2
		return $this->_instances;
106
	}
107
108
109
	/**
110
	 * @return string
111
	 */
112
	public function getAccessToken()
113
	{
114
		return $this->_accessToken;
115
	}
116
117
118
	/**
119
	 * @param string $name
120
	 *
121
	 * @return Instance|null
122
	 */
123
	public function getInstanceByName($name)
124
	{
125
		foreach ($this->_instances as $instance)
126
			if ($instance->getName() === $name)
127
				return $instance;
128
129
		return null;
130
	}
131
132
133
	/**
134
	 * @return float
135
	 */
136
	public function getUpdateInterval()
137
	{
138
		return $this->_updateInterval;
139
	}
140
141
142
	/**
143
	 * @param $updateInterval
144
	 *
145
	 * @throws \RuntimeException
146
	 */
147
	public function setUpdateInterval($updateInterval)
148
	{
149
		if ($updateInterval <= 0)
150
			throw new \RuntimeException('Invalid update interval specified');
151
152
		$this->_updateInterval = $updateInterval;
153
	}
154
155
156
	/**
157
	 * @return string
158
	 */
159
	public function getListenAddress()
160
	{
161
		return $this->_listenAddress;
162
	}
163
164
165
	/**
166
	 * @param string $listenAddress
167
	 */
168
	public function setListenAddress($listenAddress)
169
	{
170
		$this->_listenAddress = $listenAddress;
171
	}
172
173
174
	/**
175
	 * @return int
176
	 */
177
	public function getListenPort()
178
	{
179
		return $this->_listenPort;
180
	}
181
182
183
	/**
184
	 * @param int $listenPort
185
	 *
186
	 * @throws \RuntimeException
187
	 */
188
	public function setListenPort($listenPort)
189
	{
190
		if ($listenPort < 1 || $listenPort > 65535)
191
			throw new \RuntimeException('Invalid port specified');
192
193
		$this->_listenPort = $listenPort;
194
	}
195
196
}
197