|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Kwkm\MkLiveStatusClient; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Class LqlBuilder |
|
7
|
|
|
* |
|
8
|
|
|
* @package Kwkm\MkLiveStatusClient |
|
9
|
|
|
* @author Takehiro Kawakami <[email protected]> |
|
10
|
|
|
* @license MIT |
|
11
|
|
|
* |
|
12
|
|
|
* @method \Kwkm\MkLiveStatusClient\LqlBuilder filterSet(String $filter) |
|
13
|
|
|
* @method \Kwkm\MkLiveStatusClient\LqlBuilder filterEqual(String $column, String $value) |
|
14
|
|
|
* @method \Kwkm\MkLiveStatusClient\LqlBuilder filterMatch(String $column, String $value) |
|
15
|
|
|
* @method \Kwkm\MkLiveStatusClient\LqlBuilder filterNotEqual(String $column, String $value) |
|
16
|
|
|
* @method \Kwkm\MkLiveStatusClient\LqlBuilder filterNotMatch(String $column, String $value) |
|
17
|
|
|
* @method \Kwkm\MkLiveStatusClient\LqlBuilder filterLess(String $column, String $value) |
|
18
|
|
|
* @method \Kwkm\MkLiveStatusClient\LqlBuilder filterGreater(String $column, String $value) |
|
19
|
|
|
* @method \Kwkm\MkLiveStatusClient\LqlBuilder filterLessEqual(String $column, String $value) |
|
20
|
|
|
* @method \Kwkm\MkLiveStatusClient\LqlBuilder filterGreaterEqual(String $column, String $value) |
|
21
|
|
|
* @method \Kwkm\MkLiveStatusClient\LqlBuilder filterOr(Integer $or) |
|
22
|
|
|
* @method \Kwkm\MkLiveStatusClient\LqlBuilder filterAnd(Integer $and) |
|
23
|
|
|
* @method \Kwkm\MkLiveStatusClient\LqlBuilder statsSet(String $stats) |
|
24
|
|
|
* @method \Kwkm\MkLiveStatusClient\LqlBuilder statsEqual(String $column, String $value) |
|
25
|
|
|
* @method \Kwkm\MkLiveStatusClient\LqlBuilder statsNotEqual(String $column, String $value) |
|
26
|
|
|
* @method \Kwkm\MkLiveStatusClient\LqlBuilder statsSum(String $column) |
|
27
|
|
|
* @method \Kwkm\MkLiveStatusClient\LqlBuilder statsMin(String $column) |
|
28
|
|
|
* @method \Kwkm\MkLiveStatusClient\LqlBuilder statsMax(String $column) |
|
29
|
|
|
* @method \Kwkm\MkLiveStatusClient\LqlBuilder statsAvg(String $column) |
|
30
|
|
|
* @method \Kwkm\MkLiveStatusClient\LqlBuilder statsStd(String $column) |
|
31
|
|
|
* @method \Kwkm\MkLiveStatusClient\LqlBuilder statsSuminv(String $column) |
|
32
|
|
|
* @method \Kwkm\MkLiveStatusClient\LqlBuilder statsAvginv(String $column) |
|
33
|
|
|
* @method \Kwkm\MkLiveStatusClient\LqlBuilder statsAnd(Integer $and) |
|
34
|
|
|
* @method \Kwkm\MkLiveStatusClient\LqlBuilder statsOr(Integer $or) |
|
35
|
|
|
*/ |
|
36
|
|
|
class LqlBuilder extends LqlAbstract |
|
37
|
|
|
{ |
|
38
|
|
|
/** |
|
39
|
|
|
* @var \Kwkm\MkLiveStatusClient\Lql |
|
40
|
|
|
*/ |
|
41
|
|
|
private $lql; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @var \Kwkm\MkLiveStatusClient\Column |
|
45
|
|
|
*/ |
|
46
|
|
|
private $column; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @var \Kwkm\MkLiveStatusClient\Filter |
|
50
|
|
|
*/ |
|
51
|
|
|
private $filter; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @var \Kwkm\MkLiveStatusClient\Stats |
|
55
|
|
|
*/ |
|
56
|
|
|
private $stats; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* 初期化 |
|
60
|
|
|
* |
|
61
|
|
|
* @return \Kwkm\MkLiveStatusClient\LqlBuilder |
|
62
|
|
|
*/ |
|
63
|
17 |
|
public function reset() |
|
64
|
|
|
{ |
|
65
|
17 |
|
$this->lql->reset(); |
|
66
|
17 |
|
$this->column = new Column(); |
|
67
|
17 |
|
$this->filter = new Filter(); |
|
68
|
17 |
|
$this->stats = new Stats(); |
|
69
|
|
|
|
|
70
|
17 |
|
return $this; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
14 |
|
public function __call($method, $arguments) |
|
74
|
|
|
{ |
|
75
|
14 |
|
if (substr($method, 0, 5) === 'stats') { |
|
76
|
3 |
|
$this->callStats($method, $arguments); |
|
77
|
|
|
|
|
78
|
3 |
|
return $this; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
13 |
|
if (substr($method, 0, 6) === 'filter') { |
|
82
|
13 |
|
$this->callFilter($method, $arguments); |
|
83
|
13 |
|
return $this; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
trigger_error('Call to undefined method ' . get_class($this) . '::' . $method, E_USER_ERROR); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
3 |
View Code Duplication |
private function callStats($method, $arguments) |
|
|
|
|
|
|
90
|
|
|
{ |
|
91
|
3 |
|
$callMethod = lcfirst(substr($method, 5)); |
|
92
|
|
|
|
|
93
|
3 |
|
if (($callMethod === 'or') || ($callMethod === 'and')) { |
|
94
|
1 |
|
$callMethod = 'operator' . ucfirst($callMethod); |
|
95
|
1 |
|
} |
|
96
|
|
|
|
|
97
|
3 |
|
call_user_func_array(array($this->stats, $callMethod), $arguments); |
|
98
|
|
|
|
|
99
|
3 |
|
$this->lql->stats($this->stats); |
|
100
|
3 |
|
$this->stats->reset(); |
|
101
|
3 |
|
} |
|
102
|
|
|
|
|
103
|
13 |
View Code Duplication |
private function callFilter($method, $arguments) |
|
|
|
|
|
|
104
|
|
|
{ |
|
105
|
13 |
|
$callMethod = lcfirst(substr($method, 6)); |
|
106
|
|
|
|
|
107
|
13 |
|
if (($callMethod === 'or') || ($callMethod === 'and')) { |
|
108
|
4 |
|
$callMethod = 'operator' . ucfirst($callMethod); |
|
109
|
4 |
|
} |
|
110
|
|
|
|
|
111
|
13 |
|
call_user_func_array(array($this->filter, $callMethod), $arguments); |
|
112
|
|
|
|
|
113
|
13 |
|
$this->lql->filter($this->filter); |
|
114
|
13 |
|
$this->filter->reset(); |
|
115
|
13 |
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* 取得カラムの指定 |
|
119
|
|
|
* |
|
120
|
|
|
* @param string $column |
|
121
|
|
|
* @return \Kwkm\MkLiveStatusClient\LqlBuilder |
|
122
|
|
|
* @throw \InvalidArgumentException if the provided argument is not of type 'string'. |
|
123
|
|
|
*/ |
|
124
|
2 |
|
public function column($column) |
|
125
|
|
|
{ |
|
126
|
2 |
|
$this->column->add($column); |
|
127
|
2 |
|
$this->lql->column($this->column); |
|
128
|
|
|
|
|
129
|
2 |
|
return $this; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* ヘッダ情報を取得するかの設定 |
|
134
|
|
|
* |
|
135
|
|
|
* @param boolean $boolean |
|
136
|
|
|
* @return \Kwkm\MkLiveStatusClient\LqlBuilder |
|
137
|
|
|
* @throw \InvalidArgumentException if the provided argument is not of type 'boolean'. |
|
138
|
|
|
*/ |
|
139
|
|
|
public function headers($boolean) |
|
140
|
|
|
{ |
|
141
|
|
|
$this->lql->headers($boolean); |
|
142
|
|
|
|
|
143
|
|
|
return $this; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* 取得カラムの一括指定 |
|
148
|
|
|
* |
|
149
|
|
|
* @param array $columns |
|
150
|
|
|
* @return \Kwkm\MkLiveStatusClient\LqlBuilder |
|
151
|
|
|
* @throw \InvalidArgumentException if the provided argument is not of type 'array'. |
|
152
|
|
|
*/ |
|
153
|
7 |
|
public function columns($columns) |
|
154
|
|
|
{ |
|
155
|
7 |
|
$this->column = new Column($columns); |
|
156
|
7 |
|
$this->lql->column($this->column); |
|
157
|
|
|
|
|
158
|
7 |
|
return $this; |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
/** |
|
162
|
|
|
* StatsNegate の指定 |
|
163
|
|
|
* @return \Kwkm\MkLiveStatusClient\LqlBuilder |
|
164
|
|
|
*/ |
|
165
|
|
|
public function statsNegate() |
|
166
|
|
|
{ |
|
167
|
|
|
$this->lql->statsNegate(); |
|
168
|
|
|
|
|
169
|
|
|
return $this; |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* Negate の指定 |
|
174
|
|
|
* @return \Kwkm\MkLiveStatusClient\LqlBuilder |
|
175
|
|
|
*/ |
|
176
|
1 |
|
public function negate() |
|
177
|
|
|
{ |
|
178
|
1 |
|
$this->lql->negate(); |
|
179
|
|
|
|
|
180
|
1 |
|
return $this; |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* パラメータの指定 |
|
185
|
|
|
* @param string $parameter |
|
186
|
|
|
* @return \Kwkm\MkLiveStatusClient\LqlBuilder |
|
187
|
|
|
* @throw \InvalidArgumentException if the provided argument is not of type 'string'. |
|
188
|
|
|
*/ |
|
189
|
|
|
public function parameter($parameter) |
|
190
|
|
|
{ |
|
191
|
|
|
$this->lql->parameter($parameter); |
|
192
|
|
|
|
|
193
|
|
|
return $this; |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
/** |
|
197
|
|
|
* OutputFormat の指定 |
|
198
|
|
|
* @param string $outputFormat |
|
199
|
|
|
* @return \Kwkm\MkLiveStatusClient\LqlBuilder |
|
200
|
|
|
* @throw \InvalidArgumentException if the provided argument is not of type 'string'. |
|
201
|
|
|
*/ |
|
202
|
|
|
public function outputFormat($outputFormat) |
|
203
|
|
|
{ |
|
204
|
|
|
$this->lql->outputFormat($outputFormat); |
|
205
|
|
|
|
|
206
|
|
|
return $this; |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
/** |
|
210
|
|
|
* Limit の指定 |
|
211
|
|
|
* @param integer $limit |
|
212
|
|
|
* @return \Kwkm\MkLiveStatusClient\LqlBuilder |
|
213
|
|
|
* @throw \InvalidArgumentException if the provided argument is not of type 'integer'. |
|
214
|
|
|
*/ |
|
215
|
|
|
public function limit($limit) |
|
216
|
|
|
{ |
|
217
|
|
|
$this->lql->limit($limit); |
|
218
|
|
|
|
|
219
|
|
|
return $this; |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
|
|
/** |
|
223
|
|
|
* Lqlの実行テキストの作成 |
|
224
|
|
|
* @return string |
|
225
|
|
|
*/ |
|
226
|
17 |
|
public function build() |
|
227
|
|
|
{ |
|
228
|
17 |
|
return $this->lql->build(); |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
|
|
/** |
|
232
|
|
|
* コンストラクタ |
|
233
|
|
|
*/ |
|
234
|
17 |
|
public function __construct($table, $authUser = null) |
|
235
|
|
|
{ |
|
236
|
17 |
|
$this->lql = new Lql($table, $authUser); |
|
237
|
17 |
|
$this->reset(); |
|
238
|
17 |
|
} |
|
239
|
|
|
} |
|
240
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.