1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace WSSC\Components; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use WSSC\Contracts\WscCommonsContract; |
7
|
|
|
|
8
|
|
|
class ClientConfig |
9
|
|
|
{ |
10
|
|
|
|
11
|
|
|
private $scheme; |
12
|
|
|
private $host; |
13
|
|
|
private $user; |
14
|
|
|
private $password; |
15
|
|
|
private $port; |
16
|
|
|
|
17
|
|
|
private $timeout = WscCommonsContract::DEFAULT_TIMEOUT; |
18
|
|
|
private $headers = []; |
19
|
|
|
private $fragmentSize = WscCommonsContract::DEFAULT_FRAGMENT_SIZE; |
20
|
|
|
private $context; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @return int |
24
|
|
|
*/ |
25
|
|
|
public function getTimeout(): int |
26
|
|
|
{ |
27
|
|
|
return $this->timeout; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param int $timeout |
32
|
|
|
*/ |
33
|
|
|
public function setTimeout(int $timeout) |
34
|
|
|
{ |
35
|
|
|
$this->timeout = $timeout; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @return array |
40
|
|
|
*/ |
41
|
|
|
public function getHeaders(): array |
42
|
|
|
{ |
43
|
|
|
return $this->headers; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param array $headers |
48
|
|
|
*/ |
49
|
|
|
public function setHeaders(array $headers) |
50
|
|
|
{ |
51
|
|
|
$this->headers = $headers; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return int |
56
|
|
|
*/ |
57
|
|
|
public function getFragmentSize(): int |
58
|
|
|
{ |
59
|
|
|
return $this->fragmentSize; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param int $fragmentSize |
64
|
|
|
*/ |
65
|
|
|
public function setFragmentSize(int $fragmentSize) |
66
|
|
|
{ |
67
|
|
|
$this->fragmentSize = $fragmentSize; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return mixed |
72
|
|
|
*/ |
73
|
|
|
public function getContext() |
74
|
|
|
{ |
75
|
|
|
return $this->context; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param mixed $context |
80
|
|
|
*/ |
81
|
|
|
public function setContext($context) |
82
|
|
|
{ |
83
|
|
|
$this->context = $context; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return mixed |
88
|
|
|
*/ |
89
|
|
|
public function getScheme(): string |
90
|
|
|
{ |
91
|
|
|
return $this->scheme; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @param void $scheme |
96
|
|
|
*/ |
97
|
|
|
public function setScheme($scheme): void |
98
|
|
|
{ |
99
|
|
|
$this->scheme = $scheme; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @return string |
104
|
|
|
*/ |
105
|
|
|
public function getHost(): string |
106
|
|
|
{ |
107
|
|
|
return $this->host; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @param void $host |
112
|
|
|
*/ |
113
|
|
|
public function setHost($host): void |
114
|
|
|
{ |
115
|
|
|
$this->host = $host; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @return string |
120
|
|
|
*/ |
121
|
|
|
public function getUser(): string |
122
|
|
|
{ |
123
|
|
|
return $this->user; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @param array $urlParts |
128
|
|
|
*/ |
129
|
|
|
public function setUser(array $urlParts): void |
130
|
|
|
{ |
131
|
|
|
$this->user = isset($urlParts['user']) ? $urlParts['user'] : ''; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @return string |
136
|
|
|
*/ |
137
|
|
|
public function getPassword(): string |
138
|
|
|
{ |
139
|
|
|
return $this->password; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @param array $urlParts |
144
|
|
|
*/ |
145
|
|
|
public function setPassword(array $urlParts): void |
146
|
|
|
{ |
147
|
|
|
$this->password = isset($urlParts['pass']) ? $urlParts['pass'] : ''; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @return string |
152
|
|
|
*/ |
153
|
|
|
public function getPort(): string |
154
|
|
|
{ |
155
|
|
|
return $this->port; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @param array $urlParts |
160
|
|
|
*/ |
161
|
|
|
public function setPort(array $urlParts): void |
162
|
|
|
{ |
163
|
|
|
$this->port = isset($urlParts['port']) ? $urlParts['port'] : ($this->scheme === 'wss' ? 443 : 80); |
164
|
|
|
} |
165
|
|
|
} |