|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* Copyright (c) Nate Brunette. |
|
4
|
|
|
* Distributed under the MIT License (http://opensource.org/licenses/MIT) |
|
5
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
namespace Tebru\Gson\Internal; |
|
8
|
|
|
|
|
9
|
|
|
use Tebru\Gson\ClassMetadata; |
|
10
|
|
|
use Tebru\Gson\Internal\Data\AnnotationCollectionFactory; |
|
11
|
|
|
use Tebru\Gson\Internal\Data\AnnotationSet; |
|
12
|
|
|
use Tebru\Gson\Internal\Data\Property; |
|
13
|
|
|
use Tebru\Gson\PropertyMetadata; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Class MetadataFactory |
|
17
|
|
|
* |
|
18
|
|
|
* @author Nate Brunette <[email protected]> |
|
19
|
|
|
*/ |
|
20
|
|
|
final class MetadataFactory |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* Reads annotations from a class, property, or method and returns |
|
24
|
|
|
* an [@see AnnotationSet] |
|
25
|
|
|
* |
|
26
|
|
|
* @var AnnotationCollectionFactory |
|
27
|
|
|
*/ |
|
28
|
|
|
private $annotationCollectionFactory; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Constructor |
|
32
|
|
|
* |
|
33
|
|
|
* @param AnnotationCollectionFactory $annotationCollectionFactory |
|
34
|
|
|
*/ |
|
35
|
2 |
|
public function __construct(AnnotationCollectionFactory $annotationCollectionFactory) |
|
36
|
|
|
{ |
|
37
|
2 |
|
$this->annotationCollectionFactory = $annotationCollectionFactory; |
|
38
|
2 |
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Create class metadata |
|
42
|
|
|
* |
|
43
|
|
|
* @param string $className |
|
44
|
|
|
* @return ClassMetadata |
|
45
|
|
|
* @throws \InvalidArgumentException If the type does not exist |
|
46
|
|
|
*/ |
|
47
|
2 |
|
public function createClassMetadata(string $className): ClassMetadata |
|
48
|
|
|
{ |
|
49
|
2 |
|
return new ClassMetadata($className, $this->annotationCollectionFactory->createClassAnnotations($className)); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Creates property metadata |
|
54
|
|
|
* |
|
55
|
|
|
* @param Property $property |
|
56
|
|
|
* @param ClassMetadata $classMetadata |
|
57
|
|
|
* @return PropertyMetadata |
|
58
|
|
|
*/ |
|
59
|
1 |
|
public function createPropertyMetadata(Property $property, ClassMetadata $classMetadata): PropertyMetadata |
|
60
|
|
|
{ |
|
61
|
1 |
|
return new PropertyMetadata( |
|
62
|
1 |
|
$property->getRealName(), |
|
63
|
1 |
|
$property->getSerializedName(), |
|
64
|
1 |
|
$property->getType(), |
|
65
|
1 |
|
$property->getModifiers(), |
|
66
|
|
|
$classMetadata, |
|
67
|
1 |
|
$property->getAnnotations(), |
|
68
|
1 |
|
$property->isVirtual() |
|
69
|
|
|
); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|