1 | <?php |
||
7 | trait Sortable |
||
8 | { |
||
9 | |||
10 | /** |
||
11 | * Url query parameter key for sorting |
||
12 | * |
||
13 | * @var string |
||
14 | */ |
||
15 | private $sortableKey = 'sort'; |
||
16 | |||
17 | /** |
||
18 | * Delimiter of chained sort string, |
||
19 | * e.g. ?sort=foo|bar |
||
20 | * |
||
21 | * @var string |
||
22 | */ |
||
23 | private $sortDelimiter = '|'; |
||
24 | |||
25 | /** |
||
26 | * Collection of allowed keys to sort on |
||
27 | * |
||
28 | * @var array |
||
29 | */ |
||
30 | private $sortableWhitelist; |
||
31 | |||
32 | /** |
||
33 | * Key that should be used to sort the current Query |
||
34 | * |
||
35 | * @var array |
||
36 | */ |
||
37 | private $sortablePayload; |
||
38 | |||
39 | /** |
||
40 | * Enable sort |
||
41 | * |
||
42 | * @param array $sortableWhitelist - whitelist of sortable parameters |
||
43 | * @param array $forcedPayload - enforce these sorters |
||
44 | * @param array $defaultPayload - default sorting if no sorting is passed |
||
45 | * @return $this |
||
46 | */ |
||
47 | public function sort($sortableWhitelist = null, $forcedPayload = [], $defaultPayload = []) |
||
57 | |||
58 | /** |
||
59 | * Get our current sorters |
||
60 | * |
||
61 | * Sorters custom sorting payload which has priority |
||
62 | * uriSorters By default the sorters provided via uri payload are used |
||
63 | * defaults if none are given, a default sorter can be activated |
||
64 | * |
||
65 | * @param array $forcedPayload |
||
66 | * @param array $defaultPayload |
||
67 | * @return array |
||
68 | */ |
||
69 | protected function setSortablePayload($forcedPayload = [], $defaultPayload = []) |
||
81 | |||
82 | /** |
||
83 | * Process the sorting payload |
||
84 | * |
||
85 | * If the url query contains the sort key, the belonging values are taken into account for sorting. |
||
86 | * multiple values are separated by a comma. |
||
87 | * Default is Ascending sort, a minus before a value depicts a descending direction |
||
88 | * |
||
89 | * @return void |
||
90 | */ |
||
91 | protected function handleSortablePayload() |
||
105 | |||
106 | /** |
||
107 | * @param $key |
||
108 | * @param $sorter |
||
109 | * @param $order |
||
110 | */ |
||
111 | protected function addSortQuery($key, $sorter, $order) |
||
121 | |||
122 | /** |
||
123 | * @param $sorter |
||
124 | * @return array |
||
125 | */ |
||
126 | protected function getSorterAndOrderFromQueryString($sorter) |
||
134 | |||
135 | private function convertToCleanArray($values) |
||
158 | } |
||
159 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: