1 | <?php |
||
25 | class Manager |
||
26 | { |
||
27 | /** |
||
28 | * Array of scope identifiers for resources to include. |
||
29 | * |
||
30 | * @var array |
||
31 | */ |
||
32 | protected $requestedIncludes = []; |
||
33 | |||
34 | /** |
||
35 | * Array of scope identifiers for resources to exclude. |
||
36 | * |
||
37 | * @var array |
||
38 | */ |
||
39 | protected $requestedExcludes = []; |
||
40 | |||
41 | /** |
||
42 | * Array of requested fieldsets. |
||
43 | * |
||
44 | * @var array |
||
45 | */ |
||
46 | protected $requestedFieldsets = []; |
||
47 | |||
48 | /** |
||
49 | * Array containing modifiers as keys and an array value of params. |
||
50 | * |
||
51 | * @var array |
||
52 | */ |
||
53 | protected $includeParams = []; |
||
54 | |||
55 | /** |
||
56 | * The character used to separate modifier parameters. |
||
57 | * |
||
58 | * @var string |
||
59 | */ |
||
60 | protected $paramDelimiter = '|'; |
||
61 | |||
62 | /** |
||
63 | * Upper limit to how many levels of included data are allowed. |
||
64 | * |
||
65 | * @var int |
||
66 | */ |
||
67 | protected $recursionLimit = 10; |
||
68 | |||
69 | /** |
||
70 | * Serializer. |
||
71 | * |
||
72 | * @var SerializerAbstract |
||
73 | */ |
||
74 | protected $serializer; |
||
75 | |||
76 | /** |
||
77 | * Factory used to create new configured scopes. |
||
78 | * |
||
79 | * @var ScopeFactoryInterface |
||
80 | */ |
||
81 | private $scopeFactory; |
||
82 | |||
83 | 86 | public function __construct(ScopeFactoryInterface $scopeFactory = null) |
|
87 | |||
88 | /** |
||
89 | * Create Data. |
||
90 | * |
||
91 | * Main method to kick this all off. Make a resource then pass it over, and use toArray() |
||
92 | * |
||
93 | * @param ResourceInterface $resource |
||
94 | * @param string $scopeIdentifier |
||
95 | * @param Scope $parentScopeInstance |
||
96 | * |
||
97 | * @return Scope |
||
98 | */ |
||
99 | 42 | public function createData(ResourceInterface $resource, $scopeIdentifier = null, Scope $parentScopeInstance = null) |
|
107 | |||
108 | /** |
||
109 | * Get Include Params. |
||
110 | * |
||
111 | * @param string $include |
||
112 | * |
||
113 | * @return \League\Fractal\ParamBag |
||
114 | */ |
||
115 | 32 | public function getIncludeParams($include) |
|
121 | |||
122 | /** |
||
123 | * Get Requested Includes. |
||
124 | * |
||
125 | * @return array |
||
126 | */ |
||
127 | 46 | public function getRequestedIncludes() |
|
131 | |||
132 | /** |
||
133 | * Get Requested Excludes. |
||
134 | * |
||
135 | * @return array |
||
136 | */ |
||
137 | 33 | public function getRequestedExcludes() |
|
141 | |||
142 | /** |
||
143 | * Get Serializer. |
||
144 | * |
||
145 | * @return SerializerAbstract |
||
146 | */ |
||
147 | 60 | public function getSerializer() |
|
155 | |||
156 | /** |
||
157 | * Parse Include String. |
||
158 | * |
||
159 | * @param array|string $includes Array or csv string of resources to include |
||
160 | * |
||
161 | * @return $this |
||
162 | */ |
||
163 | 44 | public function parseIncludes($includes) |
|
228 | |||
229 | /** |
||
230 | * Parse field parameter. |
||
231 | * |
||
232 | 13 | * @param array $fieldsets Array of fields to include. It must be an array whose keys |
|
233 | * are resource types and values an array or a string |
||
234 | 13 | * of the fields to return, separated by a comma |
|
235 | 13 | * |
|
236 | 13 | * @return $this |
|
237 | 13 | */ |
|
238 | 13 | public function parseFieldsets(array $fieldsets) |
|
251 | 1 | ||
252 | /** |
||
253 | 1 | * Get requested fieldsets. |
|
254 | * |
||
255 | * @return array |
||
256 | */ |
||
257 | public function getRequestedFieldsets() |
||
261 | |||
262 | /** |
||
263 | 59 | * Get fieldset params for the specified type. |
|
264 | * |
||
265 | 59 | * @param string $type |
|
266 | 59 | * |
|
267 | 59 | * @return \League\Fractal\ParamBag|null |
|
268 | */ |
||
269 | public function getFieldset($type) |
||
275 | |||
276 | /** |
||
277 | 5 | * Parse Exclude String. |
|
278 | * |
||
279 | 5 | * @param array|string $excludes Array or csv string of resources to exclude |
|
280 | * |
||
281 | 5 | * @return $this |
|
282 | 2 | */ |
|
283 | 2 | public function parseExcludes($excludes) |
|
309 | |||
310 | /** |
||
311 | 1 | * Set Recursion Limit. |
|
312 | * |
||
313 | 1 | * @param int $recursionLimit |
|
314 | * |
||
315 | 1 | * @return $this |
|
316 | */ |
||
317 | public function setRecursionLimit($recursionLimit) |
||
323 | |||
324 | /** |
||
325 | 60 | * Set Serializer |
|
326 | * |
||
327 | 60 | * @param SerializerAbstract $serializer |
|
328 | * |
||
329 | 60 | * @return $this |
|
330 | */ |
||
331 | public function setSerializer(SerializerAbstract $serializer) |
||
337 | |||
338 | /** |
||
339 | * Auto-include Parents |
||
340 | * |
||
341 | * Look at the requested includes and automatically include the parents if they |
||
342 | 42 | * are not explicitly requested. E.g: [foo, bar.baz] becomes [foo, bar, bar.baz] |
|
343 | * |
||
344 | 42 | * @internal |
|
345 | * |
||
346 | 42 | * @return void |
|
347 | 42 | */ |
|
348 | protected function autoIncludeParents() |
||
366 | |||
367 | /** |
||
368 | * Trim to Acceptable Recursion Level |
||
369 | * |
||
370 | * Strip off any requested resources that are too many levels deep, to avoid DiCaprio being chased |
||
371 | * by trains or whatever the hell that movie was about. |
||
372 | * |
||
373 | 44 | * @internal |
|
374 | * |
||
375 | 44 | * @param string $includeName |
|
376 | * |
||
377 | * @return string |
||
378 | */ |
||
379 | protected function trimToAcceptableRecursionLevel($includeName) |
||
383 | } |
||
384 |