|
8 | 8 | * |
9 | 9 | * @deprecated |
10 | 10 | * @see \FreeElephants\JsonApi\DTO\AbstractResourceObject |
11 | | - * @property AbstractAttributes $attributes |
12 | | - * @property AbstractRelationships $relationships |
13 | 11 | */ |
14 | | -class AbstractResourceObject |
| 12 | +class AbstractResourceObject extends \FreeElephants\JsonApi\DTO\AbstractResourceObject |
15 | 13 | { |
16 | | - public string $id; |
17 | | - public string $type; |
18 | | - |
19 | | - public function __construct(array $data) |
20 | | - { |
21 | | - $this->id = $data['id']; |
22 | | - $this->type = $data['type']; |
23 | | - |
24 | | - $concreteClass = new \ReflectionClass($this); |
25 | | - |
26 | | - if (property_exists($this, 'attributes')) { |
27 | | - $attributesProperty = $concreteClass->getProperty('attributes'); |
28 | | - $attributesClass = $attributesProperty->getType()->getName(); |
29 | | - $this->attributes = new $attributesClass($data['attributes']); |
30 | | - } |
31 | | - |
32 | | - if (property_exists($this, 'relationships')) { |
33 | | - $relationshipsData = $data['relationships']; |
34 | | - $concreteClass = new \ReflectionClass($this); |
35 | | - $relationshipsProperty = $concreteClass->getProperty('relationships'); |
36 | | - $reflectionType = $relationshipsProperty->getType(); |
37 | | - |
38 | | - // handle php 8 union types |
39 | | - if ($reflectionType instanceof \ReflectionUnionType) { |
40 | | - $relationshipsClass = (new SuitableRelationshipsTypeDetector())->detect($reflectionType, $relationshipsData); |
41 | | - } else { |
42 | | - $relationshipsClass = $reflectionType->getName(); |
43 | | - } |
44 | | - |
45 | | - $relationshipsDto = new $relationshipsClass($relationshipsData); |
46 | | - $this->relationships = $relationshipsDto; |
47 | | - } |
48 | | - } |
49 | 14 | } |
0 commit comments