1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the jquery-datatables-bundle package. |
5
|
|
|
* |
6
|
|
|
* (c) 2018 WEBEWEB |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace WBW\Bundle\JQuery\DatatablesBundle\API\Wrapper; |
13
|
|
|
|
14
|
|
|
use WBW\Bundle\JQuery\DatatablesBundle\API\Column\DataTablesColumn; |
15
|
|
|
use WBW\Bundle\JQuery\DatatablesBundle\API\Mapping\DataTablesMapping; |
16
|
|
|
use WBW\Bundle\JQuery\DatatablesBundle\API\Request\DataTablesRequest; |
17
|
|
|
use WBW\Bundle\JQuery\DatatablesBundle\API\Response\DataTablesResponse; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* DataTables wrapper. |
21
|
|
|
* |
22
|
|
|
* @author webeweb <https://github.com/webeweb/> |
23
|
|
|
* @package WBW\Bundle\JQuery\DatatablesBundle\API\Wrapper |
24
|
|
|
* @final |
25
|
|
|
*/ |
26
|
|
|
final class DataTablesWrapper { |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Columns. |
30
|
|
|
* |
31
|
|
|
* @var DataTablesColumn[] |
32
|
|
|
*/ |
33
|
|
|
private $columns; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Mapping. |
37
|
|
|
* |
38
|
|
|
* @var DataTablesMapping |
39
|
|
|
*/ |
40
|
|
|
private $mapping; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Method. |
44
|
|
|
* |
45
|
|
|
* @var string |
46
|
|
|
*/ |
47
|
|
|
private $method; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Order. |
51
|
|
|
* |
52
|
|
|
* @var array |
53
|
|
|
*/ |
54
|
|
|
private $order; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Processing. |
58
|
|
|
* |
59
|
|
|
* @var boolean |
60
|
|
|
*/ |
61
|
|
|
private $processing; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Request. |
65
|
|
|
* |
66
|
|
|
* @var DataTablesRequest |
67
|
|
|
*/ |
68
|
|
|
private $request; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Response. |
72
|
|
|
* |
73
|
|
|
* @var DataTablesResponse |
74
|
|
|
*/ |
75
|
|
|
private $response; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Route. |
79
|
|
|
* |
80
|
|
|
* @var string |
81
|
|
|
*/ |
82
|
|
|
private $route; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Server side. |
86
|
|
|
* |
87
|
|
|
* @var boolean |
88
|
|
|
*/ |
89
|
|
|
private $serverSide; |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Constructor. |
93
|
|
|
* |
94
|
|
|
* @param string $method The method. |
95
|
|
|
* @param string $route The route. |
96
|
|
|
* @param string $prefix The prefix. |
97
|
|
|
*/ |
98
|
|
|
public function __construct($method, $route, $prefix) { |
99
|
|
|
$this->mapping = new DataTablesMapping(); |
100
|
|
|
$this->mapping->setPrefix($prefix); |
101
|
|
|
|
102
|
|
|
$this->setColumns([]); |
103
|
|
|
$this->setMethod($method); |
104
|
|
|
$this->setOrder([]); |
105
|
|
|
$this->setProcessing(true); |
106
|
|
|
$this->setRoute($route); |
107
|
|
|
$this->setServerSide(true); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Get the columns. |
112
|
|
|
* |
113
|
|
|
* @return DataTablesColumn[] Returns the columns. |
114
|
|
|
*/ |
115
|
|
|
public function getColumns() { |
116
|
|
|
return $this->columns; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Get the mapping. |
121
|
|
|
* |
122
|
|
|
* @return DataTablesMapping The mapping. |
123
|
|
|
*/ |
124
|
|
|
public function getMapping() { |
125
|
|
|
return $this->mapping; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Get the method. |
130
|
|
|
* |
131
|
|
|
* @return string Returns the method. |
132
|
|
|
*/ |
133
|
|
|
public function getMethod() { |
134
|
|
|
return $this->method; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Get the order. |
139
|
|
|
* |
140
|
|
|
* @return array Returns the order. |
141
|
|
|
*/ |
142
|
|
|
public function getOrder() { |
143
|
|
|
return $this->order; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Get the processing. |
148
|
|
|
* |
149
|
|
|
* @return boolean Returns the processing. |
150
|
|
|
*/ |
151
|
|
|
public function getProcessing() { |
152
|
|
|
return $this->processing; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* Get the request. |
157
|
|
|
* |
158
|
|
|
* @return DataTablesRequest The request. |
159
|
|
|
*/ |
160
|
|
|
public function getRequest() { |
161
|
|
|
return $this->request; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* Get the response. |
166
|
|
|
* |
167
|
|
|
* @return DataTablesResponse Returns the response. |
168
|
|
|
*/ |
169
|
|
|
public function getResponse() { |
170
|
|
|
return $this->response; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* Get the route. |
175
|
|
|
* |
176
|
|
|
* @return string Returns the reoute. |
177
|
|
|
*/ |
178
|
|
|
public function getRoute() { |
179
|
|
|
return $this->route; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* Get the server side. |
184
|
|
|
* |
185
|
|
|
* @return boolean Returns the server side. |
186
|
|
|
*/ |
187
|
|
|
public function getServerSide() { |
188
|
|
|
return $this->serverSide; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* Set the columns. |
193
|
|
|
* |
194
|
|
|
* @param DataTablesColumn[] $columns The columns. |
195
|
|
|
* @return DataTablesWrapper Returns the DataTables wrapper. |
196
|
|
|
*/ |
197
|
|
|
private function setColumns(array $columns) { |
198
|
|
|
$this->columns = $columns; |
199
|
|
|
return $this; |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* Set the method. |
204
|
|
|
* |
205
|
|
|
* @param string $method The method. |
206
|
|
|
* @return DataTablesWrapper Returns the DataTables wrapper. |
207
|
|
|
*/ |
208
|
|
|
private function setMethod($method) { |
209
|
|
|
switch ($method) { |
210
|
|
|
case "GET": |
211
|
|
|
case "POST": |
212
|
|
|
$this->method = $method; |
213
|
|
|
break; |
214
|
|
|
default: |
215
|
|
|
$this->method = "GET"; |
216
|
|
|
} |
217
|
|
|
return $this; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* Set the order. |
222
|
|
|
* |
223
|
|
|
* @param array $order The order. |
224
|
|
|
* @return DataTablesWrapper Returns the DataTables wrapper. |
225
|
|
|
*/ |
226
|
|
|
public function setOrder(array $order) { |
227
|
|
|
$this->order = $order; |
228
|
|
|
return $this; |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* Set the processing. |
233
|
|
|
* |
234
|
|
|
* @param boolean $processing The processing. |
235
|
|
|
* @return DataTablesWrapper Returns the DataTables wrapper. |
236
|
|
|
*/ |
237
|
|
|
public function setProcessing($processing) { |
238
|
|
|
switch ($processing) { |
239
|
|
|
case false : |
|
|
|
|
240
|
|
|
case true : |
|
|
|
|
241
|
|
|
$this->processing = $processing; |
242
|
|
|
break; |
243
|
|
|
default: |
244
|
|
|
$this->processing = true; |
245
|
|
|
break; |
246
|
|
|
} |
247
|
|
|
return $this; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* Set the route. |
252
|
|
|
* |
253
|
|
|
* @param string $route The route. |
254
|
|
|
* @return DataTablesWrapper Returns the DataTables wrapper. |
255
|
|
|
*/ |
256
|
|
|
private function setRoute($route) { |
257
|
|
|
$this->route = $route; |
258
|
|
|
return $this; |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
/** |
262
|
|
|
* Set the server side. |
263
|
|
|
* |
264
|
|
|
* @param boolean $serverSide The server side. |
265
|
|
|
* @return DataTablesWrapper Returns the DataTables wrapper. |
266
|
|
|
*/ |
267
|
|
|
public function setServerSide($serverSide) { |
268
|
|
|
switch ($serverSide) { |
269
|
|
|
case false : |
|
|
|
|
270
|
|
|
case true : |
|
|
|
|
271
|
|
|
$this->serverSide = $serverSide; |
272
|
|
|
break; |
273
|
|
|
default: |
274
|
|
|
$this->serverSide = true; |
275
|
|
|
break; |
276
|
|
|
} |
277
|
|
|
return $this; |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
} |
281
|
|
|
|
As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.