1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Configuration.php |
4
|
|
|
* |
5
|
|
|
* @copyright More in license.md |
6
|
|
|
* @license http://www.ipublikuj.eu |
7
|
|
|
* @author Adam Kadlec http://www.ipublikuj.eu |
8
|
|
|
* @package iPublikuj:MQTTClient! |
9
|
|
|
* @subpackage Client |
10
|
|
|
* @since 1.0.0 |
11
|
|
|
* |
12
|
|
|
* @date 14.03.17 |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
declare(strict_types = 1); |
16
|
|
|
|
17
|
|
|
namespace IPub\MQTTClient\Client; |
18
|
|
|
|
19
|
|
|
use Nette; |
20
|
|
|
|
21
|
|
|
use BinSoul\Net\Mqtt; |
22
|
|
|
|
23
|
|
|
use IPub\MQTTClient\Exceptions; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* MQTT client configuration container |
27
|
|
|
* |
28
|
|
|
* @package iPublikuj:MQTTClient! |
29
|
|
|
* @subpackage Client |
30
|
|
|
* |
31
|
|
|
* @author Adam Kadlec <[email protected]> |
32
|
|
|
*/ |
33
|
1 |
|
final class Configuration |
34
|
|
|
{ |
35
|
|
|
/** |
36
|
|
|
* Implement nette smart magic |
37
|
|
|
*/ |
38
|
1 |
|
use Nette\SmartObject; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var string |
42
|
|
|
*/ |
43
|
|
|
private $httpHost; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var int |
47
|
|
|
*/ |
48
|
|
|
private $port; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var string |
52
|
|
|
*/ |
53
|
|
|
private $address; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var bool |
57
|
|
|
*/ |
58
|
|
|
private $enableDNS = TRUE; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @var string |
62
|
|
|
*/ |
63
|
|
|
private $dnsAddress; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @var bool |
67
|
|
|
*/ |
68
|
|
|
private $enableSSL = FALSE; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @var array |
72
|
|
|
*/ |
73
|
|
|
private $sslSettings = []; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @var Mqtt\Connection |
77
|
|
|
*/ |
78
|
|
|
private $connection; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param string|NULL $httpHost |
82
|
|
|
* @param int $port |
83
|
|
|
* @param string|NULL $address |
84
|
|
|
* @param bool $enableDNS |
85
|
|
|
* @param string $dnsAddress |
86
|
|
|
* @param bool $enableSSL |
87
|
|
|
* @param array $sslSettings |
88
|
|
|
* @param Mqtt\Connection $connection |
89
|
|
|
*/ |
90
|
|
|
public function __construct( |
91
|
|
|
string $httpHost = NULL, |
92
|
|
|
int $port = 1883, |
93
|
|
|
string $address = NULL, |
94
|
|
|
bool $enableDNS = TRUE, |
95
|
|
|
string $dnsAddress = '8.8.8.8', |
96
|
|
|
bool $enableSSL = FALSE, |
97
|
|
|
array $sslSettings, |
98
|
|
|
Mqtt\Connection $connection |
99
|
|
|
) { |
100
|
1 |
|
$this->httpHost = $httpHost; |
101
|
1 |
|
$this->port = $port; |
102
|
1 |
|
$this->address = $address; |
103
|
1 |
|
$this->enableDNS = $enableDNS; |
104
|
1 |
|
$this->dnsAddress = $dnsAddress; |
105
|
1 |
|
$this->enableSSL = $enableSSL; |
106
|
1 |
|
$this->sslSettings = $sslSettings; |
107
|
1 |
|
$this->connection = $connection; |
108
|
1 |
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @return string |
112
|
|
|
* |
113
|
|
|
* @throws Exceptions\InvalidStateException |
114
|
|
|
*/ |
115
|
|
|
public function getUri() : string |
116
|
|
|
{ |
117
|
|
|
if ($this->httpHost !== NULL) { |
118
|
|
|
return $this->httpHost .':'. $this->port; |
119
|
|
|
|
120
|
|
|
} elseif ($this->address !== NULL) { |
121
|
|
|
return $this->address .':'. $this->port; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
throw new Exceptions\InvalidStateException('Broker http host or address is not specified'); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @return string|NULL |
129
|
|
|
*/ |
130
|
|
|
public function getHttpHost() : ?string |
131
|
|
|
{ |
132
|
|
|
return $this->httpHost; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @return int |
137
|
|
|
*/ |
138
|
|
|
public function getPort() : int |
139
|
|
|
{ |
140
|
|
|
return $this->port; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @return string|NULL |
145
|
|
|
*/ |
146
|
|
|
public function getAddress() : ?string |
147
|
|
|
{ |
148
|
|
|
return $this->address; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @return bool |
153
|
|
|
*/ |
154
|
|
|
public function isDNSEnabled() : bool |
155
|
|
|
{ |
156
|
1 |
|
return $this->enableDNS; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @return string |
161
|
|
|
*/ |
162
|
|
|
public function getDNSAddress() : string |
163
|
|
|
{ |
164
|
1 |
|
return $this->dnsAddress; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @return bool |
169
|
|
|
*/ |
170
|
|
|
public function isSSLEnabled() : bool |
171
|
|
|
{ |
172
|
1 |
|
return $this->enableSSL; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* @return array |
177
|
|
|
*/ |
178
|
|
|
public function getSSLConfiguration() : array |
179
|
|
|
{ |
180
|
|
|
return $this->sslSettings; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* @return Mqtt\Connection |
185
|
|
|
*/ |
186
|
|
|
public function getConnection() : Mqtt\Connection |
187
|
|
|
{ |
188
|
|
|
return $this->connection; |
189
|
|
|
} |
190
|
|
|
} |
191
|
|
|
|