1 | <?php |
||
23 | class RequestParameters |
||
24 | { |
||
25 | const DEFAULT_PAGE = 1; |
||
26 | const DEFAULT_MAX_RESULTS = 25; |
||
27 | |||
28 | /** |
||
29 | * Start date. |
||
30 | * |
||
31 | * @var DateTime|null |
||
32 | */ |
||
33 | protected $startDate; |
||
34 | |||
35 | /** |
||
36 | * End date. |
||
37 | * |
||
38 | * @var DateTime|null |
||
39 | */ |
||
40 | protected $endDate; |
||
41 | |||
42 | /** |
||
43 | * Query for text search. |
||
44 | * |
||
45 | * @var string|null |
||
46 | */ |
||
47 | protected $query; |
||
48 | |||
49 | /** |
||
50 | * Page. |
||
51 | * |
||
52 | * @var int |
||
53 | */ |
||
54 | protected $page = self::DEFAULT_PAGE; |
||
55 | |||
56 | /** |
||
57 | * Max results per page. |
||
58 | * |
||
59 | * @var int |
||
60 | */ |
||
61 | protected $maxResults = self::DEFAULT_MAX_RESULTS; |
||
62 | |||
63 | /** |
||
64 | * Include fields list. These fields will be set in your packages or items. |
||
65 | * |
||
66 | * @var array|null |
||
67 | */ |
||
68 | protected $includeFields; |
||
69 | |||
70 | /** |
||
71 | * Exclude fields lists. These fields won't be set in your packages or items. |
||
72 | * |
||
73 | * @var array|null |
||
74 | */ |
||
75 | protected $excludeFields; |
||
76 | |||
77 | /** |
||
78 | * Mapping array, which links correct parameter name for API with proper |
||
79 | * method. |
||
80 | * |
||
81 | * @var string[] |
||
82 | */ |
||
83 | protected $propertyMapping = array( |
||
84 | 'start_date' => 'getStartDate', |
||
85 | 'end_date' => 'getEndDate', |
||
86 | 'q' => 'getQuery', |
||
87 | 'page' => 'getPage', |
||
88 | 'max_results' => 'getMaxResults', |
||
89 | 'include_fields' => 'getIncludeFields', |
||
90 | 'exclude_fields' => 'getExcludeFields', |
||
91 | ); |
||
92 | |||
93 | /** |
||
94 | * Returns start date. |
||
95 | * |
||
96 | * @return DateTime|null |
||
97 | */ |
||
98 | public function getStartDate() |
||
102 | |||
103 | /** |
||
104 | * Sets start date. Will accept a string formatted 'yyyy-mm-dd' or DateTime |
||
105 | * object. |
||
106 | * |
||
107 | * @param string|DateTime|null $startDate |
||
108 | * |
||
109 | * @return self |
||
110 | */ |
||
111 | public function setStartDate($startDate) |
||
117 | |||
118 | /** |
||
119 | * Returns end date. |
||
120 | * |
||
121 | * @return DateTime|null |
||
122 | */ |
||
123 | public function getEndDate() |
||
127 | |||
128 | /** |
||
129 | * Sets end date. Will accept string formatted 'yyyy-mm-dd' or DateTIme |
||
130 | * object. |
||
131 | * |
||
132 | * @param string|DateTime|null $endDate |
||
133 | * |
||
134 | * @return self |
||
135 | */ |
||
136 | public function setEndDate($endDate) |
||
142 | |||
143 | /** |
||
144 | * Returns text query. |
||
145 | * |
||
146 | * @return string |
||
147 | */ |
||
148 | public function getQuery() |
||
152 | |||
153 | /** |
||
154 | * Sets query parameters. |
||
155 | * |
||
156 | * @param string|null $query |
||
157 | * |
||
158 | * @return self |
||
159 | */ |
||
160 | public function setQuery($query) |
||
170 | |||
171 | /** |
||
172 | * Returns page number. |
||
173 | * |
||
174 | * @return int |
||
175 | */ |
||
176 | public function getPage() |
||
180 | |||
181 | /** |
||
182 | * Sets page number. If null is supplied, resets to class default. |
||
183 | * |
||
184 | * @param int|null $page |
||
185 | * |
||
186 | * @return self |
||
187 | */ |
||
188 | public function setPage($page) |
||
198 | |||
199 | /** |
||
200 | * Returns maximum results per page. |
||
201 | * |
||
202 | * @return int |
||
203 | */ |
||
204 | public function getMaxResults() |
||
208 | |||
209 | /** |
||
210 | * Sets maximum results per page. If null is supplied, resets to class |
||
211 | * default. |
||
212 | * |
||
213 | * @param int|nul $maxResults |
||
214 | * |
||
215 | * @return self |
||
216 | */ |
||
217 | public function setMaxResults($maxResults) |
||
227 | |||
228 | /** |
||
229 | * Returns include fields. |
||
230 | * |
||
231 | * @return array |
||
232 | */ |
||
233 | public function getIncludeFields() |
||
237 | |||
238 | /** |
||
239 | * Sets include fields. |
||
240 | * |
||
241 | * @param array|null $includeFields |
||
242 | * |
||
243 | * @return self |
||
244 | */ |
||
245 | public function setIncludeFields($includeFields) |
||
251 | |||
252 | /** |
||
253 | * Gets exclude fields. |
||
254 | * |
||
255 | * @return array |
||
256 | */ |
||
257 | public function getExcludeFields() |
||
261 | |||
262 | /** |
||
263 | * Sets exclude fields |
||
264 | * |
||
265 | * @param array|null |
||
266 | * |
||
267 | * @return self |
||
268 | */ |
||
269 | public function setExcludeFields($excludeFields) |
||
275 | |||
276 | /** |
||
277 | * Validate date parameter input and converts to DateTime. |
||
278 | * |
||
279 | * @param string|DateTime $date When string format yyyy-mm-dd should be used |
||
280 | * |
||
281 | * @return DateTime |
||
282 | * @throws InvalidArgumentException |
||
283 | */ |
||
284 | private function validateDate($date) |
||
298 | |||
299 | /** |
||
300 | * Arguments of type string and array are valid. String will be split on , |
||
301 | * and converted to an array. |
||
302 | * |
||
303 | * @param string|array $value |
||
304 | * |
||
305 | * @return array |
||
306 | * @throws InvalidArgumentException |
||
307 | */ |
||
308 | private function validateStringOrArray($value) |
||
318 | |||
319 | /** |
||
320 | * Validates if value is numeric. |
||
321 | * |
||
322 | * @param string|int $value |
||
323 | * |
||
324 | * @return int |
||
325 | * @throws InvalidArgumentException |
||
326 | */ |
||
327 | private function validateNumeric($value) |
||
337 | |||
338 | /** |
||
339 | * Helper function for setting a property. Sets a proprety to a value, by |
||
340 | * pulling it through a validator function. If null is specified as value |
||
341 | * then property will be set to null as well.. |
||
342 | * |
||
343 | * @param string $property Property name |
||
344 | * @param string $value Value of the property |
||
345 | * @param string $validator Name of the validator method |
||
346 | * |
||
347 | * @throws InvalidArgumentException |
||
348 | */ |
||
349 | private function setProperty($property, $value, $validator) |
||
361 | |||
362 | /** |
||
363 | * Returns all properties either as an array or http query string. |
||
364 | * |
||
365 | * @param boolean $buildHttpQuery Build query from array |
||
366 | * |
||
367 | * @return mixed[]|string |
||
368 | */ |
||
369 | public function getAllParameters($buildHttpQuery = false) |
||
386 | } |
||
387 |
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.