1 | <?php |
||
20 | class Transform |
||
21 | { |
||
22 | /** |
||
23 | * The character used to separate modifier parameters. |
||
24 | * |
||
25 | * @var string |
||
26 | */ |
||
27 | public $paramDelimiter = '|'; |
||
28 | |||
29 | /** |
||
30 | * Upper limit to how many levels of included data are allowed. |
||
31 | * |
||
32 | * @var int |
||
33 | */ |
||
34 | public $recursionLimit = 10; |
||
35 | |||
36 | /** |
||
37 | * Scope identifiers that resources can optionally include. |
||
38 | * |
||
39 | * @var array |
||
40 | */ |
||
41 | protected $includes = []; |
||
42 | |||
43 | /** |
||
44 | * Scope identifiers that resources must exclude. |
||
45 | * |
||
46 | * @var array |
||
47 | */ |
||
48 | protected $excludes = []; |
||
49 | |||
50 | /** |
||
51 | * Scope identifiers that resources must return. |
||
52 | * |
||
53 | * @var array |
||
54 | */ |
||
55 | protected $fields = []; |
||
56 | |||
57 | /** |
||
58 | * Array containing modifiers as keys and an array value of params. |
||
59 | * |
||
60 | * @var array |
||
61 | */ |
||
62 | protected $params = []; |
||
63 | |||
64 | /** |
||
65 | * @param array $config |
||
66 | */ |
||
67 | public function __construct(array $config = []) |
||
71 | |||
72 | /** |
||
73 | * @param string $include |
||
74 | * |
||
75 | * @return ParamBag |
||
76 | */ |
||
77 | public function getParams($include): ParamBag |
||
82 | |||
83 | /******************************************* |
||
84 | * INCLUDES |
||
85 | *******************************************/ |
||
86 | |||
87 | /** |
||
88 | * Get Requested Includes. |
||
89 | * |
||
90 | * @return array |
||
91 | */ |
||
92 | public function getIncludes(): array |
||
96 | |||
97 | /** |
||
98 | * Parse Include String. |
||
99 | * |
||
100 | * @param array|string $includes Array or csv string of resources to include |
||
101 | * |
||
102 | * @return $this |
||
103 | */ |
||
104 | public function setIncludes($includes) |
||
163 | |||
164 | /******************************************* |
||
165 | * EXCLUDES |
||
166 | *******************************************/ |
||
167 | |||
168 | /** |
||
169 | * Get Requested Excludes. |
||
170 | * |
||
171 | * @return array |
||
172 | */ |
||
173 | public function getExcludes(): array |
||
177 | |||
178 | /** |
||
179 | * Parse Exclude String. |
||
180 | * |
||
181 | * @param array|string $excludes Array or csv string of resources to exclude |
||
182 | * |
||
183 | * @return $this |
||
184 | */ |
||
185 | public function setExcludes($excludes) |
||
211 | |||
212 | /******************************************* |
||
213 | * FIELDS |
||
214 | *******************************************/ |
||
215 | |||
216 | /** |
||
217 | * Parse field parameter. |
||
218 | * |
||
219 | * @param array $fields Array of fields to include. It must be an array |
||
220 | * whose keys are resource types and values a string |
||
221 | * of the fields to return, separated by a comma |
||
222 | * |
||
223 | * @return $this |
||
224 | */ |
||
225 | public function setFields(array $fields) |
||
236 | |||
237 | /** |
||
238 | * Get requested fields. |
||
239 | * |
||
240 | * @return array |
||
241 | */ |
||
242 | public function getFields(): array |
||
246 | |||
247 | /** |
||
248 | * Get field params for the specified type. |
||
249 | * |
||
250 | * @param string $type |
||
251 | * |
||
252 | * @return ParamBag|null |
||
253 | */ |
||
254 | public function getField($type) |
||
260 | |||
261 | |||
262 | /******************************************* |
||
263 | * RESOURCES |
||
264 | *******************************************/ |
||
265 | |||
266 | /** |
||
267 | * @param callable $transformer |
||
268 | * @param $data |
||
269 | * @return mixed |
||
270 | */ |
||
271 | public function item(callable $transformer, $data) |
||
277 | |||
278 | /** |
||
279 | * @param callable $transformer |
||
280 | * @param $data |
||
281 | * @return mixed |
||
282 | */ |
||
283 | public function collection(callable $transformer, $data) |
||
289 | |||
290 | |||
291 | /** |
||
292 | * Auto-include Parents |
||
293 | * |
||
294 | * Look at the requested includes and automatically include the parents if they |
||
295 | * are not explicitly requested. E.g: [foo, bar.baz] becomes [foo, bar, bar.baz] |
||
296 | * |
||
297 | * @internal |
||
298 | * |
||
299 | * @return void |
||
300 | */ |
||
301 | protected function autoIncludeParents() |
||
319 | |||
320 | /** |
||
321 | * Trim to Acceptable Recursion Level |
||
322 | * |
||
323 | * @internal |
||
324 | * |
||
325 | * @param string $includeName |
||
326 | * |
||
327 | * @return string |
||
328 | */ |
||
329 | protected function trimToAcceptableRecursionLevel($includeName) |
||
333 | } |
||
334 |