|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Dontdrinkandroot\RestBundle\Metadata; |
|
4
|
|
|
|
|
5
|
|
|
use Dontdrinkandroot\RestBundle\Metadata\Annotation\Right; |
|
6
|
|
|
use Metadata\MergeableClassMetadata; |
|
7
|
|
|
use Metadata\MergeableInterface; |
|
8
|
|
|
|
|
9
|
|
|
class ClassMetadata extends MergeableClassMetadata |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* @var bool |
|
13
|
|
|
*/ |
|
14
|
|
|
public $restResource; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @var string |
|
18
|
|
|
*/ |
|
19
|
|
|
public $namePrefix; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var string |
|
23
|
|
|
*/ |
|
24
|
|
|
public $pathPrefix; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var string |
|
28
|
|
|
*/ |
|
29
|
|
|
public $service; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var string |
|
33
|
|
|
*/ |
|
34
|
|
|
public $controller; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var Right|null |
|
38
|
|
|
*/ |
|
39
|
|
|
public $postRight; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @var Right|null |
|
43
|
|
|
*/ |
|
44
|
|
|
public $putRight; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @var Right|null |
|
48
|
|
|
*/ |
|
49
|
|
|
public $deleteRight; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @var Right|null |
|
53
|
|
|
*/ |
|
54
|
|
|
public $listRight; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @var Right|null |
|
58
|
|
|
*/ |
|
59
|
|
|
public $getRight; |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @var string[] |
|
63
|
|
|
*/ |
|
64
|
|
|
public $methods = ['LIST', 'POST', 'GET', 'PUT', 'DELETE']; |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* {@inheritdoc} |
|
68
|
|
|
*/ |
|
69
|
|
|
public function merge(MergeableInterface $object) |
|
70
|
|
|
{ |
|
71
|
|
|
parent::merge($object); |
|
72
|
|
|
/** @var ClassMetadata $object */ |
|
73
|
|
|
$this->restResource = $object->restResource; |
|
74
|
|
|
$this->namePrefix = $object->namePrefix; |
|
75
|
|
|
$this->pathPrefix = $object->pathPrefix; |
|
76
|
|
|
$this->service = $object->service; |
|
77
|
|
|
$this->controller = $object->controller; |
|
78
|
|
|
$this->listRight = $object->listRight; |
|
79
|
|
|
$this->getRight = $object->getRight; |
|
80
|
|
|
$this->postRight = $object->postRight; |
|
81
|
|
|
$this->putRight = $object->putRight; |
|
82
|
|
|
$this->deleteRight = $object->deleteRight; |
|
83
|
|
|
$this->methods = $this->mergeMethods($this->methods, $object->methods); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @param bool $restResource |
|
88
|
|
|
*/ |
|
89
|
10 |
|
public function setRestResource($restResource) |
|
90
|
|
|
{ |
|
91
|
10 |
|
$this->restResource = $restResource; |
|
92
|
10 |
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @return boolean |
|
96
|
|
|
*/ |
|
97
|
2 |
|
public function isRestResource() |
|
98
|
|
|
{ |
|
99
|
2 |
|
return $this->restResource; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @return string |
|
104
|
|
|
*/ |
|
105
|
2 |
|
public function getNamePrefix() |
|
106
|
|
|
{ |
|
107
|
2 |
|
return $this->namePrefix; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* @param string $namePrefix |
|
112
|
|
|
*/ |
|
113
|
|
|
public function setNamePrefix($namePrefix) |
|
114
|
|
|
{ |
|
115
|
|
|
$this->namePrefix = $namePrefix; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* @return string |
|
120
|
|
|
*/ |
|
121
|
2 |
|
public function getPathPrefix() |
|
122
|
|
|
{ |
|
123
|
2 |
|
return $this->pathPrefix; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* @param string $pathPrefix |
|
128
|
|
|
*/ |
|
129
|
|
|
public function setPathPrefix(string $pathPrefix) |
|
130
|
|
|
{ |
|
131
|
|
|
$this->pathPrefix = $pathPrefix; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* @return string |
|
136
|
|
|
*/ |
|
137
|
2 |
|
public function getController() |
|
138
|
|
|
{ |
|
139
|
2 |
|
return $this->controller; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* @param string $controller |
|
144
|
|
|
*/ |
|
145
|
|
|
public function setController($controller) |
|
146
|
|
|
{ |
|
147
|
|
|
$this->controller = $controller; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* @return string |
|
152
|
|
|
*/ |
|
153
|
2 |
|
public function getService() |
|
154
|
|
|
{ |
|
155
|
2 |
|
return $this->service; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* @param string $service |
|
160
|
|
|
*/ |
|
161
|
|
|
public function setService($service) |
|
162
|
|
|
{ |
|
163
|
|
|
$this->service = $service; |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
/** |
|
167
|
|
|
* @return Right|null |
|
168
|
|
|
*/ |
|
169
|
2 |
|
public function getDeleteRight() |
|
170
|
|
|
{ |
|
171
|
2 |
|
return $this->deleteRight; |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
/** |
|
175
|
|
|
* @param Right|null $deleteRight |
|
176
|
|
|
*/ |
|
177
|
|
|
public function setDeleteRight(Right $deleteRight) |
|
178
|
|
|
{ |
|
179
|
|
|
$this->deleteRight = $deleteRight; |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
/** |
|
183
|
|
|
* @return Right|null |
|
184
|
|
|
*/ |
|
185
|
2 |
|
public function getPostRight() |
|
186
|
|
|
{ |
|
187
|
2 |
|
return $this->postRight; |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
/** |
|
191
|
|
|
* @param Right|null $postRight |
|
192
|
|
|
*/ |
|
193
|
|
|
public function setPostRight(Right $postRight) |
|
194
|
|
|
{ |
|
195
|
|
|
$this->postRight = $postRight; |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
/** |
|
199
|
|
|
* @return Right|null |
|
200
|
|
|
*/ |
|
201
|
2 |
|
public function getPutRight() |
|
202
|
|
|
{ |
|
203
|
2 |
|
return $this->putRight; |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
/** |
|
207
|
|
|
* @param Right|null $putRight |
|
208
|
|
|
*/ |
|
209
|
|
|
public function setPutRight(Right $putRight) |
|
210
|
|
|
{ |
|
211
|
|
|
$this->putRight = $putRight; |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
/** |
|
215
|
|
|
* @return Right|null |
|
216
|
|
|
*/ |
|
217
|
2 |
|
public function getListRight() |
|
218
|
|
|
{ |
|
219
|
2 |
|
return $this->listRight; |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
|
|
/** |
|
223
|
|
|
* @param Right|null $listRight |
|
224
|
|
|
*/ |
|
225
|
|
|
public function setListRight(Right $listRight) |
|
226
|
|
|
{ |
|
227
|
|
|
$this->listRight = $listRight; |
|
228
|
|
|
} |
|
229
|
|
|
|
|
230
|
|
|
/** |
|
231
|
|
|
* @return Right|null |
|
232
|
|
|
*/ |
|
233
|
2 |
|
public function getGetRight() |
|
234
|
|
|
{ |
|
235
|
2 |
|
return $this->getRight; |
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
|
/** |
|
239
|
|
|
* @param Right|null $getRight |
|
240
|
|
|
*/ |
|
241
|
|
|
public function setGetRight(Right $getRight) |
|
242
|
|
|
{ |
|
243
|
|
|
$this->getRight = $getRight; |
|
244
|
|
|
} |
|
245
|
|
|
|
|
246
|
|
|
/** |
|
247
|
|
|
* @return string[] |
|
248
|
|
|
*/ |
|
249
|
2 |
|
public function getMethods() |
|
250
|
|
|
{ |
|
251
|
2 |
|
return $this->methods; |
|
252
|
|
|
} |
|
253
|
|
|
|
|
254
|
|
|
/** |
|
255
|
|
|
* @param string[] $methods |
|
256
|
|
|
*/ |
|
257
|
|
|
public function setMethods(array $methods) |
|
258
|
|
|
{ |
|
259
|
|
|
$this->methods = $methods; |
|
260
|
|
|
} |
|
261
|
|
|
|
|
262
|
10 |
|
public function getPropertyMetadata(string $property): ?PropertyMetadata |
|
263
|
|
|
{ |
|
264
|
10 |
|
if (array_key_exists($property, $this->propertyMetadata)) { |
|
265
|
10 |
|
return $this->propertyMetadata[$property]; |
|
266
|
|
|
} |
|
267
|
|
|
|
|
268
|
|
|
return null; |
|
269
|
|
|
} |
|
270
|
|
|
|
|
271
|
|
|
private function mergeMethods($thisMethods, $otherMethods) |
|
272
|
|
|
{ |
|
273
|
|
|
$mergedMethods = []; |
|
274
|
|
|
foreach ($thisMethods as $thisMethod) { |
|
275
|
|
|
if (in_array($thisMethod, $otherMethods)) { |
|
276
|
|
|
$mergedMethods[] = $thisMethod; |
|
277
|
|
|
} |
|
278
|
|
|
} |
|
279
|
|
|
|
|
280
|
|
|
return $mergedMethods; |
|
281
|
|
|
} |
|
282
|
|
|
} |
|
283
|
|
|
|