1 | <?php |
||
21 | class Scope |
||
22 | { |
||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | protected $scopeIdentifier; |
||
27 | |||
28 | /** |
||
29 | * @var Transform |
||
30 | */ |
||
31 | protected $transform; |
||
32 | |||
33 | /** |
||
34 | * @var array |
||
35 | */ |
||
36 | protected $parentScopes = []; |
||
37 | |||
38 | /** |
||
39 | * Scope constructor. |
||
40 | * @param Transform $transform |
||
41 | * @param string|null $scopeIdentifier |
||
42 | * @param array $parentScopes |
||
43 | */ |
||
44 | public function __construct( |
||
53 | |||
54 | /** |
||
55 | * @return Transform |
||
56 | */ |
||
57 | public function getTransform(): Transform |
||
61 | |||
62 | /** |
||
63 | * @param $key |
||
64 | * @return ParamBag |
||
65 | */ |
||
66 | public function getParams(string $key = null): ParamBag |
||
72 | |||
73 | |||
74 | /** |
||
75 | * Get the unique identifier for this scope. |
||
76 | * |
||
77 | * @param string $appendIdentifier |
||
78 | * |
||
79 | * @return string |
||
80 | */ |
||
81 | public function getIdentifier(string $appendIdentifier = null): string |
||
94 | |||
95 | /** |
||
96 | * Is Requested. |
||
97 | * |
||
98 | * Check if - in relation to the current scope - this specific segment is allowed. |
||
99 | * That means, if a.b.c is requested and the current scope is a.b, then c is allowed. If the current |
||
100 | * scope is a then c is not allowed, even if it is there and potentially transformable. |
||
101 | * |
||
102 | * @param string $checkScopeSegment |
||
103 | * |
||
104 | * @return bool Returns the new number of elements in the array. |
||
105 | */ |
||
106 | public function isRequested($checkScopeSegment): bool |
||
113 | |||
114 | /** |
||
115 | * Is Excluded. |
||
116 | * |
||
117 | * Check if - in relation to the current scope - this specific segment should |
||
118 | * be excluded. That means, if a.b.c is excluded and the current scope is a.b, |
||
119 | * then c will not be allowed in the transformation whether it appears in |
||
120 | * the list of default or available, requested includes. |
||
121 | * |
||
122 | * @param string $checkScopeSegment |
||
123 | * |
||
124 | * @return bool |
||
125 | */ |
||
126 | protected function isExcluded($checkScopeSegment): bool |
||
133 | |||
134 | /** |
||
135 | * @param callable $transformer |
||
136 | * @param string $key |
||
137 | * @return bool |
||
138 | */ |
||
139 | public function includeValue(callable $transformer, string $key): bool |
||
156 | |||
157 | /** |
||
158 | * @param callable $transformer |
||
159 | * @param mixed $data |
||
160 | * @param array $extra |
||
161 | * @return mixed |
||
162 | */ |
||
163 | public function transform(callable $transformer, $data, array $extra = []) |
||
174 | |||
175 | /** |
||
176 | * @param callable $transformer |
||
177 | * @param array $data |
||
178 | * @param string|null $key |
||
179 | * @param array $params |
||
180 | * @return array |
||
181 | */ |
||
182 | public function prepareData(callable $transformer, array $data, string $key = null, array $params = []): array |
||
200 | |||
201 | /** |
||
202 | * @param $value |
||
203 | * @param string|null $key |
||
204 | * @param array $params |
||
205 | * @return mixed |
||
206 | */ |
||
207 | protected function prepareValue($value, string $key = null, array $params = []) |
||
219 | |||
220 | /** |
||
221 | * @param ResourceInterface $transformer |
||
222 | * @param string $key |
||
223 | * @param array $params |
||
224 | * @return mixed |
||
225 | */ |
||
226 | protected function prepareResource( |
||
239 | |||
240 | /** |
||
241 | * @param callable $callable |
||
242 | * @param string|null $key |
||
243 | * @param array $params |
||
244 | * @return mixed |
||
245 | */ |
||
246 | protected function prepareCallable( |
||
275 | |||
276 | /** |
||
277 | * @param \Closure $transformer |
||
278 | * @param string|null $key |
||
279 | * @param array $extra |
||
280 | * @return mixed |
||
281 | */ |
||
282 | protected function prepareClosure( |
||
303 | |||
304 | /** |
||
305 | * @param TransformerInterface $transformer |
||
306 | * @param $data |
||
307 | * @param string|null $key |
||
308 | * @param array $extra |
||
309 | * @return mixed |
||
310 | */ |
||
311 | protected function prepareTransformer( |
||
332 | |||
333 | /** |
||
334 | * @param string $identifier |
||
335 | * @return Scope |
||
336 | */ |
||
337 | public function childScope(string $identifier): Scope |
||
348 | |||
349 | /** |
||
350 | * Check, if this is the root scope. |
||
351 | * |
||
352 | * @return bool |
||
353 | */ |
||
354 | protected function isRootScope(): bool |
||
358 | |||
359 | /** |
||
360 | * Filter the provided data with the requested filter fields for |
||
361 | * the scope resource |
||
362 | * |
||
363 | * @param array $data |
||
364 | * |
||
365 | * @return array |
||
366 | */ |
||
367 | protected function filterFields(array $data): array |
||
382 | |||
383 | /** |
||
384 | * Return the requested filter fields for the scope resource |
||
385 | * |
||
386 | * @internal |
||
387 | * |
||
388 | * @return ParamBag|null |
||
389 | */ |
||
390 | protected function getFilterFields() |
||
396 | |||
397 | /** |
||
398 | * @param string $checkScopeSegment |
||
399 | * @return string |
||
400 | */ |
||
401 | private function scopeString(string $checkScopeSegment): string |
||
412 | } |
||
413 |