1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
namespace ClickHouseDB; |
4
|
|
|
|
5
|
|
|
class Settings |
6
|
|
|
{ |
7
|
|
|
/** |
|
|
|
|
8
|
|
|
* @var array |
|
|
|
|
9
|
|
|
*/ |
10
|
|
|
private $settings = []; |
11
|
|
|
|
12
|
|
|
private $_ReadOnlyUser = false; |
|
|
|
|
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Settings constructor. |
|
|
|
|
16
|
|
|
*/ |
17
|
|
|
public function __construct() |
18
|
|
|
{ |
19
|
|
|
$default = [ |
20
|
|
|
'extremes' => false, |
21
|
|
|
'readonly' => true, |
22
|
|
|
'max_execution_time' => 20.0, |
23
|
|
|
'enable_http_compression' => 1, |
24
|
|
|
'https' => false, |
25
|
|
|
]; |
26
|
|
|
|
27
|
|
|
$this->settings = $default; |
28
|
|
|
} |
29
|
|
|
|
30
|
68 |
|
/** |
31
|
|
|
* @param string|int $key |
|
|
|
|
32
|
|
|
* @return mixed |
33
|
68 |
|
*/ |
34
|
|
|
public function get($key) |
35
|
|
|
{ |
36
|
|
|
if (!$this->is($key)) { |
|
|
|
|
37
|
|
|
return null; |
38
|
|
|
} |
39
|
|
|
return $this->settings[$key]; |
|
|
|
|
40
|
68 |
|
} |
41
|
68 |
|
|
42
|
68 |
|
/** |
43
|
|
|
* @param string|int $key |
|
|
|
|
44
|
|
|
* @return bool |
45
|
|
|
*/ |
46
|
|
|
public function is($key) |
|
|
|
|
47
|
|
|
{ |
48
|
55 |
|
return isset($this->settings[$key]); |
49
|
|
|
} |
|
|
|
|
50
|
55 |
|
|
51
|
|
|
|
52
|
|
|
/** |
53
|
55 |
|
* @param string|int $key |
|
|
|
|
54
|
|
|
* @param mixed $value |
|
|
|
|
55
|
|
|
* @return $this |
56
|
|
|
*/ |
57
|
|
|
public function set($key, $value) |
58
|
|
|
{ |
59
|
|
|
$this->settings[$key] = $value; |
60
|
55 |
|
return $this; |
|
|
|
|
61
|
|
|
} |
62
|
55 |
|
|
63
|
|
|
/** |
64
|
|
|
* @return mixed |
65
|
|
|
*/ |
66
|
|
|
public function getDatabase() |
67
|
|
|
{ |
68
|
|
|
return $this->get('database'); |
69
|
|
|
} |
70
|
|
|
|
71
|
68 |
|
/** |
72
|
|
|
* @param string $db |
|
|
|
|
73
|
68 |
|
* @return $this |
74
|
68 |
|
*/ |
75
|
|
|
public function database($db) |
|
|
|
|
76
|
|
|
{ |
77
|
|
|
$this->set('database', $db); |
78
|
|
|
return $this; |
|
|
|
|
79
|
|
|
} |
80
|
1 |
|
|
81
|
|
|
/** |
82
|
1 |
|
* @return int |
|
|
|
|
83
|
|
|
*/ |
84
|
|
|
public function getTimeOut(): int |
|
|
|
|
85
|
|
|
{ |
86
|
|
|
return intval($this->get('max_execution_time')); |
|
|
|
|
87
|
|
|
} |
88
|
|
|
|
89
|
68 |
|
/** |
90
|
|
|
* @return mixed|null |
91
|
68 |
|
*/ |
92
|
68 |
|
public function isEnableHttpCompression() |
93
|
|
|
{ |
94
|
|
|
return $this->getSetting('enable_http_compression'); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
46 |
|
* @param bool|int $flag |
|
|
|
|
99
|
|
|
* @return $this |
100
|
46 |
|
*/ |
101
|
|
|
public function enableHttpCompression($flag) |
102
|
|
|
{ |
103
|
|
|
$this->set('enable_http_compression', intval($flag)); |
|
|
|
|
104
|
|
|
return $this; |
|
|
|
|
105
|
|
|
} |
|
|
|
|
106
|
45 |
|
|
107
|
|
|
|
108
|
45 |
|
public function https($flag = true) |
|
|
|
|
109
|
|
|
{ |
110
|
|
|
$this->set('https', $flag); |
111
|
|
|
return $this; |
|
|
|
|
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function isHttps() |
|
|
|
|
115
|
68 |
|
{ |
116
|
|
|
return $this->get('https'); |
117
|
68 |
|
} |
|
|
|
|
118
|
68 |
|
|
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @param int|bool $flag |
|
|
|
|
122
|
1 |
|
* @return $this |
123
|
|
|
*/ |
124
|
1 |
|
public function readonly($flag) |
125
|
1 |
|
{ |
126
|
|
|
$this->set('readonly', $flag); |
127
|
|
|
return $this; |
|
|
|
|
128
|
55 |
|
} |
129
|
|
|
|
130
|
55 |
|
/** |
131
|
|
|
* @param string $session_id |
|
|
|
|
132
|
|
|
* @return $this |
133
|
|
|
*/ |
134
|
|
|
public function session_id($session_id) |
|
|
|
|
135
|
|
|
{ |
136
|
|
|
$this->set('session_id', $session_id); |
|
|
|
|
137
|
|
|
return $this; |
|
|
|
|
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @return mixed|bool |
142
|
|
|
*/ |
143
|
|
|
public function getSessionId() |
144
|
|
|
{ |
145
|
|
|
if (empty($this->settings['session_id'])) { |
|
|
|
|
146
|
|
|
return false; |
147
|
|
|
} |
148
|
2 |
|
return $this->get('session_id'); |
|
|
|
|
149
|
|
|
} |
150
|
2 |
|
|
151
|
2 |
|
/** |
152
|
|
|
* @return string|bool |
153
|
|
|
*/ |
154
|
|
|
public function makeSessionId() |
155
|
|
|
{ |
156
|
|
|
$this->session_id(sha1(uniqid('', true))); |
|
|
|
|
157
|
46 |
|
return $this->getSessionId(); |
|
|
|
|
158
|
|
|
} |
159
|
46 |
|
|
160
|
46 |
|
/** |
161
|
|
|
* |
162
|
2 |
|
* max_execution_time - is integer in Seconds clickhouse source |
|
|
|
|
163
|
|
|
* |
164
|
|
|
* @param int $time |
|
|
|
|
165
|
|
|
* @return $this |
166
|
|
|
*/ |
167
|
|
|
public function max_execution_time(int $time) |
|
|
|
|
168
|
2 |
|
{ |
169
|
|
|
$this->set('max_execution_time',$time); |
170
|
2 |
|
return $this; |
|
|
|
|
171
|
2 |
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* @return array |
|
|
|
|
175
|
|
|
*/ |
176
|
|
|
public function getSettings() |
|
|
|
|
177
|
|
|
{ |
178
|
2 |
|
return $this->settings; |
179
|
|
|
} |
180
|
2 |
|
|
181
|
2 |
|
/** |
182
|
|
|
* @param array $settings_array |
|
|
|
|
183
|
|
|
* @return $this |
184
|
|
|
*/ |
185
|
|
|
public function apply(array $settings_array) |
|
|
|
|
186
|
|
|
{ |
187
|
45 |
|
foreach ($settings_array as $key => $value) { |
|
|
|
|
188
|
|
|
$this->set($key, $value); |
189
|
45 |
|
} |
190
|
|
|
|
191
|
|
|
return $this; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* @param int|bool $flag |
196
|
1 |
|
*/ |
197
|
|
|
public function setReadOnlyUser($flag):void |
|
|
|
|
198
|
1 |
|
{ |
199
|
1 |
|
$this->_ReadOnlyUser = $flag; |
|
|
|
|
200
|
|
|
} |
201
|
|
|
|
202
|
1 |
|
/** |
203
|
|
|
* @return bool |
|
|
|
|
204
|
|
|
*/ |
205
|
|
|
public function isReadOnlyUser():bool |
|
|
|
|
206
|
|
|
{ |
207
|
|
|
return $this->_ReadOnlyUser; |
|
|
|
|
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* @param string $name |
|
|
|
|
212
|
|
|
* @return mixed|null |
213
|
|
|
*/ |
214
|
|
|
public function getSetting(string $name) |
215
|
|
|
{ |
216
|
45 |
|
if (!isset($this->settings[$name])) { |
|
|
|
|
217
|
|
|
return null; |
218
|
45 |
|
} |
219
|
|
|
|
220
|
|
|
return $this->get($name); |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
public function clear():void |
|
|
|
|
224
|
|
|
{ |
225
|
46 |
|
$this->settings = []; |
226
|
|
|
} |
227
|
|
|
} |
228
|
|
|
|