1 | <?php |
||
18 | class Filter |
||
19 | { |
||
20 | /** |
||
21 | * @var array<string, Chain> |
||
22 | */ |
||
23 | protected $chains = []; |
||
24 | |||
25 | /** |
||
26 | * @var Container |
||
27 | */ |
||
28 | protected $data; |
||
29 | |||
30 | /** |
||
31 | * @var string|null |
||
32 | */ |
||
33 | protected $encodingFormat = null; |
||
34 | |||
35 | /** |
||
36 | * @var Chain |
||
37 | */ |
||
38 | protected $globalChain = null; |
||
39 | |||
40 | /** |
||
41 | * Set a filter for a value on a specific key |
||
42 | * |
||
43 | * @param string $key |
||
44 | * @return FilterResource |
||
45 | */ |
||
46 | 154 | public function value($key) |
|
50 | |||
51 | /** |
||
52 | * Set a filter for the values on the given keys |
||
53 | * |
||
54 | * @param string[] $keys |
||
55 | * @return FilterResource |
||
56 | */ |
||
57 | 7 | public function values(array $keys) |
|
61 | |||
62 | /** |
||
63 | * Set a filter for all values off an array |
||
64 | * |
||
65 | * @return FilterResource |
||
66 | */ |
||
67 | 4 | public function all() |
|
71 | |||
72 | /** |
||
73 | * @param null|string|string[] $keys |
||
74 | * @return FilterResource |
||
75 | */ |
||
76 | 164 | public function getFilterResource($keys = null) |
|
80 | |||
81 | /** |
||
82 | * Set the encoding format for all string manipulating filter-rules. |
||
83 | * Note: You should set the encoding format before you add filter-rules to your filter, otherwise the |
||
84 | * encoding format would not be set on the values added before the encoding format was set. |
||
85 | * |
||
86 | * @param string $encodingFormat |
||
87 | */ |
||
88 | 6 | public function setEncodingFormat($encodingFormat) |
|
92 | |||
93 | /** |
||
94 | * Set a filter rule on a chain |
||
95 | * |
||
96 | * @param FilterRule $rule |
||
97 | * @param null|string $key |
||
98 | */ |
||
99 | 163 | public function addFilterRule(FilterRule $rule, $key = null) |
|
103 | |||
104 | /** |
||
105 | * Filter the provided data |
||
106 | * |
||
107 | * @param array $data |
||
108 | * @return array |
||
109 | */ |
||
110 | 165 | public function filter(array $data) |
|
120 | |||
121 | /** |
||
122 | * Filter all set fields with a global chain, recursively |
||
123 | * |
||
124 | * @param array $data |
||
125 | * @return array |
||
126 | */ |
||
127 | 165 | protected function filterArrayWithGlobalChain(array $data) |
|
139 | |||
140 | /** |
||
141 | * Filters a value with the global chain |
||
142 | * |
||
143 | * @param mixed $value |
||
144 | * @param string $key |
||
145 | * @param array $data |
||
146 | * @return array |
||
147 | */ |
||
148 | 4 | protected function filterValueWithGlobalChain($value, $key, $data) |
|
163 | |||
164 | /** |
||
165 | * Get the filter result from a chain |
||
166 | * |
||
167 | * @param string $key |
||
168 | * @param Chain $chain |
||
169 | * @return FilterResult |
||
170 | */ |
||
171 | 159 | protected function getFilterResult($key, Chain $chain) |
|
179 | |||
180 | /** |
||
181 | * Filter all chains set |
||
182 | */ |
||
183 | 165 | protected function filterChains() |
|
197 | |||
198 | /** |
||
199 | * Get a filter rule chain for a key |
||
200 | * |
||
201 | * @param null|string $key |
||
202 | * @return Chain |
||
203 | */ |
||
204 | 163 | protected function getChain($key) |
|
217 | |||
218 | /** |
||
219 | * Get the global chain for all values |
||
220 | * |
||
221 | * @return Chain |
||
222 | */ |
||
223 | 4 | protected function getGlobalChain() |
|
230 | |||
231 | /** |
||
232 | * Build a new chain of filters |
||
233 | * |
||
234 | * @return Chain |
||
235 | */ |
||
236 | 163 | protected function buildChain() |
|
240 | } |
||
241 |