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 filterNegate() |
24
|
|
|
* @method \Kwkm\MkLiveStatusClient\LqlBuilder statsSet(String $stats) |
25
|
|
|
* @method \Kwkm\MkLiveStatusClient\LqlBuilder statsEqual(String $column, String $value) |
26
|
|
|
* @method \Kwkm\MkLiveStatusClient\LqlBuilder statsNotEqual(String $column, String $value) |
27
|
|
|
* @method \Kwkm\MkLiveStatusClient\LqlBuilder statsSum(String $column) |
28
|
|
|
* @method \Kwkm\MkLiveStatusClient\LqlBuilder statsMin(String $column) |
29
|
|
|
* @method \Kwkm\MkLiveStatusClient\LqlBuilder statsMax(String $column) |
30
|
|
|
* @method \Kwkm\MkLiveStatusClient\LqlBuilder statsAvg(String $column) |
31
|
|
|
* @method \Kwkm\MkLiveStatusClient\LqlBuilder statsStd(String $column) |
32
|
|
|
* @method \Kwkm\MkLiveStatusClient\LqlBuilder statsSuminv(String $column) |
33
|
|
|
* @method \Kwkm\MkLiveStatusClient\LqlBuilder statsAvginv(String $column) |
34
|
|
|
* @method \Kwkm\MkLiveStatusClient\LqlBuilder statsAnd(Integer $and) |
35
|
|
|
* @method \Kwkm\MkLiveStatusClient\LqlBuilder statsOr(Integer $or) |
36
|
|
|
* @method \Kwkm\MkLiveStatusClient\LqlBuilder statsNegate() |
37
|
|
|
*/ |
38
|
|
|
class LqlBuilder extends LqlAbstract |
39
|
|
|
{ |
40
|
|
|
/** |
41
|
|
|
* @var \Kwkm\MkLiveStatusClient\Lql |
42
|
|
|
*/ |
43
|
|
|
private $lql; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var \Kwkm\MkLiveStatusClient\Column |
47
|
|
|
*/ |
48
|
|
|
private $column; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var \Kwkm\MkLiveStatusClient\Filter |
52
|
|
|
*/ |
53
|
|
|
private $filter; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var \Kwkm\MkLiveStatusClient\Stats |
57
|
|
|
*/ |
58
|
|
|
private $stats; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* 初期化 |
62
|
|
|
* |
63
|
|
|
* @return \Kwkm\MkLiveStatusClient\LqlBuilder |
64
|
|
|
*/ |
65
|
25 |
|
public function reset() |
66
|
|
|
{ |
67
|
25 |
|
$this->lql->reset(); |
68
|
25 |
|
$this->column = new Column(); |
69
|
25 |
|
$this->filter = new Filter(); |
70
|
25 |
|
$this->stats = new Stats(); |
71
|
|
|
|
72
|
25 |
|
return $this; |
73
|
|
|
} |
74
|
|
|
|
75
|
21 |
|
public function __call($method, $arguments) |
76
|
|
|
{ |
77
|
21 |
|
if (substr($method, 0, 5) === 'stats') { |
78
|
8 |
|
$this->callPropertyMethod(5, $method, $arguments); |
79
|
|
|
|
80
|
8 |
|
return $this; |
81
|
|
|
} |
82
|
|
|
|
83
|
18 |
|
if (substr($method, 0, 6) === 'filter') { |
84
|
17 |
|
$this->callPropertyMethod(6, $method, $arguments); |
85
|
16 |
|
return $this; |
86
|
|
|
} |
87
|
|
|
|
88
|
1 |
|
throw new \BadMethodCallException('Call to undefined method ' . get_class($this) . '::' . $method); |
89
|
|
|
} |
90
|
|
|
|
91
|
20 |
|
private function callPropertyMethod($lengthProperty, $method, $arguments) |
92
|
|
|
{ |
93
|
20 |
|
$property = substr($method, 0, $lengthProperty); |
94
|
20 |
|
$callMethod = lcfirst(substr($method, $lengthProperty)); |
95
|
|
|
|
96
|
20 |
|
if (($callMethod === 'or') || ($callMethod === 'and')) { |
97
|
5 |
|
$callMethod = 'operator' . ucfirst($callMethod); |
98
|
5 |
|
} |
99
|
|
|
|
100
|
20 |
|
if (false === method_exists($this->$property, $callMethod)) { |
101
|
1 |
|
throw new \BadMethodCallException('Call to undefined method ' . get_class($this) . '::' . $method); |
102
|
|
|
} |
103
|
|
|
|
104
|
19 |
|
call_user_func_array(array($this->$property, $callMethod), $arguments); |
105
|
19 |
|
$this->lql->$property($this->$property); |
106
|
19 |
|
$this->$property->reset(); |
107
|
19 |
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* 取得カラムの指定 |
111
|
|
|
* |
112
|
|
|
* @param string $column |
113
|
|
|
* @return \Kwkm\MkLiveStatusClient\LqlBuilder |
114
|
|
|
* @throw \InvalidArgumentException if the provided argument is not of type 'string'. |
115
|
|
|
*/ |
116
|
7 |
|
public function column($column) |
117
|
|
|
{ |
118
|
7 |
|
$this->column->add($column); |
119
|
7 |
|
$this->lql->column($this->column); |
120
|
|
|
|
121
|
7 |
|
return $this; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* ヘッダ情報を取得するかの設定 |
126
|
|
|
* |
127
|
|
|
* @param boolean $boolean |
128
|
|
|
* @return \Kwkm\MkLiveStatusClient\LqlBuilder |
129
|
|
|
* @throw \InvalidArgumentException if the provided argument is not of type 'boolean'. |
130
|
|
|
*/ |
131
|
1 |
|
public function headers($boolean) |
132
|
|
|
{ |
133
|
1 |
|
$this->lql->headers($boolean); |
134
|
|
|
|
135
|
1 |
|
return $this; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* 取得カラムの一括指定 |
140
|
|
|
* |
141
|
|
|
* @param array $columns |
142
|
|
|
* @return \Kwkm\MkLiveStatusClient\LqlBuilder |
143
|
|
|
* @throw \InvalidArgumentException if the provided argument is not of type 'array'. |
144
|
|
|
*/ |
145
|
7 |
|
public function columns($columns) |
146
|
|
|
{ |
147
|
7 |
|
$this->column = new Column($columns); |
148
|
7 |
|
$this->lql->column($this->column); |
149
|
|
|
|
150
|
7 |
|
return $this; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* パラメータの指定 |
155
|
|
|
* @param string $parameter |
156
|
|
|
* @return \Kwkm\MkLiveStatusClient\LqlBuilder |
157
|
|
|
* @throw \InvalidArgumentException if the provided argument is not of type 'string'. |
158
|
|
|
*/ |
159
|
1 |
|
public function parameter($parameter) |
160
|
|
|
{ |
161
|
1 |
|
$this->lql->parameter($parameter); |
162
|
|
|
|
163
|
1 |
|
return $this; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* OutputFormat の指定 |
168
|
|
|
* @param string $outputFormat |
169
|
|
|
* @return \Kwkm\MkLiveStatusClient\LqlBuilder |
170
|
|
|
* @throw \InvalidArgumentException if the provided argument is not of type 'string'. |
171
|
|
|
*/ |
172
|
1 |
|
public function outputFormat($outputFormat) |
173
|
|
|
{ |
174
|
1 |
|
$this->lql->outputFormat($outputFormat); |
175
|
|
|
|
176
|
1 |
|
return $this; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* Limit の指定 |
181
|
|
|
* @param integer $limit |
182
|
|
|
* @return \Kwkm\MkLiveStatusClient\LqlBuilder |
183
|
|
|
* @throw \InvalidArgumentException if the provided argument is not of type 'integer'. |
184
|
|
|
*/ |
185
|
1 |
|
public function limit($limit) |
186
|
|
|
{ |
187
|
1 |
|
$this->lql->limit($limit); |
188
|
|
|
|
189
|
1 |
|
return $this; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* Lqlの実行テキストの作成 |
194
|
|
|
* @return string |
195
|
|
|
*/ |
196
|
23 |
|
public function build() |
197
|
|
|
{ |
198
|
23 |
|
return $this->lql->build(); |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* コンストラクタ |
203
|
|
|
*/ |
204
|
25 |
|
public function __construct($table, $authUser = null) |
205
|
|
|
{ |
206
|
25 |
|
$this->lql = new Lql($table, $authUser); |
207
|
25 |
|
$this->reset(); |
208
|
25 |
|
} |
209
|
|
|
} |
210
|
|
|
|