1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Mapado\RestClientSdk\Mapping; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class Relation |
7
|
|
|
* @author Julien Deniau <[email protected]> |
8
|
|
|
*/ |
9
|
|
|
class Relation |
10
|
|
|
{ |
11
|
|
|
const MANY_TO_ONE = 'ManyToOne'; |
12
|
|
|
const ONE_TO_MANY = 'OneToMany'; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* key |
16
|
|
|
* |
17
|
|
|
* @var string |
18
|
|
|
* @access private |
19
|
|
|
*/ |
20
|
|
|
private $serializedKey; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* type |
24
|
|
|
* |
25
|
|
|
* @var string |
26
|
|
|
* @access private |
27
|
|
|
*/ |
28
|
|
|
private $type; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* targetEntity |
32
|
|
|
* |
33
|
|
|
* @var string |
34
|
|
|
* @access private |
35
|
|
|
*/ |
36
|
|
|
private $targetEntity; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* __construct |
40
|
|
|
* |
41
|
|
|
* @param string $serializedKey |
42
|
|
|
* @param string $type |
43
|
|
|
* @access public |
44
|
|
|
*/ |
45
|
|
|
public function __construct($serializedKey, $type, $targetEntity) |
46
|
|
|
{ |
47
|
|
|
$this->serializedKey = $serializedKey; |
48
|
|
|
$this->type = $type; |
49
|
|
|
$this->targetEntity = $targetEntity; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Getter for serializedKey |
54
|
|
|
* |
55
|
|
|
* @return string |
56
|
|
|
*/ |
57
|
|
|
public function getSerializedKey() |
58
|
|
|
{ |
59
|
|
|
return $this->serializedKey; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Setter for serializedKey |
64
|
|
|
* |
65
|
|
|
* @param string $serializedKey |
66
|
|
|
* @return Relation |
67
|
|
|
*/ |
68
|
|
|
public function setSerializedKey($serializedKey) |
69
|
|
|
{ |
70
|
|
|
$this->serializedKey = $serializedKey; |
71
|
|
|
|
72
|
|
|
return $this; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Getter for type |
77
|
|
|
* |
78
|
|
|
* return string |
79
|
|
|
*/ |
80
|
|
|
public function getType() |
81
|
|
|
{ |
82
|
|
|
return $this->type; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Setter for type |
87
|
|
|
* |
88
|
|
|
* @param string $type |
89
|
|
|
* @return Relation |
90
|
|
|
*/ |
91
|
|
|
public function setType($type) |
92
|
|
|
{ |
93
|
|
|
$this->type = $type; |
94
|
|
|
return $this; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* isOneToMany |
99
|
|
|
* |
100
|
|
|
* @access public |
101
|
|
|
* @return boolean |
102
|
|
|
*/ |
103
|
|
|
public function isOneToMany() |
104
|
|
|
{ |
105
|
|
|
return $this->getType() == self::ONE_TO_MANY; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* isManyToOne |
110
|
|
|
* |
111
|
|
|
* @access public |
112
|
|
|
* @return boolean |
113
|
|
|
*/ |
114
|
|
|
public function isManyToOne() |
115
|
|
|
{ |
116
|
|
|
return $this->getType() == self::MANY_TO_ONE; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Getter for targetEntity |
121
|
|
|
* |
122
|
|
|
* return string |
123
|
|
|
*/ |
124
|
|
|
public function getTargetEntity() |
125
|
|
|
{ |
126
|
|
|
return $this->targetEntity; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Setter for targetEntity |
131
|
|
|
* |
132
|
|
|
* @param string $targetEntity |
133
|
|
|
* @return Relation |
134
|
|
|
*/ |
135
|
|
|
public function setTargetEntity($targetEntity) |
136
|
|
|
{ |
137
|
|
|
$this->targetEntity = $targetEntity; |
138
|
|
|
return $this; |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|