|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Hateoas\Configuration\Metadata; |
|
4
|
|
|
|
|
5
|
|
|
use Hateoas\Configuration\Relation; |
|
6
|
|
|
use Hateoas\Configuration\RelationProvider; |
|
7
|
|
|
use Metadata\MergeableClassMetadata; |
|
8
|
|
|
use Metadata\MergeableInterface; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* @author Adrien Brault <[email protected]> |
|
12
|
|
|
*/ |
|
13
|
|
|
class ClassMetadata extends MergeableClassMetadata implements ClassMetadataInterface |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @var Relation[] |
|
17
|
|
|
*/ |
|
18
|
|
|
private $relations = array(); |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var RelationProvider[] |
|
22
|
|
|
*/ |
|
23
|
|
|
private $relationProviders = array(); |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* {@inheritDoc} |
|
27
|
|
|
*/ |
|
28
|
|
|
public function getName() |
|
29
|
|
|
{ |
|
30
|
|
|
return $this->name; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* {@inheritDoc} |
|
35
|
|
|
*/ |
|
36
|
|
|
public function getRelations() |
|
37
|
|
|
{ |
|
38
|
|
|
return $this->relations; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* {@inheritDoc} |
|
43
|
|
|
*/ |
|
44
|
|
|
public function getRelationProviders() |
|
45
|
|
|
{ |
|
46
|
|
|
return $this->relationProviders; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* {@inheritDoc} |
|
51
|
|
|
*/ |
|
52
|
|
|
public function addRelation(Relation $relation) |
|
53
|
|
|
{ |
|
54
|
|
|
$this->relations[] = $relation; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* {@inheritDoc} |
|
59
|
|
|
*/ |
|
60
|
|
|
public function addRelationProvider(RelationProvider $relationProvider) |
|
61
|
|
|
{ |
|
62
|
|
|
$this->relationProviders[] = $relationProvider; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* {@inheritDoc} |
|
67
|
|
|
*/ |
|
68
|
|
|
public function merge(MergeableInterface $object) |
|
69
|
|
|
{ |
|
70
|
|
|
if (!$object instanceof self) { |
|
71
|
|
|
throw new \InvalidArgumentException(sprintf('Object must be an instance of %s.', __CLASS__)); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
parent::merge($object); |
|
75
|
|
|
|
|
76
|
|
|
$this->relations = array_merge($this->relations, $object->getRelations()); |
|
77
|
|
|
$this->relationProviders = array_merge($this->relationProviders, $object->getRelationProviders()); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* {@inheritDoc} |
|
82
|
|
|
*/ |
|
83
|
|
|
public function serialize() |
|
84
|
|
|
{ |
|
85
|
|
|
return serialize(array( |
|
86
|
|
|
$this->relations, |
|
87
|
|
|
$this->relationProviders, |
|
88
|
|
|
parent::serialize(), |
|
89
|
|
|
)); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* {@inheritDoc} |
|
94
|
|
|
*/ |
|
95
|
|
|
public function unserialize($str) |
|
96
|
|
|
{ |
|
97
|
|
|
list( |
|
98
|
|
|
$this->relations, |
|
99
|
|
|
$this->relationProviders, |
|
100
|
|
|
$parentStr |
|
101
|
|
|
) = unserialize($str); |
|
102
|
|
|
|
|
103
|
|
|
parent::unserialize($parentStr); |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|