1 | <?php |
||
15 | class SerializedEntity implements EntityDocument { |
||
16 | |||
17 | /** |
||
18 | * @var EntityId|null |
||
19 | */ |
||
20 | private $entityId; |
||
21 | |||
22 | /** |
||
23 | * @var array |
||
24 | */ |
||
25 | private $serialization; |
||
26 | |||
27 | /** |
||
28 | * @param EntityId|null $entityId |
||
29 | * @param array $serialization |
||
30 | */ |
||
31 | 8 | public function __construct( EntityId $entityId = null, array $serialization ) { |
|
32 | 8 | if( !array_key_exists( 'type', $serialization ) ) { |
|
33 | 1 | throw new InvalidArgumentException( 'The entity serialization does not have a type.' ); |
|
34 | } |
||
35 | |||
36 | 7 | $this->entityId = $entityId; |
|
37 | 7 | $this->serialization = $serialization; |
|
38 | 7 | } |
|
39 | |||
40 | /** |
||
41 | * @see EntityDocument::getId |
||
42 | */ |
||
43 | 3 | public function getId() { |
|
46 | |||
47 | /** |
||
48 | * @see EntityDocument::setId |
||
49 | */ |
||
50 | public function setId( $id ) { |
||
53 | |||
54 | /** |
||
55 | * @see EntityDocument::getType |
||
56 | */ |
||
57 | 2 | public function getType() { |
|
60 | |||
61 | /** |
||
62 | * @see EntityDocument::isEmpty |
||
63 | */ |
||
64 | 2 | public function isEmpty() { |
|
65 | 2 | foreach( array_keys( $this->serialization ) as $key ) { |
|
66 | 2 | if( !in_array( $key, [ 'type', 'id' ] ) ) { |
|
67 | 1 | return false; |
|
68 | } |
||
69 | 2 | } |
|
70 | |||
71 | 1 | return true; |
|
72 | } |
||
73 | |||
74 | /** |
||
75 | * @return array |
||
76 | */ |
||
77 | 2 | public function getSerialization() { |
|
80 | |||
81 | /** |
||
82 | * @see Comparable::equals |
||
83 | */ |
||
84 | public function equals( $target ) { |
||
87 | |||
88 | /** |
||
89 | * @see EntityDocument::copy |
||
90 | */ |
||
91 | public function copy() { |
||
94 | } |
||
95 |