1 | <?php |
||
23 | class DataTablesRequest implements DataTablesRequestInterface, HTTPInterface { |
||
24 | |||
25 | /** |
||
26 | * @var DataTablesWrapperTrait |
||
27 | */ |
||
28 | use DataTablesWrapperTrait; |
||
29 | |||
30 | /** |
||
31 | * Columns. |
||
32 | * |
||
33 | * @var DataTablesColumnInterface[] |
||
34 | */ |
||
35 | private $columns; |
||
36 | |||
37 | /** |
||
38 | * Draw. |
||
39 | * |
||
40 | * @var int |
||
41 | */ |
||
42 | private $draw; |
||
43 | |||
44 | /** |
||
45 | * Length. |
||
46 | * |
||
47 | * @var int |
||
48 | */ |
||
49 | private $length; |
||
50 | |||
51 | /** |
||
52 | * Order. |
||
53 | * |
||
54 | * @var DataTablesOrderInterface[] |
||
55 | */ |
||
56 | private $order; |
||
57 | |||
58 | /** |
||
59 | * Query. |
||
60 | * |
||
61 | * @var ParameterBag |
||
62 | */ |
||
63 | private $query; |
||
64 | |||
65 | /** |
||
66 | * Request. |
||
67 | * |
||
68 | * @var ParameterBag |
||
69 | */ |
||
70 | private $request; |
||
71 | |||
72 | /** |
||
73 | * Search. |
||
74 | * |
||
75 | * @var DataTablesSearchInterface |
||
76 | */ |
||
77 | private $search; |
||
78 | |||
79 | /** |
||
80 | * Start. |
||
81 | * |
||
82 | * @var int |
||
83 | */ |
||
84 | private $start; |
||
85 | |||
86 | /** |
||
87 | * Constructor. |
||
88 | */ |
||
89 | public function __construct() { |
||
98 | |||
99 | /** |
||
100 | * {@inheritdoc} |
||
101 | */ |
||
102 | public function getColumn($data) { |
||
110 | |||
111 | /** |
||
112 | * {@inheritdoc} |
||
113 | */ |
||
114 | public function getColumns() { |
||
117 | |||
118 | /** |
||
119 | * {@inheritdoc} |
||
120 | */ |
||
121 | public function getDraw() { |
||
124 | |||
125 | /** |
||
126 | * {@inheritdoc} |
||
127 | */ |
||
128 | public function getLength() { |
||
131 | |||
132 | /** |
||
133 | * {@inheritdoc} |
||
134 | */ |
||
135 | public function getOrder() { |
||
138 | |||
139 | /** |
||
140 | * {@inheritdoc} |
||
141 | */ |
||
142 | public function getQuery() { |
||
145 | |||
146 | /** |
||
147 | * {@inheritdoc} |
||
148 | */ |
||
149 | public function getRequest() { |
||
152 | |||
153 | /** |
||
154 | * {@inheritdoc} |
||
155 | */ |
||
156 | public function getSearch() { |
||
159 | |||
160 | /** |
||
161 | * {@inheritdoc} |
||
162 | */ |
||
163 | public function getStart() { |
||
166 | |||
167 | /** |
||
168 | * Set the columns. |
||
169 | * |
||
170 | * @param DataTablesColumnInterface[] $columns The columns. |
||
171 | * @return DataTablesRequestInterface Returns this request. |
||
172 | */ |
||
173 | public function setColumns(array $columns) { |
||
177 | |||
178 | /** |
||
179 | * Set the draw. |
||
180 | * |
||
181 | * @param int $draw The draw. |
||
182 | * @return DataTablesRequestInterface Returns this request. |
||
183 | */ |
||
184 | public function setDraw($draw) { |
||
188 | |||
189 | /** |
||
190 | * Set the length. |
||
191 | * |
||
192 | * @param int $length The length. |
||
193 | * @return DataTablesRequestInterface Returns this request. |
||
194 | */ |
||
195 | public function setLength($length) { |
||
199 | |||
200 | /** |
||
201 | * Set the order. |
||
202 | * |
||
203 | * @param DataTablesOrderInterface[] $order The order. |
||
204 | * @return DataTablesRequestInterface Returns this request. |
||
205 | */ |
||
206 | public function setOrder(array $order) { |
||
210 | |||
211 | /** |
||
212 | * Set the request. |
||
213 | * |
||
214 | * @param ParameterBag $query The query. |
||
215 | * @return DataTablesRequestInterface Returns this request. |
||
216 | */ |
||
217 | protected function setQuery(ParameterBag $query) { |
||
221 | |||
222 | /** |
||
223 | * Set the request. |
||
224 | * |
||
225 | * @param ParameterBag $request The request. |
||
226 | * @return DataTablesRequestInterface Returns this request. |
||
227 | */ |
||
228 | protected function setRequest(ParameterBag $request) { |
||
232 | |||
233 | /** |
||
234 | * Set the search. |
||
235 | * |
||
236 | * @param DataTablesSearchInterface $search The search. |
||
237 | * @return DataTablesRequestInterface Returns this request. |
||
238 | */ |
||
239 | public function setSearch(DataTablesSearchInterface $search) { |
||
243 | |||
244 | /** |
||
245 | * Set the start. |
||
246 | * |
||
247 | * @param int $start The start. |
||
248 | * @return DataTablesRequestInterface Returns this request. |
||
249 | */ |
||
250 | public function setStart($start) { |
||
254 | |||
255 | } |
||
256 |
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.