1 | <?php |
||
25 | class DataTablesRequest implements DataTablesRequestInterface, HTTPInterface { |
||
26 | |||
27 | /** |
||
28 | * Columns. |
||
29 | * |
||
30 | * @var DataTablesColumn[] |
||
31 | */ |
||
32 | private $columns; |
||
33 | |||
34 | /** |
||
35 | * Draw. |
||
36 | * |
||
37 | * @var int |
||
38 | */ |
||
39 | private $draw; |
||
40 | |||
41 | /** |
||
42 | * Length. |
||
43 | * |
||
44 | * @var int |
||
45 | */ |
||
46 | private $length; |
||
47 | |||
48 | /** |
||
49 | * Order. |
||
50 | * |
||
51 | * @var DataTablesOrderInterface[] |
||
52 | */ |
||
53 | private $order; |
||
54 | |||
55 | /** |
||
56 | * Query. |
||
57 | * |
||
58 | * @var ParameterBag |
||
59 | */ |
||
60 | private $query; |
||
61 | |||
62 | /** |
||
63 | * Request. |
||
64 | * |
||
65 | * @var ParameterBag |
||
66 | */ |
||
67 | private $request; |
||
68 | |||
69 | /** |
||
70 | * Search. |
||
71 | * |
||
72 | * @var DataTablesSearchInterface |
||
73 | */ |
||
74 | private $search; |
||
75 | |||
76 | /** |
||
77 | * Start. |
||
78 | * |
||
79 | * @var int |
||
80 | */ |
||
81 | private $start; |
||
82 | |||
83 | /** |
||
84 | * Wrapper. |
||
85 | * |
||
86 | * @var DataTablesWrapper |
||
87 | */ |
||
88 | private $wrapper; |
||
89 | |||
90 | /** |
||
91 | * Constructor. |
||
92 | */ |
||
93 | protected function __construct() { |
||
102 | |||
103 | /** |
||
104 | * {@inheritdoc} |
||
105 | */ |
||
106 | public function getColumn($data) { |
||
114 | |||
115 | /** |
||
116 | * {@inheritdoc} |
||
117 | */ |
||
118 | public function getColumns() { |
||
121 | |||
122 | /** |
||
123 | * {@inheritdoc} |
||
124 | */ |
||
125 | public function getDraw() { |
||
128 | |||
129 | /** |
||
130 | * {@inheritdoc} |
||
131 | */ |
||
132 | public function getLength() { |
||
135 | |||
136 | /** |
||
137 | * {@inheritdoc} |
||
138 | */ |
||
139 | public function getOrder() { |
||
142 | |||
143 | /** |
||
144 | * {@inheritdoc} |
||
145 | */ |
||
146 | public function getQuery() { |
||
149 | |||
150 | /** |
||
151 | * {@inheritdoc} |
||
152 | */ |
||
153 | public function getRequest() { |
||
156 | |||
157 | /** |
||
158 | * {@inheritdoc} |
||
159 | */ |
||
160 | public function getSearch() { |
||
163 | |||
164 | /** |
||
165 | * {@inheritdoc} |
||
166 | */ |
||
167 | public function getStart() { |
||
170 | |||
171 | /** |
||
172 | * {@inheritdoc} |
||
173 | */ |
||
174 | public function getWrapper() { |
||
177 | |||
178 | /** |
||
179 | * Parse a request. |
||
180 | * |
||
181 | * @param DataTablesWrapper $wrapper The wrapper. |
||
182 | * @param Request $request The request. |
||
183 | * @return DataTablesRequestInterface Returns the request. |
||
184 | */ |
||
185 | public static function parse(DataTablesWrapper $wrapper, Request $request) { |
||
218 | |||
219 | /** |
||
220 | * Recopy. |
||
221 | * |
||
222 | * @param ParameterBag $request The request. |
||
223 | * @param ParameterBag $bag The bag. |
||
224 | * @return void |
||
225 | */ |
||
226 | protected static function recopy(ParameterBag $request, ParameterBag $bag) { |
||
234 | |||
235 | /** |
||
236 | * Set the columns. |
||
237 | * |
||
238 | * @param DataTablesColumn[] $columns The columns. |
||
239 | * @return DataTablesRequestInterface Returns this request. |
||
240 | */ |
||
241 | protected function setColumns(array $columns) { |
||
245 | |||
246 | /** |
||
247 | * Set the draw. |
||
248 | * |
||
249 | * @param int $draw The draw. |
||
250 | * @return DataTablesRequestInterface Returns this request. |
||
251 | */ |
||
252 | protected function setDraw($draw) { |
||
256 | |||
257 | /** |
||
258 | * Set the length. |
||
259 | * |
||
260 | * @param int $length The length. |
||
261 | * @return DataTablesRequestInterface Returns this request. |
||
262 | */ |
||
263 | protected function setLength($length) { |
||
267 | |||
268 | /** |
||
269 | * Set the order. |
||
270 | * |
||
271 | * @param DataTablesOrderInterface[] $order The order. |
||
272 | * @return DataTablesRequestInterface Returns this request. |
||
273 | */ |
||
274 | protected function setOrder(array $order) { |
||
278 | |||
279 | /** |
||
280 | * Set the request. |
||
281 | * |
||
282 | * @param ParameterBag $query The query. |
||
283 | * @return DataTablesRequestInterface Returns this request. |
||
284 | */ |
||
285 | protected function setQuery(ParameterBag $query) { |
||
289 | |||
290 | /** |
||
291 | * Set the request. |
||
292 | * |
||
293 | * @param ParameterBag $request The request. |
||
294 | * @return DataTablesRequestInterface Returns this request. |
||
295 | */ |
||
296 | protected function setRequest(ParameterBag $request) { |
||
300 | |||
301 | /** |
||
302 | * Set the search. |
||
303 | * |
||
304 | * @param DataTablesSearchInterface $search The search. |
||
305 | * @return DataTablesRequestInterface Returns this request. |
||
306 | */ |
||
307 | protected function setSearch(DataTablesSearchInterface $search) { |
||
311 | |||
312 | /** |
||
313 | * Set the start. |
||
314 | * |
||
315 | * @param int $start The start. |
||
316 | * @return DataTablesRequestInterface Returns this request. |
||
317 | */ |
||
318 | protected function setStart($start) { |
||
322 | |||
323 | /** |
||
324 | * Set the wrapper. |
||
325 | * |
||
326 | * @param DataTablesWrapper $wrapper The wrapper. |
||
327 | * @return DataTablesRequestInterface Returns this request. |
||
328 | */ |
||
329 | protected function setWrapper(DataTablesWrapper $wrapper) { |
||
333 | |||
334 | } |
||
335 |
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_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.