1 | <?php |
||
13 | class LqlObject |
||
14 | { |
||
15 | /** |
||
16 | * Lql query |
||
17 | * @var array |
||
18 | */ |
||
19 | protected $queries; |
||
20 | |||
21 | /** |
||
22 | * Acquisition table |
||
23 | * @var string |
||
24 | */ |
||
25 | protected $table; |
||
26 | |||
27 | /** |
||
28 | * Header |
||
29 | * @var string |
||
30 | */ |
||
31 | protected $headers; |
||
32 | |||
33 | /** |
||
34 | * Acquisition column |
||
35 | * @var array |
||
36 | */ |
||
37 | protected $columns; |
||
38 | |||
39 | /** |
||
40 | * Output Format type |
||
41 | * @var string |
||
42 | */ |
||
43 | protected $outputFormat; |
||
44 | |||
45 | /** |
||
46 | * Authentication username |
||
47 | * @var string |
||
48 | */ |
||
49 | protected $authUser; |
||
50 | |||
51 | /** |
||
52 | * Acquisition number |
||
53 | * @var integer; |
||
54 | */ |
||
55 | protected $limit; |
||
56 | |||
57 | 57 | public function __construct() |
|
61 | |||
62 | 43 | public function setTable($table) |
|
63 | { |
||
64 | 43 | if (!is_string($table)) { |
|
65 | 1 | throw new InvalidArgumentException("Argument 1 must be a string."); |
|
66 | } |
||
67 | |||
68 | 42 | $this->table = trim($table); |
|
69 | 42 | } |
|
70 | |||
71 | 24 | public function setColumns($columns) |
|
72 | { |
||
73 | 24 | if (!is_array($columns)) { |
|
74 | 1 | throw new InvalidArgumentException("Argument 1 must be an array."); |
|
75 | } |
||
76 | 23 | $this->columns = $columns; |
|
77 | 23 | } |
|
78 | |||
79 | 2 | public function appendColumns($column) |
|
80 | { |
||
81 | 2 | if (!is_string($column)) { |
|
82 | 1 | throw new InvalidArgumentException("Argument 1 must be a string."); |
|
83 | } |
||
84 | 1 | $this->columns[] = trim($column); |
|
85 | 1 | } |
|
86 | |||
87 | 33 | public function appendArrayQuery(array $array) |
|
88 | { |
||
89 | 33 | $this->queries = array_merge($this->queries, $array); |
|
90 | 33 | } |
|
91 | |||
92 | 2 | public function appendStringQuery($name, $value) |
|
93 | { |
||
94 | 2 | if (!is_string($value)) { |
|
95 | 1 | throw new InvalidArgumentException("Argument 1 must be a string."); |
|
96 | } |
||
97 | 1 | $this->queries[] = sprintf("%s: %s\n", $name, trim($value)); |
|
98 | 1 | } |
|
99 | |||
100 | 2 | public function appendIntegerQuery($name, $value) |
|
101 | { |
||
102 | 2 | if (!is_int($value)) { |
|
103 | 1 | throw new InvalidArgumentException("Argument 1 must be an integer."); |
|
104 | } |
||
105 | 1 | $this->queries[] = sprintf("%s: %d\n", $name, $value); |
|
106 | 1 | } |
|
107 | |||
108 | 1 | public function appendNoValueQuery($name) |
|
109 | { |
||
110 | 1 | $this->queries[] = sprintf("%s:\n", $name); |
|
111 | 1 | } |
|
112 | |||
113 | 3 | public function appendParameter($parameter) |
|
114 | { |
||
115 | 3 | if (!is_string($parameter)) { |
|
116 | 1 | throw new InvalidArgumentException("Argument 1 must be a string."); |
|
117 | } |
||
118 | 2 | if (trim($parameter) !== "") { |
|
119 | 2 | $this->queries[] = $this->formatEnding($parameter); |
|
120 | 2 | } |
|
121 | 2 | } |
|
122 | |||
123 | 57 | public function setHeader($boolean) |
|
124 | { |
||
125 | 57 | if (!is_bool($boolean)) { |
|
126 | 1 | throw new InvalidArgumentException("Argument 1 must be a boolean."); |
|
127 | } |
||
128 | 57 | if ($boolean === true) { |
|
129 | 57 | $this->headers = "ColumnHeaders: on\n"; |
|
130 | 57 | } else { |
|
131 | 1 | $this->headers = "ColumnHeaders: off\n"; |
|
132 | } |
||
133 | 57 | } |
|
134 | |||
135 | 57 | public function setOutputFormat($outputFormat) |
|
136 | { |
||
137 | 57 | if (!is_string($outputFormat)) { |
|
138 | 1 | throw new InvalidArgumentException("Argument 1 must be a string."); |
|
139 | } |
||
140 | 57 | $this->outputFormat = sprintf("OutputFormat: %s\n", $outputFormat); |
|
141 | 57 | } |
|
142 | |||
143 | 2 | public function setLimit($limit) |
|
144 | { |
||
145 | 2 | if (!is_int($limit)) { |
|
146 | 1 | throw new InvalidArgumentException("Argument 1 must be an integer."); |
|
147 | } |
||
148 | 1 | $this->limit = sprintf("Limit: %d\n", $limit); |
|
149 | 1 | } |
|
150 | |||
151 | 3 | public function setAuthUser($authUser) |
|
152 | { |
||
153 | 3 | if (!is_string($authUser)) { |
|
154 | 1 | throw new InvalidArgumentException("Argument 1 must be a string."); |
|
155 | } |
||
156 | 2 | $this->authUser = sprintf("AuthUser: %s\n", trim($authUser)); |
|
157 | 2 | } |
|
158 | |||
159 | /** |
||
160 | * 初期化 |
||
161 | * |
||
162 | * @return \Kwkm\MkLiveStatusClient\Lql |
||
163 | */ |
||
164 | 57 | public function reset() |
|
175 | |||
176 | /** |
||
177 | * 終端の改行文字の付与 |
||
178 | * @param string $string 改行文字を付与する文字列 |
||
179 | * @return string 改行文字が付与された文字列 |
||
180 | */ |
||
181 | 2 | protected function formatEnding($string) |
|
182 | { |
||
183 | 2 | if ($string[strlen($string) - 1] !== "\n") { |
|
184 | 2 | $string .= "\n"; |
|
185 | 2 | } |
|
186 | |||
187 | 2 | return $string; |
|
188 | } |
||
189 | |||
190 | 40 | public function build() |
|
203 | |||
204 | 40 | private function getColumnsField() |
|
212 | |||
213 | 40 | private function getQueriesFiled() |
|
221 | |||
222 | 40 | private function getOutputFormatFiled() |
|
230 | } |
||
231 |