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