1
|
|
|
<?php |
2
|
|
|
namespace Kwkm\MkLiveStatusClient; |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* Class Filter |
6
|
|
|
* |
7
|
|
|
* @package Kwkm\MkLiveStatusClient |
8
|
|
|
* @author Takehiro Kawakami <[email protected]> |
9
|
|
|
* @license MIT |
10
|
|
|
*/ |
11
|
|
|
class Filter |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var array |
15
|
|
|
*/ |
16
|
|
|
private $filters; |
17
|
|
|
|
18
|
39 |
|
public function __construct() |
19
|
|
|
{ |
20
|
39 |
|
$this->reset(); |
21
|
39 |
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* 任意のフィルタ設定 |
25
|
|
|
* |
26
|
|
|
* @param string $filter |
27
|
|
|
* @return \Kwkm\MkLiveStatusClient\Filter |
28
|
|
|
* @throw \InvalidArgumentException if the provided argument is not of type 'string'. |
29
|
|
|
*/ |
30
|
30 |
|
public function set($filter) |
31
|
|
|
{ |
32
|
30 |
|
$this->filters[] = trim(sprintf("Filter: %s", trim($filter))) . "\n"; |
33
|
|
|
|
34
|
30 |
|
return $this; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* column = value のフィルタ設定 |
39
|
|
|
* |
40
|
|
|
* @param string $column カラム名 |
41
|
|
|
* @param string $value フィルタする値 |
42
|
|
|
* @return \Kwkm\MkLiveStatusClient\Filter |
43
|
|
|
*/ |
44
|
17 |
|
public function equal($column, $value) |
45
|
|
|
{ |
46
|
17 |
|
return $this->set( |
47
|
17 |
|
sprintf("%s = %s", $column, $value) |
48
|
17 |
|
); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* column ~ value のフィルタ設定 |
53
|
|
|
* |
54
|
|
|
* @param string $column カラム名 |
55
|
|
|
* @param string $value フィルタする値 |
56
|
|
|
* @return \Kwkm\MkLiveStatusClient\Filter |
57
|
|
|
*/ |
58
|
5 |
|
public function match($column, $value) |
59
|
|
|
{ |
60
|
5 |
|
return $this->set( |
61
|
5 |
|
sprintf("%s ~ %s", $column, $value) |
62
|
5 |
|
); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* column != value のフィルタ設定 |
67
|
|
|
* |
68
|
|
|
* @param string $column カラム名 |
69
|
|
|
* @param string $value フィルタする値 |
70
|
|
|
* @return \Kwkm\MkLiveStatusClient\Filter |
71
|
|
|
*/ |
72
|
3 |
|
public function notEqual($column, $value) |
73
|
|
|
{ |
74
|
3 |
|
return $this->set( |
75
|
3 |
|
sprintf("%s != %s", $column, $value) |
76
|
3 |
|
); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* column !~ value のフィルタ設定 |
81
|
|
|
* |
82
|
|
|
* @param string $column カラム名 |
83
|
|
|
* @param string $value フィルタする値 |
84
|
|
|
* @return \Kwkm\MkLiveStatusClient\Filter |
85
|
|
|
*/ |
86
|
1 |
|
public function notMatch($column, $value) |
87
|
|
|
{ |
88
|
1 |
|
return $this->set( |
89
|
1 |
|
sprintf("%s !~ %s", $column, $value) |
90
|
1 |
|
); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* column < value のフィルタ設定 |
95
|
|
|
* |
96
|
|
|
* @param string $column カラム名 |
97
|
|
|
* @param string $value フィルタする値 |
98
|
|
|
* @return \Kwkm\MkLiveStatusClient\Filter |
99
|
|
|
*/ |
100
|
1 |
|
public function less($column, $value) |
101
|
|
|
{ |
102
|
1 |
|
return $this->set( |
103
|
1 |
|
sprintf("%s < %s", $column, $value) |
104
|
1 |
|
); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* column > value のフィルタ設定 |
109
|
|
|
* |
110
|
|
|
* @param string $column カラム名 |
111
|
|
|
* @param string $value フィルタする値 |
112
|
|
|
* @return \Kwkm\MkLiveStatusClient\Filter |
113
|
|
|
*/ |
114
|
3 |
|
public function greater($column, $value) |
115
|
|
|
{ |
116
|
3 |
|
return $this->set( |
117
|
3 |
|
sprintf("%s > %s", $column, $value) |
118
|
3 |
|
); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* column <= value のフィルタ設定 |
123
|
|
|
* |
124
|
|
|
* @param string $column カラム名 |
125
|
|
|
* @param string $value フィルタする値 |
126
|
|
|
* @return \Kwkm\MkLiveStatusClient\Filter |
127
|
|
|
*/ |
128
|
1 |
|
public function lessEqual($column, $value) |
129
|
|
|
{ |
130
|
1 |
|
return $this->set( |
131
|
1 |
|
sprintf("%s <= %s", $column, $value) |
132
|
1 |
|
); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* column >= value のフィルタ設定 |
137
|
|
|
* |
138
|
|
|
* @param string $column カラム名 |
139
|
|
|
* @param string $value フィルタする値 |
140
|
|
|
* @return \Kwkm\MkLiveStatusClient\Filter |
141
|
|
|
*/ |
142
|
8 |
|
public function greaterEqual($column, $value) |
143
|
|
|
{ |
144
|
8 |
|
return $this->set( |
145
|
8 |
|
sprintf("%s >= %s", $column, $value) |
146
|
8 |
|
); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* Or の指定 |
151
|
|
|
* @param integer $or |
152
|
|
|
* @return \Kwkm\MkLiveStatusClient\Filter |
153
|
|
|
* @throw \InvalidArgumentException if the provided argument is not of type 'integer'. |
154
|
|
|
*/ |
155
|
9 |
|
public function operatorOr($or) |
156
|
|
|
{ |
157
|
9 |
|
$this->filters[] = sprintf("Or: %d\n", $or); |
158
|
|
|
|
159
|
9 |
|
return $this; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* And の指定 |
164
|
|
|
* @param integer $and |
165
|
|
|
* @return \Kwkm\MkLiveStatusClient\Filter |
166
|
|
|
* @throw \InvalidArgumentException if the provided argument is not of type 'integer'. |
167
|
|
|
*/ |
168
|
3 |
|
public function operatorAnd($and) |
169
|
|
|
{ |
170
|
3 |
|
$this->filters[] = sprintf("And: %d\n", $and); |
171
|
|
|
|
172
|
3 |
|
return $this; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* Negate の指定 |
177
|
|
|
* @return \Kwkm\MkLiveStatusClient\Filter |
178
|
|
|
*/ |
179
|
3 |
|
public function negate() |
180
|
|
|
{ |
181
|
3 |
|
$this->filters[] = "Negate:\n"; |
182
|
|
|
|
183
|
3 |
|
return $this; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* Reset filter |
188
|
|
|
* @return \Kwkm\MkLiveStatusClient\Filter |
189
|
|
|
*/ |
190
|
39 |
|
public function reset() |
191
|
|
|
{ |
192
|
39 |
|
$this->filters = array(); |
193
|
|
|
|
194
|
39 |
|
return $this; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* Get filter |
199
|
|
|
* @return array |
200
|
|
|
*/ |
201
|
30 |
|
public function get() |
202
|
|
|
{ |
203
|
30 |
|
return $this->filters; |
204
|
|
|
} |
205
|
|
|
} |
206
|
|
|
|