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 | 176 | public function __construct(Filter $filter, $keys = null) |
|
32 | { |
||
33 | 176 | $this->filter = $filter; |
|
34 | 176 | $this->keys = $keys; |
|
35 | 176 | } |
|
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 Chain |
||
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 Chain |
||
86 | */ |
||
87 | 4 | public function cut($start, $length = null) |
|
88 | { |
||
89 | 4 | return $this->addRule(new FilterRule\Cut($start, $length)); |
|
90 | } |
||
91 | |||
92 | /** |
||
93 | * Returns rule that defaults a given value if the data key was not provided |
||
94 | * |
||
95 | * @param mixed $defaultValue |
||
96 | * @return $this |
||
97 | */ |
||
98 | 13 | public function defaults($defaultValue) |
|
99 | { |
||
100 | 13 | return $this->addRule(new FilterRule\Defaults($defaultValue)); |
|
101 | } |
||
102 | |||
103 | /** |
||
104 | * Returns rule that can filter repeated nested arrays |
||
105 | * |
||
106 | * @param callable $callable |
||
107 | * @return $this |
||
108 | */ |
||
109 | 2 | public function each(callable $callable) |
|
113 | |||
114 | /** |
||
115 | * Returns rule that returns an value in a specific encoding format |
||
116 | * |
||
117 | * @param string|null $toEncodingFormat |
||
118 | * @param string|null $fromEncodingFormat |
||
119 | * @return $this |
||
120 | */ |
||
121 | 5 | public function encode($toEncodingFormat = null, $fromEncodingFormat = null) |
|
122 | { |
||
123 | 5 | return $this->addRule(new FilterRule\Encode($toEncodingFormat, $fromEncodingFormat)); |
|
124 | } |
||
125 | |||
126 | /** |
||
127 | * Returns rule that results a casted float |
||
128 | * |
||
129 | * @return $this |
||
130 | */ |
||
131 | 12 | public function float() |
|
132 | { |
||
133 | 12 | return $this->addRule(new FilterRule\CastFloat); |
|
134 | } |
||
135 | |||
136 | /** |
||
137 | * Returns rule that results a casted int |
||
138 | * |
||
139 | * @return $this |
||
140 | */ |
||
141 | 11 | public function int() |
|
142 | { |
||
143 | 11 | return $this->addRule(new FilterRule\CastInt); |
|
144 | } |
||
145 | |||
146 | /** |
||
147 | * Returns rule that results all letters of a value |
||
148 | * |
||
149 | * @return $this |
||
150 | */ |
||
151 | 3 | public function letters() |
|
152 | { |
||
153 | 3 | return $this->addRule(new FilterRule\Letters); |
|
154 | } |
||
155 | |||
156 | /** |
||
157 | * Returns rule that results a lower-cased value |
||
158 | * |
||
159 | * @return $this |
||
160 | */ |
||
161 | 17 | public function lower() |
|
165 | |||
166 | /** |
||
167 | * Returns rule that formats numbers |
||
168 | * |
||
169 | * @param int $decimals |
||
170 | * @param string $decimalPoint |
||
171 | * @param string $thousandSeparator |
||
172 | * @return $this |
||
173 | */ |
||
174 | 12 | public function numberFormat($decimals, $decimalPoint, $thousandSeparator) |
|
175 | { |
||
176 | 12 | return $this->addRule(new FilterRule\NumberFormat($decimals, $decimalPoint, $thousandSeparator)); |
|
177 | } |
||
178 | |||
179 | /** |
||
180 | * Returns rule that results all numbers of a value |
||
181 | * |
||
182 | * @return $this |
||
183 | */ |
||
184 | 3 | public function numbers() |
|
185 | { |
||
186 | 3 | return $this->addRule(new FilterRule\Numbers); |
|
187 | } |
||
188 | |||
189 | /** |
||
190 | * Results rule that returns the value prepended with a given value |
||
191 | * |
||
192 | * @param string $prepend |
||
193 | * @return Chain |
||
194 | */ |
||
195 | 4 | public function prepend($prepend) |
|
199 | |||
200 | /** |
||
201 | * Results rule that returns a value with replacements by a regex |
||
202 | * |
||
203 | * @param string $searchRegex |
||
204 | * @param string $replace |
||
205 | * @return $this |
||
206 | */ |
||
207 | 2 | public function regexReplace($searchRegex, $replace) |
|
208 | { |
||
209 | 2 | return $this->addRule(new FilterRule\RegexReplace($searchRegex, $replace)); |
|
210 | } |
||
211 | |||
212 | /** |
||
213 | * Results rule that returns an empty result so it can be removed |
||
214 | * |
||
215 | * @return $this |
||
216 | */ |
||
217 | 5 | public function remove() |
|
218 | { |
||
219 | 5 | return $this->addRule(new FilterRule\Remove); |
|
220 | } |
||
221 | |||
222 | /** |
||
223 | * Results rule that returns an empty result when the value is null so it can be removed |
||
224 | * |
||
225 | * @return $this |
||
226 | */ |
||
227 | 7 | public function removeNull() |
|
231 | |||
232 | /** |
||
233 | * Results rule that returns a value with replacements |
||
234 | * |
||
235 | * @param mixed $search |
||
236 | * @param mixed $replace |
||
237 | * @return $this |
||
238 | */ |
||
239 | 5 | public function replace($search, $replace) |
|
240 | { |
||
241 | 5 | return $this->addRule(new FilterRule\Replace($search, $replace)); |
|
243 | |||
244 | /** |
||
245 | * Results that returns a value slugged |
||
246 | * |
||
247 | * @param string|null $fieldToSlugFrom |
||
248 | * @return $this |
||
249 | */ |
||
250 | 8 | public function slug($fieldToSlugFrom = null) |
|
254 | |||
255 | /** |
||
256 | * Returns rule that results a casted string |
||
257 | * |
||
258 | * @return $this |
||
259 | */ |
||
260 | 7 | public function string() |
|
264 | |||
265 | /** |
||
266 | * Results rule that results a html-stripped value |
||
267 | * |
||
268 | * @param null|string $excludeTags |
||
269 | * @return $this |
||
270 | */ |
||
271 | 4 | public function stripHtml($excludeTags = null) |
|
275 | |||
276 | /** |
||
277 | * Returns rule that results a trimmed value |
||
278 | * |
||
279 | * @param string|null $characters |
||
280 | * @return $this |
||
281 | */ |
||
282 | 21 | public function trim($characters = null) |
|
286 | |||
287 | /** |
||
288 | * Results rule that returns an upper-cased value |
||
289 | * |
||
290 | * @return $this |
||
291 | */ |
||
292 | 7 | public function upper() |
|
296 | |||
297 | /** |
||
298 | * Returns rule that results a value starting with a upper-cased character |
||
299 | * |
||
300 | * @return $this |
||
301 | */ |
||
302 | 14 | public function upperFirst() |
|
306 | |||
307 | /** |
||
308 | * Add a new rule to the chain |
||
309 | * |
||
310 | * @param FilterRule $rule |
||
311 | * @return $this |
||
312 | */ |
||
313 | 175 | protected function addRule(FilterRule $rule) |
|
329 | } |
||
330 |