1 | <?php |
||
22 | class Scope |
||
23 | { |
||
24 | const IGNORE_EXTRA_PARAMS = ['data', 'scope', 'identifier']; |
||
25 | |||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $scopeIdentifier; |
||
30 | |||
31 | /** |
||
32 | * @var Transform |
||
33 | */ |
||
34 | protected $transform; |
||
35 | |||
36 | /** |
||
37 | * @var array |
||
38 | */ |
||
39 | protected $parentScopes = []; |
||
40 | |||
41 | /** |
||
42 | * Scope constructor. |
||
43 | * @param Transform $transform |
||
44 | * @param string|null $scopeIdentifier |
||
45 | * @param array $parentScopes |
||
46 | */ |
||
47 | public function __construct( |
||
56 | |||
57 | /** |
||
58 | * @return Transform |
||
59 | */ |
||
60 | public function getTransform(): Transform |
||
64 | |||
65 | /** |
||
66 | * @param $key |
||
67 | * @return ParamBag |
||
68 | */ |
||
69 | public function getParams(string $key = null): ParamBag |
||
75 | |||
76 | /** |
||
77 | * Get the current identifier. |
||
78 | * |
||
79 | * @return string|null |
||
80 | */ |
||
81 | public function getScopeIdentifier() |
||
85 | |||
86 | /** |
||
87 | * Get the unique identifier for this scope. |
||
88 | * |
||
89 | * @param string $appendIdentifier |
||
90 | * |
||
91 | * @return string |
||
92 | */ |
||
93 | public function getIdentifier(string $appendIdentifier = null): string |
||
106 | |||
107 | /** |
||
108 | * Getter for parentScopes. |
||
109 | * |
||
110 | * @return array |
||
111 | */ |
||
112 | public function getParentScopes(): array |
||
116 | |||
117 | /** |
||
118 | * Is Requested. |
||
119 | * |
||
120 | * Check if - in relation to the current scope - this specific segment is allowed. |
||
121 | * That means, if a.b.c is requested and the current scope is a.b, then c is allowed. If the current |
||
122 | * scope is a then c is not allowed, even if it is there and potentially transformable. |
||
123 | * |
||
124 | * @internal |
||
125 | * |
||
126 | * @param string $checkScopeSegment |
||
127 | * |
||
128 | * @return bool Returns the new number of elements in the array. |
||
129 | */ |
||
130 | public function isRequested($checkScopeSegment): bool |
||
137 | |||
138 | /** |
||
139 | * Is Excluded. |
||
140 | * |
||
141 | * Check if - in relation to the current scope - this specific segment should |
||
142 | * be excluded. That means, if a.b.c is excluded and the current scope is a.b, |
||
143 | * then c will not be allowed in the transformation whether it appears in |
||
144 | * the list of default or available, requested includes. |
||
145 | * |
||
146 | * @internal |
||
147 | * |
||
148 | * @param string $checkScopeSegment |
||
149 | * |
||
150 | * @return bool |
||
151 | */ |
||
152 | public function isExcluded($checkScopeSegment): bool |
||
159 | |||
160 | /** |
||
161 | * @param TransformerInterface|callable $transformer |
||
162 | * @param mixed $data |
||
163 | * @param array $extra |
||
164 | * @return mixed |
||
165 | */ |
||
166 | public function transform(callable $transformer, $data, array $extra = []) |
||
170 | |||
171 | /** |
||
172 | * @param callable $transformer |
||
173 | * @param string $key |
||
174 | * @return bool |
||
175 | */ |
||
176 | public function includeValue(callable $transformer, string $key): bool |
||
193 | |||
194 | /** |
||
195 | * @param $val |
||
196 | * @param $data |
||
197 | * @param string|null $key |
||
198 | * @param array $extra |
||
199 | * @return mixed |
||
200 | */ |
||
201 | public function parseValue($val, $data, string $key = null, array $extra = []) |
||
218 | |||
219 | /** |
||
220 | * @param $transformer |
||
221 | * @param array $params |
||
222 | * @return array |
||
223 | */ |
||
224 | private function validParams($transformer, array $params): array |
||
246 | |||
247 | /** |
||
248 | * @param ReflectionParameter $param |
||
249 | * @param array $params |
||
250 | * @param array $args |
||
251 | * @param array $missing |
||
252 | */ |
||
253 | private function validParam( |
||
271 | |||
272 | /** |
||
273 | * @param ReflectionParameter $param |
||
274 | * @param $value |
||
275 | * @return mixed |
||
276 | */ |
||
277 | private function argType( |
||
302 | |||
303 | /** |
||
304 | * @param string $identifier |
||
305 | * @return Scope |
||
306 | */ |
||
307 | public function childScope(string $identifier): Scope |
||
318 | |||
319 | /** |
||
320 | * Check, if this is the root scope. |
||
321 | * |
||
322 | * @return bool |
||
323 | */ |
||
324 | protected function isRootScope(): bool |
||
328 | |||
329 | /** |
||
330 | * Filter the provided data with the requested filter fields for |
||
331 | * the scope resource |
||
332 | * |
||
333 | * @param array $data |
||
334 | * |
||
335 | * @return array |
||
336 | */ |
||
337 | public function filterFields(array $data): array |
||
352 | |||
353 | /** |
||
354 | * Return the requested filter fields for the scope resource |
||
355 | * |
||
356 | * @internal |
||
357 | * |
||
358 | * @return ParamBag|null |
||
359 | */ |
||
360 | protected function getFilterFields() |
||
366 | |||
367 | /** |
||
368 | * @param string $checkScopeSegment |
||
369 | * @return string |
||
370 | */ |
||
371 | private function scopeString(string $checkScopeSegment): string |
||
382 | } |
||
383 |