1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Broker.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\Configuration; |
18
|
|
|
|
19
|
|
|
use Nette; |
20
|
|
|
|
21
|
|
|
use IPub\MQTTClient\Exceptions; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* MQTT client broker configuration |
25
|
|
|
* |
26
|
|
|
* @package iPublikuj:MQTTClient! |
27
|
|
|
* @subpackage Client |
28
|
|
|
* |
29
|
|
|
* @author Adam Kadlec <[email protected]> |
30
|
|
|
*/ |
31
|
1 |
|
final class Broker |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* Implement nette smart magic |
35
|
|
|
*/ |
36
|
1 |
|
use Nette\SmartObject; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var string |
40
|
|
|
*/ |
41
|
|
|
private $httpHost; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var int |
45
|
|
|
*/ |
46
|
|
|
private $port; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var string |
50
|
|
|
*/ |
51
|
|
|
private $address; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @var bool |
55
|
|
|
*/ |
56
|
|
|
private $enableSSL = FALSE; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @var array |
60
|
|
|
*/ |
61
|
|
|
private $sslSettings = []; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @var Connection |
65
|
|
|
*/ |
66
|
|
|
private $connection; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param string|NULL $httpHost |
70
|
|
|
* @param int $port |
71
|
|
|
* @param string|NULL $address |
72
|
|
|
* @param bool $enableSSL |
73
|
|
|
* @param array $sslSettings |
74
|
|
|
* @param Connection $connection |
75
|
|
|
*/ |
76
|
|
|
public function __construct( |
77
|
|
|
string $httpHost = NULL, |
78
|
|
|
int $port = 1883, |
79
|
|
|
string $address = NULL, |
80
|
|
|
bool $enableSSL = FALSE, |
81
|
|
|
array $sslSettings = [], |
82
|
|
|
Connection $connection |
83
|
|
|
) { |
84
|
1 |
|
$this->httpHost = $httpHost; |
85
|
1 |
|
$this->port = $port; |
86
|
1 |
|
$this->address = $address; |
87
|
1 |
|
$this->enableSSL = $enableSSL; |
88
|
1 |
|
$this->sslSettings = $sslSettings; |
89
|
1 |
|
$this->connection = $connection; |
90
|
1 |
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return string |
94
|
|
|
* |
95
|
|
|
* @throws Exceptions\InvalidStateException |
96
|
|
|
*/ |
97
|
|
|
public function getUri() : string |
98
|
|
|
{ |
99
|
|
|
if ($this->httpHost !== NULL) { |
100
|
|
|
return $this->httpHost . ':' . $this->port; |
101
|
|
|
|
102
|
|
|
} elseif ($this->address !== NULL) { |
103
|
|
|
return $this->address . ':' . $this->port; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
throw new Exceptions\InvalidStateException('Broker http host or address is not specified'); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @return string|NULL |
111
|
|
|
*/ |
112
|
|
|
public function getHttpHost() : ?string |
113
|
|
|
{ |
114
|
|
|
return $this->httpHost; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @return int |
119
|
|
|
*/ |
120
|
|
|
public function getPort() : int |
121
|
|
|
{ |
122
|
|
|
return $this->port; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @return string|NULL |
127
|
|
|
*/ |
128
|
|
|
public function getAddress() : ?string |
129
|
|
|
{ |
130
|
|
|
return $this->address; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @return bool |
135
|
|
|
*/ |
136
|
|
|
public function isSSLEnabled() : bool |
137
|
|
|
{ |
138
|
|
|
return $this->enableSSL; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @return array |
143
|
|
|
*/ |
144
|
|
|
public function getSSLConfiguration() : array |
145
|
|
|
{ |
146
|
|
|
return $this->sslSettings; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @return Connection |
151
|
|
|
*/ |
152
|
|
|
public function getConnection() : Connection |
153
|
|
|
{ |
154
|
|
|
return $this->connection; |
155
|
|
|
} |
156
|
|
|
} |
157
|
|
|
|