1 | <?php namespace Neomerx\JsonApi\Schema; |
||
31 | abstract class BaseSchema implements SchemaInterface |
||
32 | { |
||
33 | /** Links information */ |
||
34 | const LINKS = DocumentInterface::KEYWORD_LINKS; |
||
35 | |||
36 | /** Linked data key. */ |
||
37 | const DATA = DocumentInterface::KEYWORD_DATA; |
||
38 | |||
39 | /** Relationship meta */ |
||
40 | const META = DocumentInterface::KEYWORD_META; |
||
41 | |||
42 | /** If 'self' URL should be shown. */ |
||
43 | const SHOW_SELF = 'showSelf'; |
||
44 | |||
45 | /** If 'related' URL should be shown. */ |
||
46 | const SHOW_RELATED = 'related'; |
||
47 | |||
48 | /** If data should be shown in relationships. */ |
||
49 | const SHOW_DATA = 'showData'; |
||
50 | |||
51 | /** |
||
52 | * @var string |
||
53 | */ |
||
54 | protected $resourceType; |
||
55 | |||
56 | /** |
||
57 | * @var string Must start with '/' e.g. '/sub-url' |
||
58 | */ |
||
59 | protected $selfSubUrl; |
||
60 | |||
61 | /** |
||
62 | * @var bool |
||
63 | */ |
||
64 | protected $isShowAttributesInIncluded = true; |
||
65 | |||
66 | /** |
||
67 | * @var SchemaFactoryInterface |
||
68 | */ |
||
69 | private $factory; |
||
70 | |||
71 | /** |
||
72 | * @param SchemaFactoryInterface $factory |
||
73 | * |
||
74 | * @SuppressWarnings(PHPMD.StaticAccess) |
||
75 | * @SuppressWarnings(PHPMD.ElseExpression) |
||
76 | */ |
||
77 | 72 | public function __construct(SchemaFactoryInterface $factory) |
|
96 | |||
97 | /** |
||
98 | * @inheritdoc |
||
99 | */ |
||
100 | 72 | public function getResourceType(): string |
|
104 | |||
105 | /** |
||
106 | * @inheritdoc |
||
107 | */ |
||
108 | 57 | public function getSelfSubUrl($resource = null): string |
|
112 | |||
113 | /** |
||
114 | * @inheritdoc |
||
115 | */ |
||
116 | 54 | public function getSelfSubLink($resource): LinkInterface |
|
120 | |||
121 | /** |
||
122 | * @inheritdoc |
||
123 | * |
||
124 | * @SuppressWarnings(PHPMD.BooleanArgumentFlag) |
||
125 | */ |
||
126 | 4 | public function getRelationshipSelfLink( |
|
136 | |||
137 | /** |
||
138 | * @inheritdoc |
||
139 | * |
||
140 | * @SuppressWarnings(PHPMD.BooleanArgumentFlag) |
||
141 | */ |
||
142 | 5 | public function getRelationshipRelatedLink( |
|
152 | |||
153 | /** |
||
154 | * @inheritdoc |
||
155 | */ |
||
156 | 62 | public function getPrimaryMeta($resource) |
|
160 | |||
161 | /** |
||
162 | * @inheritdoc |
||
163 | */ |
||
164 | 29 | public function getLinkageMeta($resource) |
|
168 | |||
169 | /** |
||
170 | * @inheritdoc |
||
171 | */ |
||
172 | 19 | public function getInclusionMeta($resource) |
|
176 | |||
177 | /** |
||
178 | * @inheritdoc |
||
179 | */ |
||
180 | 33 | public function getRelationshipsPrimaryMeta($resource) |
|
184 | |||
185 | /** |
||
186 | * @inheritdoc |
||
187 | */ |
||
188 | 16 | public function getRelationshipsInclusionMeta($resource) |
|
192 | |||
193 | /** |
||
194 | * @inheritdoc |
||
195 | */ |
||
196 | 19 | public function isShowAttributesInIncluded(): bool |
|
200 | |||
201 | /** |
||
202 | * Get resource links. |
||
203 | * |
||
204 | * @param object $resource |
||
205 | * @param bool $isPrimary |
||
206 | * @param array $includeRelationships A list of relationships that will be included as full resources. |
||
207 | * |
||
208 | * @return array |
||
209 | */ |
||
210 | 8 | public function getRelationships($resource, bool $isPrimary, array $includeRelationships): ?array |
|
216 | |||
217 | /** |
||
218 | * @inheritdoc |
||
219 | */ |
||
220 | 59 | public function createResourceObject( |
|
227 | |||
228 | /** |
||
229 | * @inheritdoc |
||
230 | */ |
||
231 | 59 | public function getRelationshipObjectIterator($resource, bool $isPrimary, array $includeRelationships): iterable |
|
238 | |||
239 | /** |
||
240 | * @inheritdoc |
||
241 | */ |
||
242 | 34 | public function getIncludePaths(): array |
|
246 | |||
247 | /** |
||
248 | * @inheritdoc |
||
249 | */ |
||
250 | 54 | public function getResourceLinks($resource): array |
|
258 | |||
259 | /** |
||
260 | * @inheritdoc |
||
261 | */ |
||
262 | 16 | public function getIncludedResourceLinks($resource): array |
|
266 | |||
267 | /** |
||
268 | * @param object $resource |
||
269 | * @param string $name |
||
270 | * |
||
271 | * @return string |
||
272 | */ |
||
273 | 4 | protected function getRelationshipSelfUrl($resource, $name) |
|
279 | |||
280 | /** |
||
281 | * @param object $resource |
||
282 | * @param string $name |
||
283 | * |
||
284 | * @return string |
||
285 | */ |
||
286 | 5 | protected function getRelationshipRelatedUrl($resource, $name) |
|
292 | |||
293 | /** |
||
294 | * @param string $subHref |
||
295 | * @param null|mixed $meta |
||
296 | * @param bool $treatAsHref |
||
297 | * |
||
298 | * @return LinkInterface |
||
299 | * |
||
300 | * @SuppressWarnings(PHPMD.BooleanArgumentFlag) |
||
301 | */ |
||
302 | 56 | protected function createLink($subHref, $meta = null, $treatAsHref = false) |
|
306 | |||
307 | /** |
||
308 | * @param object $resource |
||
309 | * @param string $relationshipName |
||
310 | * @param array $description |
||
311 | * @param bool $isShowSelf |
||
312 | * @param bool $isShowRelated |
||
313 | * |
||
314 | * @return array <string,LinkInterface> |
||
315 | */ |
||
316 | 44 | protected function readLinks($resource, $relationshipName, array $description, $isShowSelf, $isShowRelated) |
|
328 | |||
329 | /** |
||
330 | * @param object $resource |
||
331 | * @param string $name |
||
332 | * @param array $desc |
||
333 | * |
||
334 | * @return RelationshipObjectInterface |
||
335 | */ |
||
336 | 44 | protected function createRelationshipObject($resource, $name, array $desc) |
|
347 | } |
||
348 |
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.