1 | <?php |
||
20 | class Scope |
||
21 | { |
||
22 | /** |
||
23 | * @var string |
||
24 | */ |
||
25 | protected $scopeIdentifier; |
||
26 | |||
27 | /** |
||
28 | * @var Transform |
||
29 | */ |
||
30 | protected $transform; |
||
31 | |||
32 | /** |
||
33 | * @var array |
||
34 | */ |
||
35 | protected $parentScopes = []; |
||
36 | |||
37 | /** |
||
38 | * Scope constructor. |
||
39 | * @param Transform $transform |
||
40 | * @param string|null $scopeIdentifier |
||
41 | * @param array $parentScopes |
||
42 | */ |
||
43 | public function __construct( |
||
52 | |||
53 | /** |
||
54 | * @return Transform |
||
55 | */ |
||
56 | public function getTransform(): Transform |
||
60 | |||
61 | /** |
||
62 | * @param $key |
||
63 | * @return ParamBag |
||
64 | */ |
||
65 | public function getParams(string $key = null): ParamBag |
||
71 | |||
72 | /** |
||
73 | * Get the current identifier. |
||
74 | * |
||
75 | * @return string|null |
||
76 | */ |
||
77 | public function getScopeIdentifier() |
||
81 | |||
82 | /** |
||
83 | * Get the unique identifier for this scope. |
||
84 | * |
||
85 | * @param string $appendIdentifier |
||
86 | * |
||
87 | * @return string |
||
88 | */ |
||
89 | public function getIdentifier(string $appendIdentifier = null): string |
||
102 | |||
103 | /** |
||
104 | * Getter for parentScopes. |
||
105 | * |
||
106 | * @return array |
||
107 | */ |
||
108 | public function getParentScopes(): array |
||
112 | |||
113 | /** |
||
114 | * Is Requested. |
||
115 | * |
||
116 | * Check if - in relation to the current scope - this specific segment is allowed. |
||
117 | * That means, if a.b.c is requested and the current scope is a.b, then c is allowed. If the current |
||
118 | * scope is a then c is not allowed, even if it is there and potentially transformable. |
||
119 | * |
||
120 | * @internal |
||
121 | * |
||
122 | * @param string $checkScopeSegment |
||
123 | * |
||
124 | * @return bool Returns the new number of elements in the array. |
||
125 | */ |
||
126 | public function isRequested($checkScopeSegment): bool |
||
133 | |||
134 | /** |
||
135 | * Is Excluded. |
||
136 | * |
||
137 | * Check if - in relation to the current scope - this specific segment should |
||
138 | * be excluded. That means, if a.b.c is excluded and the current scope is a.b, |
||
139 | * then c will not be allowed in the transformation whether it appears in |
||
140 | * the list of default or available, requested includes. |
||
141 | * |
||
142 | * @internal |
||
143 | * |
||
144 | * @param string $checkScopeSegment |
||
145 | * |
||
146 | * @return bool |
||
147 | */ |
||
148 | public function isExcluded($checkScopeSegment): bool |
||
155 | |||
156 | /** |
||
157 | * @param TransformerInterface|callable $transformer |
||
158 | * @param mixed $data |
||
159 | * @param array $extra |
||
160 | * @return mixed |
||
161 | */ |
||
162 | public function transform(callable $transformer, $data, array $extra = []) |
||
166 | |||
167 | /** |
||
168 | * @param callable $transformer |
||
169 | * @param string $key |
||
170 | * @return bool |
||
171 | */ |
||
172 | public function includeValue(callable $transformer, string $key): bool |
||
189 | |||
190 | /** |
||
191 | * @param $val |
||
192 | * @param $data |
||
193 | * @param string|null $key |
||
194 | * @param array $extra |
||
195 | * @return mixed |
||
196 | */ |
||
197 | public function parseValue($val, $data, string $key = null, array $extra = []) |
||
214 | |||
215 | /** |
||
216 | * @param $transformer |
||
217 | * @param array $params |
||
218 | * @return array |
||
219 | */ |
||
220 | private function validParams($transformer, array $params): array |
||
265 | |||
266 | /** |
||
267 | * @param string $identifier |
||
268 | * @return Scope |
||
269 | */ |
||
270 | public function childScope(string $identifier): Scope |
||
281 | |||
282 | /** |
||
283 | * Check, if this is the root scope. |
||
284 | * |
||
285 | * @return bool |
||
286 | */ |
||
287 | protected function isRootScope(): bool |
||
291 | |||
292 | /** |
||
293 | * Filter the provided data with the requested filter fields for |
||
294 | * the scope resource |
||
295 | * |
||
296 | * @param array $data |
||
297 | * |
||
298 | * @return array |
||
299 | */ |
||
300 | public function filterFields(array $data): array |
||
315 | |||
316 | /** |
||
317 | * Return the requested filter fields for the scope resource |
||
318 | * |
||
319 | * @internal |
||
320 | * |
||
321 | * @return ParamBag|null |
||
322 | */ |
||
323 | protected function getFilterFields() |
||
329 | |||
330 | /** |
||
331 | * @param string $checkScopeSegment |
||
332 | * @return string |
||
333 | */ |
||
334 | private function scopeString(string $checkScopeSegment): string |
||
345 | } |
||
346 |