|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
|
|
3
|
|
|
namespace ClickHouseDB; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* @see https://clickhouse.yandex/docs/en/operations/settings/ |
|
7
|
|
|
*/ |
|
8
|
|
|
class Settings |
|
9
|
|
|
{ |
|
10
|
|
|
/** @var mixed[] */ |
|
11
|
|
|
private $settings = []; |
|
12
|
|
|
|
|
13
|
|
|
/** @var bool */ |
|
14
|
|
|
private $httpCompressionEnabled = false; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @return mixed|null |
|
18
|
|
|
*/ |
|
19
|
3 |
|
public function get(string $key) |
|
20
|
|
|
{ |
|
21
|
3 |
|
if (! $this->isSet($key)) { |
|
22
|
|
|
return null; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
3 |
|
return $this->settings[$key]; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
4 |
|
public function isSet(string $key) : bool |
|
29
|
|
|
{ |
|
30
|
4 |
|
return isset($this->settings[$key]); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param mixed $value |
|
35
|
|
|
*/ |
|
36
|
7 |
|
public function set(string $key, $value) : void |
|
37
|
|
|
{ |
|
38
|
7 |
|
$this->settings[$key] = $value; |
|
39
|
7 |
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @return mixed|null |
|
43
|
|
|
*/ |
|
44
|
63 |
|
public function isHttpCompressionEnabled() |
|
45
|
|
|
{ |
|
46
|
63 |
|
return $this->httpCompressionEnabled; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
63 |
|
public function setHttpCompression(bool $enable) : self |
|
50
|
|
|
{ |
|
51
|
63 |
|
$this->httpCompressionEnabled = $enable; |
|
52
|
|
|
|
|
53
|
63 |
|
return $this; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function readonly(int $flag) : self |
|
57
|
|
|
{ |
|
58
|
|
|
$this->set('readonly', $flag); |
|
59
|
|
|
|
|
60
|
|
|
return $this; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param string $session_id |
|
|
|
|
|
|
65
|
|
|
* @return $this |
|
66
|
|
|
*/ |
|
67
|
2 |
|
public function session_id($session_id) |
|
|
|
|
|
|
68
|
|
|
{ |
|
69
|
2 |
|
$this->set('session_id', $session_id); |
|
70
|
|
|
|
|
71
|
2 |
|
return $this; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @return mixed|bool |
|
76
|
|
|
*/ |
|
77
|
63 |
|
public function getSessionId() |
|
78
|
|
|
{ |
|
79
|
63 |
|
if (empty($this->settings['session_id'])) { |
|
80
|
63 |
|
return false; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
2 |
|
return $this->get('session_id'); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @return string|bool |
|
88
|
|
|
*/ |
|
89
|
2 |
|
public function makeSessionId() |
|
90
|
|
|
{ |
|
91
|
2 |
|
$this->session_id(sha1(uniqid('', true))); |
|
|
|
|
|
|
92
|
|
|
|
|
93
|
2 |
|
return $this->getSessionId(); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @param mixed[] $forcedSettings |
|
98
|
|
|
* |
|
99
|
|
|
* @return mixed[] |
|
100
|
|
|
*/ |
|
101
|
63 |
|
public function getQueryableSettings(array $forcedSettings) : array |
|
102
|
|
|
{ |
|
103
|
63 |
|
$settings = $this->settings; |
|
104
|
63 |
|
if (! empty($forcedSettings)) { |
|
105
|
11 |
|
$settings = $forcedSettings + $this->settings; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
63 |
|
return $settings; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @param array $settings_array |
|
|
|
|
|
|
113
|
|
|
* @return $this |
|
114
|
|
|
*/ |
|
115
|
1 |
|
public function apply($settings_array) |
|
|
|
|
|
|
116
|
|
|
{ |
|
117
|
1 |
|
foreach ($settings_array as $key => $value) { |
|
118
|
1 |
|
$this->set($key, $value); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
1 |
|
return $this; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* @param string $name |
|
|
|
|
|
|
126
|
|
|
* @return mixed|null |
|
127
|
|
|
*/ |
|
128
|
1 |
|
public function getSetting($name) |
|
|
|
|
|
|
129
|
|
|
{ |
|
130
|
1 |
|
if (! isset($this->settings[$name])) { |
|
131
|
|
|
return null; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
1 |
|
return $this->get($name); |
|
135
|
|
|
} |
|
136
|
|
|
} |
|
137
|
|
|
|