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
|
6 |
|
public function merge(MergeableInterface $object) |
70
|
|
|
{ |
71
|
6 |
|
if (!$object instanceof MergeableClassMetadata) { |
72
|
|
|
throw new \InvalidArgumentException('$object must be an instance of MergeableClassMetadata.'); |
73
|
|
|
} |
74
|
|
|
|
75
|
6 |
|
$this->name = $object->name; |
76
|
6 |
|
$this->reflection = $object->reflection; |
77
|
6 |
|
$this->methodMetadata = array_merge($this->methodMetadata, $object->methodMetadata); |
78
|
6 |
|
$this->propertyMetadata = $this->mergePropertyMetadata($object); |
79
|
6 |
|
$this->fileResources = array_merge($this->fileResources, $object->fileResources); |
80
|
|
|
|
81
|
6 |
|
if ($object->createdAt < $this->createdAt) { |
82
|
|
|
$this->createdAt = $object->createdAt; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** @var ClassMetadata $object */ |
86
|
6 |
|
$this->restResource = $object->restResource; |
87
|
6 |
|
$this->namePrefix = $object->namePrefix; |
88
|
6 |
|
$this->pathPrefix = $object->pathPrefix; |
89
|
6 |
|
$this->service = $object->service; |
90
|
6 |
|
$this->controller = $object->controller; |
91
|
6 |
|
$this->listRight = $object->listRight; |
92
|
6 |
|
$this->getRight = $object->getRight; |
93
|
6 |
|
$this->postRight = $object->postRight; |
94
|
6 |
|
$this->putRight = $object->putRight; |
95
|
6 |
|
$this->deleteRight = $object->deleteRight; |
96
|
|
|
|
97
|
6 |
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @param bool $restResource |
101
|
|
|
*/ |
102
|
38 |
|
public function setRestResource($restResource) |
103
|
|
|
{ |
104
|
38 |
|
$this->restResource = $restResource; |
105
|
38 |
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @return boolean |
109
|
|
|
*/ |
110
|
4 |
|
public function isRestResource() |
111
|
|
|
{ |
112
|
4 |
|
return $this->restResource; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @return string |
117
|
|
|
*/ |
118
|
4 |
|
public function getNamePrefix() |
119
|
|
|
{ |
120
|
4 |
|
return $this->namePrefix; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @param string $namePrefix |
125
|
|
|
*/ |
126
|
|
|
public function setNamePrefix($namePrefix) |
127
|
|
|
{ |
128
|
|
|
$this->namePrefix = $namePrefix; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @return string |
133
|
|
|
*/ |
134
|
4 |
|
public function getPathPrefix() |
135
|
|
|
{ |
136
|
4 |
|
return $this->pathPrefix; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @param string $pathPrefix |
141
|
|
|
*/ |
142
|
24 |
|
public function setPathPrefix(string $pathPrefix) |
143
|
|
|
{ |
144
|
24 |
|
$this->pathPrefix = $pathPrefix; |
145
|
24 |
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @return string |
149
|
|
|
*/ |
150
|
4 |
|
public function getController() |
151
|
|
|
{ |
152
|
4 |
|
return $this->controller; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @param string $controller |
157
|
|
|
*/ |
158
|
|
|
public function setController($controller) |
159
|
|
|
{ |
160
|
|
|
$this->controller = $controller; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @return string |
165
|
|
|
*/ |
166
|
4 |
|
public function getService() |
167
|
|
|
{ |
168
|
4 |
|
return $this->service; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @param string $service |
173
|
|
|
*/ |
174
|
4 |
|
public function setService($service) |
175
|
|
|
{ |
176
|
4 |
|
$this->service = $service; |
177
|
4 |
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @return Right|null |
181
|
|
|
*/ |
182
|
2 |
|
public function getDeleteRight() |
183
|
|
|
{ |
184
|
2 |
|
return $this->deleteRight; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* @param Right|null $deleteRight |
189
|
|
|
*/ |
190
|
|
|
public function setDeleteRight(Right $deleteRight) |
191
|
|
|
{ |
192
|
|
|
$this->deleteRight = $deleteRight; |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* @return Right|null |
197
|
|
|
*/ |
198
|
2 |
|
public function getPostRight() |
199
|
|
|
{ |
200
|
2 |
|
return $this->postRight; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* @param Right|null $postRight |
205
|
|
|
*/ |
206
|
|
|
public function setPostRight(Right $postRight) |
207
|
|
|
{ |
208
|
|
|
$this->postRight = $postRight; |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* @return Right|null |
213
|
|
|
*/ |
214
|
6 |
|
public function getPutRight() |
215
|
|
|
{ |
216
|
6 |
|
return $this->putRight; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* @param Right|null $putRight |
221
|
|
|
*/ |
222
|
24 |
|
public function setPutRight(Right $putRight) |
223
|
|
|
{ |
224
|
24 |
|
$this->putRight = $putRight; |
225
|
24 |
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* @return Right|null |
229
|
|
|
*/ |
230
|
8 |
|
public function getListRight() |
231
|
|
|
{ |
232
|
8 |
|
return $this->listRight; |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* @param Right|null $listRight |
237
|
|
|
*/ |
238
|
24 |
|
public function setListRight(Right $listRight) |
239
|
|
|
{ |
240
|
24 |
|
$this->listRight = $listRight; |
241
|
24 |
|
} |
242
|
|
|
|
243
|
|
|
/** |
244
|
|
|
* @return Right|null |
245
|
|
|
*/ |
246
|
10 |
|
public function getGetRight() |
247
|
|
|
{ |
248
|
10 |
|
return $this->getRight; |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* @param Right|null $getRight |
253
|
|
|
*/ |
254
|
24 |
|
public function setGetRight(Right $getRight) |
255
|
|
|
{ |
256
|
24 |
|
$this->getRight = $getRight; |
257
|
24 |
|
} |
258
|
|
|
|
259
|
|
|
/** |
260
|
|
|
* @return string[] |
261
|
|
|
*/ |
262
|
4 |
|
public function getMethods() |
263
|
|
|
{ |
264
|
4 |
|
return $this->methods; |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
/** |
268
|
|
|
* @param string[] $methods |
269
|
|
|
*/ |
270
|
|
|
public function setMethods(array $methods) |
271
|
|
|
{ |
272
|
|
|
$this->methods = $methods; |
273
|
|
|
} |
274
|
|
|
|
275
|
38 |
|
public function getPropertyMetadata(string $property): ?PropertyMetadata |
276
|
|
|
{ |
277
|
38 |
|
if (array_key_exists($property, $this->propertyMetadata)) { |
278
|
38 |
|
return $this->propertyMetadata[$property]; |
279
|
|
|
} |
280
|
|
|
|
281
|
28 |
|
return null; |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
/** |
285
|
|
|
* @param MergeableInterface $object |
286
|
|
|
* |
287
|
|
|
* @return array |
288
|
|
|
*/ |
289
|
6 |
|
protected function mergePropertyMetadata(MergeableInterface $object): array |
290
|
|
|
{ |
291
|
|
|
/** @var ClassMetadata $object */ |
292
|
|
|
/** @var PropertyMetadata[] $mergedMetadata */ |
293
|
6 |
|
$mergedMetadata = $this->propertyMetadata; |
294
|
|
|
|
295
|
6 |
|
foreach ($object->propertyMetadata as $otherMetadata) { |
|
|
|
|
296
|
|
|
/** @var PropertyMetadata $otherMetadata */ |
297
|
6 |
|
if (array_key_exists($otherMetadata->name, $mergedMetadata)) { |
298
|
4 |
|
$mergedMetadata[$otherMetadata->name] = $mergedMetadata[$otherMetadata->name]->merge($otherMetadata); |
299
|
|
|
} else { |
300
|
6 |
|
$mergedMetadata[$otherMetadata->name] = $otherMetadata; |
301
|
|
|
} |
302
|
|
|
} |
303
|
|
|
|
304
|
6 |
|
return $mergedMetadata; |
305
|
|
|
} |
306
|
|
|
} |
307
|
|
|
|
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: