1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Ivory Serializer package. |
5
|
|
|
* |
6
|
|
|
* (c) Eric GELOEN <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please read the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Ivory\Serializer\Mapping; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @author GeLo <[email protected]> |
16
|
|
|
*/ |
17
|
|
|
class PropertyMetadata implements PropertyMetadataInterface |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
private $name; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
private $alias; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var TypeMetadataInterface|null |
31
|
|
|
*/ |
32
|
|
|
private $type; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var string|null |
36
|
|
|
*/ |
37
|
|
|
private $accessor; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var string|null |
41
|
|
|
*/ |
42
|
|
|
private $mutator; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var string|null |
46
|
|
|
*/ |
47
|
|
|
private $since; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var string|null |
51
|
|
|
*/ |
52
|
|
|
private $until; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @var int|null |
56
|
|
|
*/ |
57
|
|
|
private $maxDepth; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @var string[] |
61
|
|
|
*/ |
62
|
|
|
private $groups = []; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param string $name |
66
|
|
|
*/ |
67
|
777 |
|
public function __construct($name) |
68
|
|
|
{ |
69
|
777 |
|
$this->setName($name); |
70
|
777 |
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* {@inheritdoc} |
74
|
|
|
*/ |
75
|
648 |
|
public function getName() |
76
|
|
|
{ |
77
|
648 |
|
return $this->name; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* {@inheritdoc} |
82
|
|
|
*/ |
83
|
777 |
|
public function setName($name) |
84
|
|
|
{ |
85
|
777 |
|
$this->name = $name; |
86
|
777 |
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* {@inheritdoc} |
90
|
|
|
*/ |
91
|
612 |
|
public function hasAlias() |
92
|
|
|
{ |
93
|
612 |
|
return $this->alias !== null; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* {@inheritdoc} |
98
|
|
|
*/ |
99
|
261 |
|
public function getAlias() |
100
|
|
|
{ |
101
|
261 |
|
return $this->alias; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* {@inheritdoc} |
106
|
|
|
*/ |
107
|
90 |
|
public function setAlias($alias) |
108
|
|
|
{ |
109
|
90 |
|
$this->alias = $alias; |
110
|
90 |
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* {@inheritdoc} |
114
|
|
|
*/ |
115
|
189 |
|
public function hasType() |
116
|
|
|
{ |
117
|
189 |
|
return $this->type !== null; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* {@inheritdoc} |
122
|
|
|
*/ |
123
|
480 |
|
public function getType() |
124
|
|
|
{ |
125
|
480 |
|
return $this->type; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* {@inheritdoc} |
130
|
|
|
*/ |
131
|
264 |
|
public function setType(TypeMetadataInterface $type = null) |
132
|
|
|
{ |
133
|
264 |
|
$this->type = $type; |
134
|
264 |
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* {@inheritdoc} |
138
|
|
|
*/ |
139
|
441 |
|
public function hasAccessor() |
140
|
|
|
{ |
141
|
441 |
|
return $this->accessor !== null; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* {@inheritdoc} |
146
|
|
|
*/ |
147
|
198 |
|
public function getAccessor() |
148
|
|
|
{ |
149
|
198 |
|
return $this->accessor; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* {@inheritdoc} |
154
|
|
|
*/ |
155
|
36 |
|
public function setAccessor($accessor) |
156
|
|
|
{ |
157
|
36 |
|
$this->accessor = $accessor; |
158
|
36 |
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* {@inheritdoc} |
162
|
|
|
*/ |
163
|
315 |
|
public function hasMutator() |
164
|
|
|
{ |
165
|
315 |
|
return $this->mutator !== null; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* {@inheritdoc} |
170
|
|
|
*/ |
171
|
198 |
|
public function getMutator() |
172
|
|
|
{ |
173
|
198 |
|
return $this->mutator; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* {@inheritdoc} |
178
|
|
|
*/ |
179
|
36 |
|
public function setMutator($mutator) |
180
|
|
|
{ |
181
|
36 |
|
$this->mutator = $mutator; |
182
|
36 |
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* {@inheritdoc} |
186
|
|
|
*/ |
187
|
225 |
|
public function hasSinceVersion() |
188
|
|
|
{ |
189
|
225 |
|
return $this->since !== null; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* {@inheritdoc} |
194
|
|
|
*/ |
195
|
225 |
|
public function getSinceVersion() |
196
|
|
|
{ |
197
|
225 |
|
return $this->since; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* {@inheritdoc} |
202
|
|
|
*/ |
203
|
72 |
|
public function setSinceVersion($since) |
204
|
|
|
{ |
205
|
72 |
|
$this->since = $since; |
206
|
72 |
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* {@inheritdoc} |
210
|
|
|
*/ |
211
|
225 |
|
public function hasUntilVersion() |
212
|
|
|
{ |
213
|
225 |
|
return $this->until !== null; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* {@inheritdoc} |
218
|
|
|
*/ |
219
|
225 |
|
public function getUntilVersion() |
220
|
|
|
{ |
221
|
225 |
|
return $this->until; |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* {@inheritdoc} |
226
|
|
|
*/ |
227
|
72 |
|
public function setUntilVersion($until) |
228
|
|
|
{ |
229
|
72 |
|
$this->until = $until; |
230
|
72 |
|
} |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* {@inheritdoc} |
234
|
|
|
*/ |
235
|
198 |
|
public function hasMaxDepth() |
236
|
|
|
{ |
237
|
198 |
|
return $this->maxDepth !== null; |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* {@inheritdoc} |
242
|
|
|
*/ |
243
|
198 |
|
public function getMaxDepth() |
244
|
|
|
{ |
245
|
198 |
|
return $this->maxDepth; |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* {@inheritdoc} |
250
|
|
|
*/ |
251
|
54 |
|
public function setMaxDepth($maxDepth) |
252
|
|
|
{ |
253
|
54 |
|
$this->maxDepth = $maxDepth; |
254
|
54 |
|
} |
255
|
|
|
|
256
|
|
|
/** |
257
|
|
|
* {@inheritdoc} |
258
|
|
|
*/ |
259
|
195 |
|
public function hasGroups() |
260
|
|
|
{ |
261
|
195 |
|
return !empty($this->groups); |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
/** |
265
|
|
|
* {@inheritdoc} |
266
|
|
|
*/ |
267
|
198 |
|
public function getGroups() |
268
|
|
|
{ |
269
|
198 |
|
return array_keys($this->groups); |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
/** |
273
|
|
|
* {@inheritdoc} |
274
|
|
|
*/ |
275
|
9 |
|
public function setGroups(array $groups) |
276
|
|
|
{ |
277
|
9 |
|
$this->groups = []; |
278
|
9 |
|
$this->addGroups($groups); |
279
|
9 |
|
} |
280
|
|
|
|
281
|
|
|
/** |
282
|
|
|
* {@inheritdoc} |
283
|
|
|
*/ |
284
|
9 |
|
public function addGroups(array $groups) |
285
|
|
|
{ |
286
|
9 |
|
foreach ($groups as $group) { |
287
|
9 |
|
$this->addGroup($group); |
288
|
6 |
|
} |
289
|
9 |
|
} |
290
|
|
|
|
291
|
|
|
/** |
292
|
|
|
* {@inheritdoc} |
293
|
|
|
*/ |
294
|
90 |
|
public function hasGroup($group) |
295
|
|
|
{ |
296
|
90 |
|
return isset($this->groups[$group]); |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
/** |
300
|
|
|
* {@inheritdoc} |
301
|
|
|
*/ |
302
|
90 |
|
public function addGroup($group) |
303
|
|
|
{ |
304
|
90 |
|
if (!$this->hasGroup($group)) { |
305
|
90 |
|
$this->groups[$group] = true; |
306
|
60 |
|
} |
307
|
90 |
|
} |
308
|
|
|
|
309
|
|
|
/** |
310
|
|
|
* {@inheritdoc} |
311
|
|
|
*/ |
312
|
3 |
|
public function removeGroup($group) |
313
|
|
|
{ |
314
|
3 |
|
unset($this->groups[$group]); |
315
|
3 |
|
} |
316
|
|
|
|
317
|
|
|
/** |
318
|
|
|
* {@inheritdoc} |
319
|
|
|
*/ |
320
|
3 |
|
public function merge(PropertyMetadataInterface $propertyMetadata) |
321
|
|
|
{ |
322
|
3 |
|
if ($propertyMetadata->hasAlias()) { |
323
|
3 |
|
$this->setAlias($propertyMetadata->getAlias()); |
324
|
2 |
|
} |
325
|
|
|
|
326
|
3 |
|
if ($propertyMetadata->hasType()) { |
327
|
3 |
|
$this->setType($propertyMetadata->getType()); |
328
|
2 |
|
} |
329
|
|
|
|
330
|
3 |
|
if ($propertyMetadata->hasAccessor()) { |
331
|
3 |
|
$this->setAccessor($propertyMetadata->getAccessor()); |
332
|
2 |
|
} |
333
|
|
|
|
334
|
3 |
|
if ($propertyMetadata->hasMutator()) { |
335
|
3 |
|
$this->setMutator($propertyMetadata->getMutator()); |
336
|
2 |
|
} |
337
|
|
|
|
338
|
3 |
|
if ($propertyMetadata->hasSinceVersion()) { |
339
|
3 |
|
$this->setSinceVersion($propertyMetadata->getSinceVersion()); |
340
|
2 |
|
} |
341
|
|
|
|
342
|
3 |
|
if ($propertyMetadata->hasUntilVersion()) { |
343
|
3 |
|
$this->setUntilVersion($propertyMetadata->getUntilVersion()); |
344
|
2 |
|
} |
345
|
|
|
|
346
|
3 |
|
if ($propertyMetadata->hasMaxDepth()) { |
347
|
3 |
|
$this->setMaxDepth($propertyMetadata->getMaxDepth()); |
348
|
2 |
|
} |
349
|
|
|
|
350
|
3 |
|
foreach ($propertyMetadata->getGroups() as $group) { |
351
|
3 |
|
$this->addGroup($group); |
352
|
2 |
|
} |
353
|
3 |
|
} |
354
|
|
|
|
355
|
|
|
/** |
356
|
|
|
* {@inheritdoc} |
357
|
|
|
*/ |
358
|
3 |
|
public function serialize() |
359
|
|
|
{ |
360
|
3 |
|
return serialize([ |
361
|
3 |
|
$this->name, |
362
|
3 |
|
$this->alias, |
363
|
3 |
|
$this->type, |
364
|
3 |
|
$this->accessor, |
365
|
3 |
|
$this->mutator, |
366
|
3 |
|
$this->since, |
367
|
3 |
|
$this->until, |
368
|
3 |
|
$this->maxDepth, |
369
|
3 |
|
$this->groups, |
370
|
2 |
|
]); |
371
|
|
|
} |
372
|
|
|
|
373
|
|
|
/** |
374
|
|
|
* {@inheritdoc} |
375
|
|
|
*/ |
376
|
3 |
|
public function unserialize($serialized) |
377
|
|
|
{ |
378
|
|
|
list( |
379
|
3 |
|
$this->name, |
380
|
3 |
|
$this->alias, |
381
|
3 |
|
$this->type, |
382
|
3 |
|
$this->accessor, |
383
|
3 |
|
$this->mutator, |
384
|
3 |
|
$this->since, |
385
|
3 |
|
$this->until, |
386
|
3 |
|
$this->maxDepth, |
387
|
3 |
|
$this->groups |
388
|
3 |
|
) = unserialize($serialized); |
389
|
3 |
|
} |
390
|
|
|
} |
391
|
|
|
|