1 | <?php |
||
15 | class FilterResource |
||
16 | { |
||
17 | /** |
||
18 | * @var Filter |
||
19 | */ |
||
20 | protected $filter; |
||
21 | |||
22 | /** |
||
23 | * @var null|string|string[] |
||
24 | */ |
||
25 | protected $keys; |
||
26 | |||
27 | /** |
||
28 | * @param Filter $filter |
||
29 | * @param null|string|string[] $keys |
||
30 | */ |
||
31 | 192 | public function __construct(Filter $filter, $keys = null) |
|
36 | |||
37 | /** |
||
38 | * Results rule that returns alphabetic numeric characters from the value |
||
39 | * |
||
40 | * @return $this |
||
41 | */ |
||
42 | 4 | public function alnum() |
|
46 | |||
47 | /** |
||
48 | * Results rule that returns the value appended with a given value |
||
49 | * |
||
50 | * @param string $append |
||
51 | * @return $this |
||
52 | */ |
||
53 | 4 | public function append($append) |
|
57 | |||
58 | /** |
||
59 | * Results rule that returns a casted boolean |
||
60 | * |
||
61 | * @return $this |
||
62 | */ |
||
63 | 16 | public function bool() |
|
67 | |||
68 | /** |
||
69 | * Returns rule that returns a value modified by a callable closure |
||
70 | * |
||
71 | * @param callable $callable |
||
72 | * @param bool $allowNotSet |
||
73 | * @return $this |
||
74 | */ |
||
75 | 6 | public function callback(callable $callable, $allowNotSet = false) |
|
79 | |||
80 | /** |
||
81 | * Results rule that returns the cut value |
||
82 | * |
||
83 | * @param int $start |
||
84 | * @param int|null $length |
||
85 | * @return $this |
||
86 | */ |
||
87 | 5 | public function cut($start, $length = null) |
|
91 | |||
92 | /** |
||
93 | * Returns rule that decodes JSON code of a given value |
||
94 | * |
||
95 | * @param bool $assoc When `true`, decoded objects will be converted into associative arrays (the default value is |
||
96 | * set to `true` because both Filter and Validator can't deal with objects) |
||
97 | * @param int $depth Decode recursion dept |
||
98 | * @param int $options Bitmask of JSON decode options |
||
99 | * @see http://php.net/manual/en/function.json-decode.php More information about the parameters |
||
100 | * @return $this |
||
101 | */ |
||
102 | 11 | public function decodeJSON($assoc = true, $depth = 512, $options = 0) |
|
106 | |||
107 | /** |
||
108 | * Returns rule that defaults a given value if the data key was not provided |
||
109 | * |
||
110 | * @param mixed $defaultValue |
||
111 | * @return $this |
||
112 | */ |
||
113 | 13 | public function defaults($defaultValue) |
|
117 | |||
118 | /** |
||
119 | * Returns rule that can filter repeated nested arrays |
||
120 | * |
||
121 | * @param callable $callable |
||
122 | * @return $this |
||
123 | */ |
||
124 | 2 | public function each(callable $callable) |
|
128 | |||
129 | /** |
||
130 | * Returns rule that returns an value in a specific encoding format |
||
131 | * |
||
132 | * @param string|null $toEncodingFormat |
||
133 | * @param string|null $fromEncodingFormat |
||
134 | * @return $this |
||
135 | */ |
||
136 | 5 | public function encode($toEncodingFormat = null, $fromEncodingFormat = null) |
|
140 | |||
141 | /** |
||
142 | * Returns rule that results a casted float |
||
143 | * |
||
144 | * @return $this |
||
145 | */ |
||
146 | 12 | public function float() |
|
150 | |||
151 | /** |
||
152 | * Returns rule that results a casted int |
||
153 | * |
||
154 | * @return $this |
||
155 | */ |
||
156 | 11 | public function int() |
|
160 | |||
161 | /** |
||
162 | * Returns rule that results all letters of a value |
||
163 | * |
||
164 | * @return $this |
||
165 | */ |
||
166 | 3 | public function letters() |
|
170 | |||
171 | /** |
||
172 | * Returns rule that results a lower-cased value |
||
173 | * |
||
174 | * @return $this |
||
175 | */ |
||
176 | 17 | public function lower() |
|
180 | |||
181 | /** |
||
182 | * Returns rule that formats numbers |
||
183 | * |
||
184 | * @param int $decimals |
||
185 | * @param string $decimalPoint |
||
186 | * @param string $thousandSeparator |
||
187 | * @return $this |
||
188 | */ |
||
189 | 12 | public function numberFormat($decimals, $decimalPoint, $thousandSeparator) |
|
193 | |||
194 | /** |
||
195 | * Returns rule that results all numbers of a value |
||
196 | * |
||
197 | * @return $this |
||
198 | */ |
||
199 | 3 | public function numbers() |
|
203 | |||
204 | /** |
||
205 | * Results rule that returns the value prepended with a given value |
||
206 | * |
||
207 | * @param string $prepend |
||
208 | * @return $this |
||
209 | */ |
||
210 | 4 | public function prepend($prepend) |
|
214 | |||
215 | /** |
||
216 | * Results rule that returns a value with replacements by a regex |
||
217 | * |
||
218 | * @param string $searchRegex |
||
219 | * @param string $replace |
||
220 | * @return $this |
||
221 | */ |
||
222 | 2 | public function regexReplace($searchRegex, $replace) |
|
226 | |||
227 | /** |
||
228 | * Results rule that returns an empty result so it can be removed |
||
229 | * |
||
230 | * @return $this |
||
231 | */ |
||
232 | 5 | public function remove() |
|
236 | |||
237 | /** |
||
238 | * Results rule that returns an empty result when the value is null so it can be removed |
||
239 | * |
||
240 | * @return $this |
||
241 | */ |
||
242 | 7 | public function removeNull() |
|
246 | |||
247 | /** |
||
248 | * Results rule that returns a value with replacements |
||
249 | * |
||
250 | * @param mixed $search |
||
251 | * @param mixed $replace |
||
252 | * @return $this |
||
253 | */ |
||
254 | 5 | public function replace($search, $replace) |
|
258 | |||
259 | /** |
||
260 | * Results that returns a value slugged |
||
261 | * |
||
262 | * @param string|null $fieldToSlugFrom |
||
263 | * @return $this |
||
264 | */ |
||
265 | 11 | public function slug($fieldToSlugFrom = null) |
|
269 | |||
270 | /** |
||
271 | * Returns rule that results a casted string |
||
272 | * |
||
273 | * @return $this |
||
274 | */ |
||
275 | 7 | public function string() |
|
279 | |||
280 | /** |
||
281 | * Results rule that results a html-stripped value |
||
282 | * |
||
283 | * @param null|string $excludeTags |
||
284 | * @return $this |
||
285 | */ |
||
286 | 4 | public function stripHtml($excludeTags = null) |
|
290 | |||
291 | /** |
||
292 | * Returns rule that results a trimmed value |
||
293 | * |
||
294 | * @param string|null $characters |
||
295 | * @return $this |
||
296 | */ |
||
297 | 22 | public function trim($characters = null) |
|
301 | |||
302 | /** |
||
303 | * Results rule that returns an upper-cased value |
||
304 | * |
||
305 | * @return $this |
||
306 | */ |
||
307 | 7 | public function upper() |
|
311 | |||
312 | /** |
||
313 | * Returns rule that results a value starting with a upper-cased character |
||
314 | * |
||
315 | * @return $this |
||
316 | */ |
||
317 | 14 | public function upperFirst() |
|
321 | |||
322 | /** |
||
323 | * Add a new rule to the chain |
||
324 | * |
||
325 | * @param FilterRule $rule |
||
326 | * @return $this |
||
327 | */ |
||
328 | 191 | protected function addRule(FilterRule $rule) |
|
344 | } |
||
345 |