1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\Annotations\Metadata; |
6
|
|
|
|
7
|
|
|
use function array_combine; |
8
|
|
|
use function array_filter; |
9
|
|
|
use function array_map; |
10
|
|
|
use function array_values; |
11
|
|
|
use function count; |
12
|
|
|
|
13
|
|
|
final class AnnotationMetadata |
14
|
|
|
{ |
15
|
|
|
/** @var string */ |
16
|
|
|
private $name; |
17
|
|
|
|
18
|
|
|
/** @var AnnotationTarget */ |
19
|
|
|
private $target; |
20
|
|
|
|
21
|
|
|
/** @var bool */ |
22
|
|
|
private $hasConstructor; |
23
|
|
|
|
24
|
|
|
/** @var PropertyMetadata[] */ |
25
|
|
|
private $properties; |
26
|
|
|
|
27
|
|
|
/** @var PropertyMetadata|null */ |
28
|
|
|
private $defaultProperty; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* TODO: Validate input |
32
|
|
|
* |
33
|
|
|
* @param PropertyMetadata[] $properties |
34
|
|
|
*/ |
35
|
10 |
|
public function __construct( |
36
|
|
|
string $name, |
37
|
|
|
AnnotationTarget $target, |
38
|
|
|
bool $hasConstructor, |
39
|
|
|
array $properties = [] |
40
|
|
|
) { |
41
|
10 |
|
$this->name = $name; |
42
|
10 |
|
$this->target = $target; |
43
|
10 |
|
$this->hasConstructor = $hasConstructor; |
44
|
10 |
|
$this->properties = array_combine( |
45
|
|
|
array_map(function (PropertyMetadata $property) : string { |
46
|
6 |
|
return $property->getName(); |
47
|
10 |
|
}, $properties), |
48
|
10 |
|
$properties |
49
|
|
|
); |
50
|
|
|
|
51
|
|
|
$this->defaultProperty = array_values(array_filter($properties, function (PropertyMetadata $property) : bool { |
52
|
6 |
|
return $property->isDefault(); |
53
|
10 |
|
}))[0] ?? null; |
54
|
10 |
|
} |
55
|
|
|
|
56
|
18 |
|
public function getName() : string |
57
|
|
|
{ |
58
|
18 |
|
return $this->name; |
59
|
|
|
} |
60
|
|
|
|
61
|
26 |
|
public function getTarget() : AnnotationTarget |
62
|
|
|
{ |
63
|
26 |
|
return $this->target; |
64
|
|
|
} |
65
|
|
|
|
66
|
9 |
|
public function hasConstructor() : bool |
67
|
|
|
{ |
68
|
9 |
|
return $this->hasConstructor; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return PropertyMetadata[] |
73
|
|
|
*/ |
74
|
6 |
|
public function getProperties() : array |
75
|
|
|
{ |
76
|
6 |
|
return $this->properties; |
77
|
|
|
} |
78
|
|
|
|
79
|
6 |
|
public function getDefaultProperty() : ?PropertyMetadata |
80
|
|
|
{ |
81
|
6 |
|
return $this->defaultProperty; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|