1 | <?php |
||
20 | class Scope |
||
21 | { |
||
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(Transform $transform, string $scopeIdentifier = null, array $parentScopes = []) |
||
50 | |||
51 | /** |
||
52 | * @return Transform |
||
53 | */ |
||
54 | public function getTransform(): Transform |
||
58 | |||
59 | /** |
||
60 | * @param $key |
||
61 | * @return ParamBag |
||
62 | */ |
||
63 | public function getParams(string $key = null): ParamBag |
||
69 | |||
70 | /** |
||
71 | * Get the current identifier. |
||
72 | * |
||
73 | * @return string|null |
||
74 | */ |
||
75 | public function getScopeIdentifier() |
||
79 | |||
80 | /** |
||
81 | * Get the unique identifier for this scope. |
||
82 | * |
||
83 | * @param string $appendIdentifier |
||
84 | * |
||
85 | * @return string |
||
86 | */ |
||
87 | public function getIdentifier(string $appendIdentifier = null): string |
||
100 | |||
101 | /** |
||
102 | * Getter for parentScopes. |
||
103 | * |
||
104 | * @return array |
||
105 | */ |
||
106 | public function getParentScopes(): array |
||
110 | |||
111 | /** |
||
112 | * Is Requested. |
||
113 | * |
||
114 | * Check if - in relation to the current scope - this specific segment is allowed. |
||
115 | * That means, if a.b.c is requested and the current scope is a.b, then c is allowed. If the current |
||
116 | * scope is a then c is not allowed, even if it is there and potentially transformable. |
||
117 | * |
||
118 | * @internal |
||
119 | * |
||
120 | * @param string $checkScopeSegment |
||
121 | * |
||
122 | * @return bool Returns the new number of elements in the array. |
||
123 | */ |
||
124 | public function isRequested($checkScopeSegment): bool |
||
131 | |||
132 | /** |
||
133 | * Is Excluded. |
||
134 | * |
||
135 | * Check if - in relation to the current scope - this specific segment should |
||
136 | * be excluded. That means, if a.b.c is excluded and the current scope is a.b, |
||
137 | * then c will not be allowed in the transformation whether it appears in |
||
138 | * the list of default or available, requested includes. |
||
139 | * |
||
140 | * @internal |
||
141 | * |
||
142 | * @param string $checkScopeSegment |
||
143 | * |
||
144 | * @return bool |
||
145 | */ |
||
146 | public function isExcluded($checkScopeSegment): bool |
||
153 | |||
154 | /** |
||
155 | * @param TransformerInterface|callable $transformer |
||
156 | * @param mixed $data |
||
157 | * @return array |
||
158 | */ |
||
159 | public function transform(callable $transformer, $data): array |
||
193 | |||
194 | /** |
||
195 | * @param callable $transformer |
||
196 | * @param string $key |
||
197 | * @return bool |
||
198 | */ |
||
199 | protected function includeValue(callable $transformer, string $key): bool |
||
215 | |||
216 | /** |
||
217 | * @param $val |
||
218 | * @param $data |
||
219 | * @param string|null $key |
||
220 | * @return array|string|null |
||
221 | */ |
||
222 | protected function parseValue($val, $data, string $key = null) |
||
235 | |||
236 | /** |
||
237 | * @param string $identifier |
||
238 | * @return Scope |
||
239 | */ |
||
240 | public function childScope(string $identifier): Scope |
||
253 | |||
254 | /** |
||
255 | * Check, if this is the root scope. |
||
256 | * |
||
257 | * @return bool |
||
258 | */ |
||
259 | protected function isRootScope(): bool |
||
263 | |||
264 | /** |
||
265 | * Filter the provided data with the requested filter fields for |
||
266 | * the scope resource |
||
267 | * |
||
268 | * @internal |
||
269 | * |
||
270 | * @param array $data |
||
271 | * |
||
272 | * @return array |
||
273 | */ |
||
274 | protected function filterFields(array $data): array |
||
291 | |||
292 | /** |
||
293 | * Return the requested filter fields for the scope resource |
||
294 | * |
||
295 | * @internal |
||
296 | * |
||
297 | * @return ParamBag|null |
||
298 | */ |
||
299 | protected function getFilterFields() |
||
305 | |||
306 | /** |
||
307 | * @param string $checkScopeSegment |
||
308 | * @return string |
||
309 | */ |
||
310 | private function _scopeString(string $checkScopeSegment): string |
||
323 | |||
324 | } |
||
325 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.