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