1 | <?php |
||
18 | class Transform |
||
19 | { |
||
20 | /** |
||
21 | * The character used to separate modifier parameters. |
||
22 | * |
||
23 | * @var string |
||
24 | */ |
||
25 | public $paramDelimiter = '|'; |
||
26 | |||
27 | /** |
||
28 | * Upper limit to how many levels of included data are allowed. |
||
29 | * |
||
30 | * @var int |
||
31 | */ |
||
32 | public $recursionLimit = 10; |
||
33 | |||
34 | /** |
||
35 | * Scope identifiers that resources can optionally include. |
||
36 | * |
||
37 | * @var array |
||
38 | */ |
||
39 | protected $includes = []; |
||
40 | |||
41 | /** |
||
42 | * Scope identifiers that resources must exclude. |
||
43 | * |
||
44 | * @var array |
||
45 | */ |
||
46 | protected $excludes = []; |
||
47 | |||
48 | /** |
||
49 | * Scope identifiers that resources must return. |
||
50 | * |
||
51 | * @var array |
||
52 | */ |
||
53 | protected $fields = []; |
||
54 | |||
55 | /** |
||
56 | * Array containing modifiers as keys and an array value of params. |
||
57 | * |
||
58 | * @var array |
||
59 | */ |
||
60 | protected $params = []; |
||
61 | |||
62 | /** |
||
63 | * @param array $config |
||
64 | */ |
||
65 | public function __construct(array $config = []) |
||
69 | |||
70 | /** |
||
71 | * @param string $include |
||
72 | * |
||
73 | * @return ParamBag |
||
74 | */ |
||
75 | public function getParams($include): ParamBag |
||
80 | |||
81 | /******************************************* |
||
82 | * INCLUDES |
||
83 | *******************************************/ |
||
84 | |||
85 | /** |
||
86 | * Get Requested Includes. |
||
87 | * |
||
88 | * @return array |
||
89 | */ |
||
90 | public function getIncludes(): array |
||
94 | |||
95 | /** |
||
96 | * Parse Include String. |
||
97 | * |
||
98 | * @param array|string $includes Array or csv string of resources to include |
||
99 | * |
||
100 | * @return $this |
||
101 | */ |
||
102 | public function setIncludes($includes) |
||
161 | |||
162 | /******************************************* |
||
163 | * EXCLUDES |
||
164 | *******************************************/ |
||
165 | |||
166 | /** |
||
167 | * Get Requested Excludes. |
||
168 | * |
||
169 | * @return array |
||
170 | */ |
||
171 | public function getExcludes(): array |
||
175 | |||
176 | /** |
||
177 | * Parse Exclude String. |
||
178 | * |
||
179 | * @param array|string $excludes Array or csv string of resources to exclude |
||
180 | * |
||
181 | * @return $this |
||
182 | */ |
||
183 | public function setExcludes($excludes) |
||
209 | |||
210 | /******************************************* |
||
211 | * FIELDS |
||
212 | *******************************************/ |
||
213 | |||
214 | /** |
||
215 | * Parse field parameter. |
||
216 | * |
||
217 | * @param array $fields Array of fields to include. It must be an array |
||
218 | * whose keys are resource types and values a string |
||
219 | * of the fields to return, separated by a comma |
||
220 | * |
||
221 | * @return $this |
||
222 | */ |
||
223 | public function setFields(array $fields) |
||
234 | |||
235 | /** |
||
236 | * Get requested fields. |
||
237 | * |
||
238 | * @return array |
||
239 | */ |
||
240 | public function getFields(): array |
||
244 | |||
245 | /** |
||
246 | * Get field params for the specified type. |
||
247 | * |
||
248 | * @param string $type |
||
249 | * |
||
250 | * @return ParamBag|null |
||
251 | */ |
||
252 | public function getField($type) |
||
258 | |||
259 | |||
260 | /******************************************* |
||
261 | * RESOURCES |
||
262 | *******************************************/ |
||
263 | |||
264 | /** |
||
265 | * @param callable $transformer |
||
266 | * @param $data |
||
267 | * @param array $extra |
||
268 | * @return array |
||
269 | */ |
||
270 | public function item(callable $transformer, $data, array $extra = []): array |
||
280 | |||
281 | /** |
||
282 | * @param callable $transformer |
||
283 | * @param $data |
||
284 | * @param array $extra |
||
285 | * @return mixed |
||
286 | */ |
||
287 | public function collection(callable $transformer, array $data, array $extra = []): array |
||
302 | |||
303 | |||
304 | /** |
||
305 | * Auto-include Parents |
||
306 | * |
||
307 | * Look at the requested includes and automatically include the parents if they |
||
308 | * are not explicitly requested. E.g: [foo, bar.baz] becomes [foo, bar, bar.baz] |
||
309 | * |
||
310 | * @internal |
||
311 | * |
||
312 | * @return void |
||
313 | */ |
||
314 | protected function autoIncludeParents() |
||
332 | |||
333 | /** |
||
334 | * Trim to Acceptable Recursion Level |
||
335 | * |
||
336 | * @internal |
||
337 | * |
||
338 | * @param string $includeName |
||
339 | * |
||
340 | * @return string |
||
341 | */ |
||
342 | protected function trimToAcceptableRecursionLevel($includeName) |
||
346 | } |
||
347 |