1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace WSSC\Components; |
4
|
|
|
|
5
|
|
|
use WSSC\Contracts\WscCommonsContract; |
6
|
|
|
|
7
|
|
|
class ClientConfig |
8
|
|
|
{ |
9
|
|
|
private $scheme; |
10
|
|
|
private $host; |
11
|
|
|
private $user; |
12
|
|
|
private $password; |
13
|
|
|
private $port; |
14
|
|
|
|
15
|
|
|
private $timeout = WscCommonsContract::DEFAULT_TIMEOUT; |
16
|
|
|
private $headers = []; |
17
|
|
|
private $fragmentSize = WscCommonsContract::DEFAULT_FRAGMENT_SIZE; |
18
|
|
|
private $context; |
19
|
|
|
|
20
|
|
|
// proxy settings |
21
|
|
|
private $hasProxy = false; |
22
|
|
|
private $proxyIp; |
23
|
|
|
private $proxyPort; |
24
|
|
|
private $proxyAuth; |
25
|
|
|
|
26
|
|
|
private $contextOptions = []; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @return int |
30
|
|
|
*/ |
31
|
|
|
public function getTimeout(): int |
32
|
|
|
{ |
33
|
|
|
return $this->timeout; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param int $timeout |
38
|
|
|
*/ |
39
|
|
|
public function setTimeout(int $timeout) |
40
|
|
|
{ |
41
|
|
|
$this->timeout = $timeout; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return array |
46
|
|
|
*/ |
47
|
|
|
public function getHeaders(): array |
48
|
|
|
{ |
49
|
|
|
return $this->headers; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param array $headers |
54
|
|
|
*/ |
55
|
|
|
public function setHeaders(array $headers) |
56
|
|
|
{ |
57
|
|
|
$this->headers = $headers; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return int |
62
|
|
|
*/ |
63
|
|
|
public function getFragmentSize(): int |
64
|
|
|
{ |
65
|
|
|
return $this->fragmentSize; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param int $fragmentSize |
70
|
|
|
*/ |
71
|
|
|
public function setFragmentSize(int $fragmentSize) |
72
|
|
|
{ |
73
|
|
|
$this->fragmentSize = $fragmentSize; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @return mixed |
78
|
|
|
*/ |
79
|
|
|
public function getContext() |
80
|
|
|
{ |
81
|
|
|
return $this->context; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @param mixed $context |
86
|
|
|
*/ |
87
|
|
|
public function setContext($context) |
88
|
|
|
{ |
89
|
|
|
$this->context = $context; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return mixed |
94
|
|
|
*/ |
95
|
|
|
public function getScheme(): string |
96
|
|
|
{ |
97
|
|
|
return $this->scheme; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @param void $scheme |
102
|
|
|
*/ |
103
|
|
|
public function setScheme($scheme): void |
104
|
|
|
{ |
105
|
|
|
$this->scheme = $scheme; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @return string |
110
|
|
|
*/ |
111
|
|
|
public function getHost(): string |
112
|
|
|
{ |
113
|
|
|
return $this->host; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @param void $host |
118
|
|
|
*/ |
119
|
|
|
public function setHost($host): void |
120
|
|
|
{ |
121
|
|
|
$this->host = $host; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @return string |
126
|
|
|
*/ |
127
|
|
|
public function getUser(): string |
128
|
|
|
{ |
129
|
|
|
return $this->user; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @param array $urlParts |
134
|
|
|
*/ |
135
|
|
|
public function setUser(array $urlParts): void |
136
|
|
|
{ |
137
|
|
|
$this->user = isset($urlParts['user']) ? $urlParts['user'] : ''; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @return string |
142
|
|
|
*/ |
143
|
|
|
public function getPassword(): string |
144
|
|
|
{ |
145
|
|
|
return $this->password; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @param array $urlParts |
150
|
|
|
*/ |
151
|
|
|
public function setPassword(array $urlParts): void |
152
|
|
|
{ |
153
|
|
|
$this->password = isset($urlParts['pass']) ? $urlParts['pass'] : ''; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* @return string |
158
|
|
|
*/ |
159
|
|
|
public function getPort(): string |
160
|
|
|
{ |
161
|
|
|
return $this->port; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @param array $urlParts |
166
|
|
|
*/ |
167
|
|
|
public function setPort(array $urlParts): void |
168
|
|
|
{ |
169
|
|
|
$this->port = isset($urlParts['port']) ? $urlParts['port'] : ($this->scheme === 'wss' ? '443' : '80'); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @return array |
174
|
|
|
*/ |
175
|
|
|
public function getContextOptions(): array |
176
|
|
|
{ |
177
|
|
|
return $this->contextOptions; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* @param array $contextOptions |
182
|
|
|
*/ |
183
|
|
|
public function setContextOptions($contextOptions): void |
184
|
|
|
{ |
185
|
|
|
$this->contextOptions = $contextOptions; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* @param string $ip |
190
|
|
|
* @param string $port |
191
|
|
|
*/ |
192
|
|
|
public function setProxy(string $ip, string $port): void |
193
|
|
|
{ |
194
|
|
|
$this->hasProxy = true; |
195
|
|
|
$this->proxyIp = $ip; |
196
|
|
|
$this->proxyPort = $port; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* Sets auth for proxy |
201
|
|
|
* |
202
|
|
|
* @param string $userName |
203
|
|
|
* @param string $password |
204
|
|
|
*/ |
205
|
|
|
public function setProxyAuth(string $userName, string $password): void |
206
|
|
|
{ |
207
|
|
|
$this->proxyAuth = (empty($userName) === false && empty($password) === false) ? base64_encode($userName.':'.$password) : null; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* @return bool |
212
|
|
|
*/ |
213
|
|
|
public function hasProxy() : bool |
214
|
|
|
{ |
215
|
|
|
return $this->hasProxy; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* @return string|null |
220
|
|
|
*/ |
221
|
|
|
public function getProxyIp() : ?string |
222
|
|
|
{ |
223
|
|
|
return $this->proxyIp; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* @return string|null |
228
|
|
|
*/ |
229
|
|
|
public function getProxyPort() : ?string |
230
|
|
|
{ |
231
|
|
|
return $this->proxyPort; |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
/** |
235
|
|
|
* @return string|null |
236
|
|
|
*/ |
237
|
|
|
public function getProxyAuth() : ?string |
238
|
|
|
{ |
239
|
|
|
return $this->proxyAuth; |
240
|
|
|
} |
241
|
|
|
} |
242
|
|
|
|