1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Mapado\RestClientSdk\Mapping; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class ClassMetadata |
7
|
|
|
* @author Julien Deniau <[email protected]> |
8
|
|
|
*/ |
9
|
|
|
class ClassMetadata |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* Model name (entity class with full namespace, ie: "Foo\Entity\Article"). |
13
|
|
|
* |
14
|
|
|
* @var string |
15
|
|
|
* @access private |
16
|
|
|
*/ |
17
|
|
|
private $modelName; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Model short name (entity class without namespace, ie: "Article"). |
21
|
|
|
* |
22
|
|
|
* @var string |
23
|
|
|
* @access private |
24
|
|
|
*/ |
25
|
|
|
private $modelShortName; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Model key, used as path prefix for API calls. |
29
|
|
|
* |
30
|
|
|
* @var string |
31
|
|
|
* @access private |
32
|
|
|
*/ |
33
|
|
|
private $key; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Repository name (repository class with full namespace, ie: "Foo\Repository\ArticleRepository"). |
37
|
|
|
* |
38
|
|
|
* @var string |
39
|
|
|
* @access private |
40
|
|
|
*/ |
41
|
|
|
private $repositoryName; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* attributeList |
45
|
|
|
* |
46
|
|
|
* @var Attribute[] |
47
|
|
|
* @access private |
48
|
|
|
*/ |
49
|
|
|
private $attributeList; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* relationList |
53
|
|
|
* |
54
|
|
|
* @var Relation[] |
55
|
|
|
* @access private |
56
|
|
|
*/ |
57
|
|
|
private $relationList; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* identifierAttribute |
61
|
|
|
* |
62
|
|
|
* @var Attribute |
63
|
|
|
* @access private |
64
|
|
|
*/ |
65
|
|
|
private $identifierAttribute; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Constructor. |
69
|
|
|
* |
70
|
|
|
* @param string $key |
71
|
|
|
* @param string $modelName |
72
|
|
|
* @param string $repositoryName |
73
|
|
|
* @access public |
74
|
|
|
*/ |
75
|
|
|
public function __construct($key, $modelName, $repositoryName) |
76
|
|
|
{ |
77
|
|
|
$this->key = $key; |
78
|
|
|
$this->setModelName($modelName); |
79
|
|
|
$this->repositoryName = $repositoryName; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Getter for modelName |
84
|
|
|
* |
85
|
|
|
* @return string |
86
|
|
|
*/ |
87
|
|
|
public function getModelName() |
88
|
|
|
{ |
89
|
|
|
return $this->modelName; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Getter for modelShortName |
94
|
|
|
* |
95
|
|
|
* @return string |
96
|
|
|
*/ |
97
|
|
|
public function getModelShortName() |
98
|
|
|
{ |
99
|
|
|
return $this->modelShortName; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Setter for modelName |
104
|
|
|
* |
105
|
|
|
* @param string $modelName |
106
|
|
|
* @return ClassMetadata |
107
|
|
|
*/ |
108
|
|
|
public function setModelName($modelName) |
109
|
|
|
{ |
110
|
|
|
$this->modelName = $modelName; |
111
|
|
|
$classParts = explode('\\', $modelName); |
112
|
|
|
$this->modelShortName = array_pop($classParts); |
113
|
|
|
return $this; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Getter for key |
118
|
|
|
* |
119
|
|
|
* @return string |
120
|
|
|
*/ |
121
|
|
|
public function getKey() |
122
|
|
|
{ |
123
|
|
|
return $this->key; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Setter for key |
128
|
|
|
* |
129
|
|
|
* @param string $key |
130
|
|
|
* @return ClassMetadata |
131
|
|
|
*/ |
132
|
|
|
public function setKey($key) |
133
|
|
|
{ |
134
|
|
|
$this->key = $key; |
135
|
|
|
|
136
|
|
|
return $this; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* getAttribute |
141
|
|
|
* |
142
|
|
|
* @param string $name |
143
|
|
|
* @access public |
144
|
|
|
* @return Attribute |
145
|
|
|
*/ |
146
|
|
|
public function getAttribute($name) |
147
|
|
|
{ |
148
|
|
|
return isset($this->attributeList[$name]) ? $this->attributeList[$name] : null; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* getIdentifierAttribute |
153
|
|
|
* |
154
|
|
|
* @access public |
155
|
|
|
* @return Attribute |
156
|
|
|
*/ |
157
|
|
|
public function getIdentifierAttribute() |
158
|
|
|
{ |
159
|
|
|
return $this->identifierAttribute; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* Getter for attributeList |
164
|
|
|
* |
165
|
|
|
* @return Attribute[] |
166
|
|
|
*/ |
167
|
|
|
public function getAttributeList() |
168
|
|
|
{ |
169
|
|
|
return $this->attributeList; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* Setter for attributeList |
174
|
|
|
* |
175
|
|
|
* @param Attribute[] $attributeList |
176
|
|
|
* @return ClassMetadata |
177
|
|
|
*/ |
178
|
|
|
public function setAttributeList($attributeList) |
179
|
|
|
{ |
180
|
|
|
$this->attributeList = []; |
181
|
|
|
foreach ($attributeList as $attribute) { |
182
|
|
|
$this->attributeList[$attribute->getSerializedKey()] = $attribute; |
183
|
|
|
|
184
|
|
|
if ($attribute->isIdentifier()) { |
185
|
|
|
$this->identifierAttribute = $attribute; |
186
|
|
|
} |
187
|
|
|
} |
188
|
|
|
return $this; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* Getter for relationList |
193
|
|
|
* |
194
|
|
|
* @return Relation[] |
195
|
|
|
*/ |
196
|
|
|
public function getRelationList() |
197
|
|
|
{ |
198
|
|
|
return $this->relationList; |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* Setter for relationList |
203
|
|
|
* |
204
|
|
|
* @param Relation[] $relationList |
205
|
|
|
* @return ClassMetadata |
206
|
|
|
*/ |
207
|
|
|
public function setRelationList($relationList) |
208
|
|
|
{ |
209
|
|
|
$this->relationList = $relationList; |
210
|
|
|
return $this; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* getRelation |
215
|
|
|
* |
216
|
|
|
* @param string $key |
217
|
|
|
* @access public |
218
|
|
|
* @return Relation|null |
219
|
|
|
*/ |
220
|
|
|
public function getRelation($key) |
221
|
|
|
{ |
222
|
|
|
if (!empty($this->relationList)) { |
223
|
|
|
foreach ($this->relationList as $relation) { |
224
|
|
|
if ($relation->getSerializedKey() == $key) { |
225
|
|
|
return $relation; |
226
|
|
|
} |
227
|
|
|
} |
228
|
|
|
} |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* Getter for repositoryName |
233
|
|
|
* |
234
|
|
|
* @return string |
235
|
|
|
*/ |
236
|
|
|
public function getRepositoryName() |
237
|
|
|
{ |
238
|
|
|
return $this->repositoryName; |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
/** |
242
|
|
|
* Setter for repositoryName |
243
|
|
|
* |
244
|
|
|
* @param string $repositoryName |
245
|
|
|
* @return ClassMetadata |
246
|
|
|
*/ |
247
|
|
|
public function setRepositoryName($repositoryName) |
248
|
|
|
{ |
249
|
|
|
$this->repositoryName = $repositoryName; |
250
|
|
|
return $this; |
251
|
|
|
} |
252
|
|
|
} |
253
|
|
|
|