1 | <?php |
||
7 | trait QueryStringParserTrait |
||
8 | { |
||
9 | /** |
||
10 | * Parse HTTP query string and return array representation |
||
11 | * to be attached to a database query. |
||
12 | * |
||
13 | * @param string $query |
||
14 | * |
||
15 | * @return array |
||
16 | */ |
||
17 | 11 | public function parseQueryString($query) |
|
36 | |||
37 | /** |
||
38 | * Map the parsed query string in to correct array structure. |
||
39 | * |
||
40 | * @param string $key |
||
41 | * @param mixed $value |
||
42 | * |
||
43 | * @return array|boolean |
||
44 | */ |
||
45 | 10 | protected function filterQueryParams($key, $value) |
|
65 | |||
66 | /** |
||
67 | * Map search to a usable format. |
||
68 | * |
||
69 | * @param string $value |
||
70 | * |
||
71 | * @return array |
||
72 | */ |
||
73 | protected function parseSearch($value) |
||
74 | { |
||
75 | $search = explode('|', $value); |
||
76 | |||
77 | if (count($search) !== 2) { |
||
78 | throw new InvalidArgumentException( |
||
79 | 'Malformed query string, search format should be (search=column|term) or (search=column1,column2|term)' |
||
80 | ); |
||
81 | } |
||
82 | |||
83 | return [ |
||
84 | 'fields' => $search[0], |
||
85 | 'term' => $search[1] |
||
86 | ]; |
||
87 | } |
||
88 | |||
89 | /** |
||
90 | * Map filters in to useable array. |
||
91 | * |
||
92 | * @param array $filters |
||
93 | * |
||
94 | * @return array |
||
95 | */ |
||
96 | 9 | protected function parseFilters(array $filters) |
|
127 | } |
||
128 |