|
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; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\HttpFoundation\ParameterBag; |
|
15
|
|
|
use WBW\Library\Core\Network\HTTP\HTTPInterface; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* DataTables request. |
|
19
|
|
|
* |
|
20
|
|
|
* @author webeweb <https://github.com/webeweb/> |
|
21
|
|
|
* @package WBW\Bundle\JQuery\DataTablesBundle\API |
|
22
|
|
|
*/ |
|
23
|
|
|
class DataTablesRequest implements DataTablesRequestInterface, HTTPInterface { |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Columns. |
|
27
|
|
|
* |
|
28
|
|
|
* @var DataTablesColumn[] |
|
29
|
|
|
*/ |
|
30
|
|
|
private $columns; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Draw. |
|
34
|
|
|
* |
|
35
|
|
|
* @var int |
|
36
|
|
|
*/ |
|
37
|
|
|
private $draw; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Length. |
|
41
|
|
|
* |
|
42
|
|
|
* @var int |
|
43
|
|
|
*/ |
|
44
|
|
|
private $length; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Order. |
|
48
|
|
|
* |
|
49
|
|
|
* @var DataTablesOrderInterface[] |
|
50
|
|
|
*/ |
|
51
|
|
|
private $order; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Query. |
|
55
|
|
|
* |
|
56
|
|
|
* @var ParameterBag |
|
57
|
|
|
*/ |
|
58
|
|
|
private $query; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Request. |
|
62
|
|
|
* |
|
63
|
|
|
* @var ParameterBag |
|
64
|
|
|
*/ |
|
65
|
|
|
private $request; |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Search. |
|
69
|
|
|
* |
|
70
|
|
|
* @var DataTablesSearchInterface |
|
71
|
|
|
*/ |
|
72
|
|
|
private $search; |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Start. |
|
76
|
|
|
* |
|
77
|
|
|
* @var int |
|
78
|
|
|
*/ |
|
79
|
|
|
private $start; |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Wrapper. |
|
83
|
|
|
* |
|
84
|
|
|
* @var DataTablesWrapper |
|
85
|
|
|
*/ |
|
86
|
|
|
private $wrapper; |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Constructor. |
|
90
|
|
|
*/ |
|
91
|
|
|
public function __construct() { |
|
92
|
|
|
$this->setColumns([]); |
|
93
|
|
|
$this->setDraw(0); |
|
94
|
|
|
$this->setLength(10); |
|
95
|
|
|
$this->setOrder([]); |
|
96
|
|
|
$this->setQuery(new ParameterBag()); |
|
97
|
|
|
$this->setRequest(new ParameterBag()); |
|
98
|
|
|
$this->setStart(0); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* {@inheritdoc} |
|
103
|
|
|
*/ |
|
104
|
|
|
public function getColumn($data) { |
|
105
|
|
|
foreach ($this->columns as $current) { |
|
106
|
|
|
if ($data === $current->getData()) { |
|
107
|
|
|
return $current; |
|
|
|
|
|
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
return null; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* {@inheritdoc} |
|
115
|
|
|
*/ |
|
116
|
|
|
public function getColumns() { |
|
117
|
|
|
return $this->columns; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* {@inheritdoc} |
|
122
|
|
|
*/ |
|
123
|
|
|
public function getDraw() { |
|
124
|
|
|
return $this->draw; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* {@inheritdoc} |
|
129
|
|
|
*/ |
|
130
|
|
|
public function getLength() { |
|
131
|
|
|
return $this->length; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* {@inheritdoc} |
|
136
|
|
|
*/ |
|
137
|
|
|
public function getOrder() { |
|
138
|
|
|
return $this->order; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* {@inheritdoc} |
|
143
|
|
|
*/ |
|
144
|
|
|
public function getQuery() { |
|
145
|
|
|
return $this->query; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* {@inheritdoc} |
|
150
|
|
|
*/ |
|
151
|
|
|
public function getRequest() { |
|
152
|
|
|
return $this->request; |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* {@inheritdoc} |
|
157
|
|
|
*/ |
|
158
|
|
|
public function getSearch() { |
|
159
|
|
|
return $this->search; |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* {@inheritdoc} |
|
164
|
|
|
*/ |
|
165
|
|
|
public function getStart() { |
|
166
|
|
|
return $this->start; |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* {@inheritdoc} |
|
171
|
|
|
*/ |
|
172
|
|
|
public function getWrapper() { |
|
173
|
|
|
return $this->wrapper; |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* Set the columns. |
|
178
|
|
|
* |
|
179
|
|
|
* @param DataTablesColumn[] $columns The columns. |
|
180
|
|
|
* @return DataTablesRequestInterface Returns this request. |
|
181
|
|
|
*/ |
|
182
|
|
|
public function setColumns(array $columns) { |
|
183
|
|
|
$this->columns = $columns; |
|
184
|
|
|
return $this; |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* Set the draw. |
|
189
|
|
|
* |
|
190
|
|
|
* @param int $draw The draw. |
|
191
|
|
|
* @return DataTablesRequestInterface Returns this request. |
|
192
|
|
|
*/ |
|
193
|
|
|
public function setDraw($draw) { |
|
194
|
|
|
$this->draw = $draw; |
|
195
|
|
|
return $this; |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
/** |
|
199
|
|
|
* Set the length. |
|
200
|
|
|
* |
|
201
|
|
|
* @param int $length The length. |
|
202
|
|
|
* @return DataTablesRequestInterface Returns this request. |
|
203
|
|
|
*/ |
|
204
|
|
|
public function setLength($length) { |
|
205
|
|
|
$this->length = $length; |
|
206
|
|
|
return $this; |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
/** |
|
210
|
|
|
* Set the order. |
|
211
|
|
|
* |
|
212
|
|
|
* @param DataTablesOrderInterface[] $order The order. |
|
213
|
|
|
* @return DataTablesRequestInterface Returns this request. |
|
214
|
|
|
*/ |
|
215
|
|
|
public function setOrder(array $order) { |
|
216
|
|
|
$this->order = $order; |
|
217
|
|
|
return $this; |
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
|
|
/** |
|
221
|
|
|
* Set the request. |
|
222
|
|
|
* |
|
223
|
|
|
* @param ParameterBag $query The query. |
|
224
|
|
|
* @return DataTablesRequestInterface Returns this request. |
|
225
|
|
|
*/ |
|
226
|
|
|
protected function setQuery(ParameterBag $query) { |
|
227
|
|
|
$this->query = $query; |
|
228
|
|
|
return $this; |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
|
|
/** |
|
232
|
|
|
* Set the request. |
|
233
|
|
|
* |
|
234
|
|
|
* @param ParameterBag $request The request. |
|
235
|
|
|
* @return DataTablesRequestInterface Returns this request. |
|
236
|
|
|
*/ |
|
237
|
|
|
protected function setRequest(ParameterBag $request) { |
|
238
|
|
|
$this->request = $request; |
|
239
|
|
|
return $this; |
|
240
|
|
|
} |
|
241
|
|
|
|
|
242
|
|
|
/** |
|
243
|
|
|
* Set the search. |
|
244
|
|
|
* |
|
245
|
|
|
* @param DataTablesSearchInterface $search The search. |
|
246
|
|
|
* @return DataTablesRequestInterface Returns this request. |
|
247
|
|
|
*/ |
|
248
|
|
|
public function setSearch(DataTablesSearchInterface $search) { |
|
249
|
|
|
$this->search = $search; |
|
250
|
|
|
return $this; |
|
251
|
|
|
} |
|
252
|
|
|
|
|
253
|
|
|
/** |
|
254
|
|
|
* Set the start. |
|
255
|
|
|
* |
|
256
|
|
|
* @param int $start The start. |
|
257
|
|
|
* @return DataTablesRequestInterface Returns this request. |
|
258
|
|
|
*/ |
|
259
|
|
|
public function setStart($start) { |
|
260
|
|
|
$this->start = $start; |
|
261
|
|
|
return $this; |
|
262
|
|
|
} |
|
263
|
|
|
|
|
264
|
|
|
/** |
|
265
|
|
|
* Set the wrapper. |
|
266
|
|
|
* |
|
267
|
|
|
* @param DataTablesWrapper $wrapper The wrapper. |
|
268
|
|
|
* @return DataTablesRequestInterface Returns this request. |
|
269
|
|
|
*/ |
|
270
|
|
|
public function setWrapper(DataTablesWrapper $wrapper) { |
|
271
|
|
|
$this->wrapper = $wrapper; |
|
272
|
|
|
return $this; |
|
273
|
|
|
} |
|
274
|
|
|
|
|
275
|
|
|
} |
|
276
|
|
|
|
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_functionexpects aPostobject, and outputs the author of the post. The base classPostreturns a simple string and outputting a simple string will work just fine. However, the child classBlogPostwhich is a sub-type ofPostinstead decided to return anobject, and is therefore violating the SOLID principles. If aBlogPostwere passed tomy_function, PHP would not complain, but ultimately fail when executing thestrtouppercall in its body.