1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\Annotations\Metadata; |
6
|
|
|
|
7
|
|
|
use Doctrine\Annotations\Metadata\Exception\MetadataAlreadyExists; |
8
|
|
|
use Doctrine\Annotations\Metadata\Exception\MetadataDoesNotExist; |
9
|
|
|
use Traversable; |
10
|
|
|
use function array_key_exists; |
11
|
|
|
use function array_values; |
12
|
|
|
use function count; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* In-memory metadata collection. |
16
|
|
|
* |
17
|
|
|
* @internal |
18
|
|
|
*/ |
19
|
|
|
final class TransientMetadataCollection implements MetadataCollection |
20
|
|
|
{ |
21
|
|
|
/** @var array<string, AnnotationMetadata> */ |
22
|
|
|
private $metadata = []; |
23
|
|
|
|
24
|
295 |
|
public function __construct(AnnotationMetadata ...$metadatas) |
25
|
|
|
{ |
26
|
295 |
|
$this->add(...$metadatas); |
27
|
294 |
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @throws MetadataAlreadyExists |
31
|
|
|
*/ |
32
|
295 |
|
public function add(AnnotationMetadata ...$metadatas) : void |
33
|
|
|
{ |
34
|
295 |
|
foreach ($metadatas as $metadata) { |
35
|
294 |
|
if (isset($this->metadata[$metadata->getName()])) { |
36
|
1 |
|
throw MetadataAlreadyExists::new($metadata); |
37
|
|
|
} |
38
|
|
|
|
39
|
294 |
|
$this->metadata[$metadata->getName()] = $metadata; |
40
|
|
|
} |
41
|
294 |
|
} |
42
|
|
|
|
43
|
1 |
|
public function include(MetadataCollection $other) : void |
44
|
|
|
{ |
45
|
1 |
|
$this->add(...$other); |
46
|
1 |
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @throws MetadataDoesNotExist |
50
|
|
|
*/ |
51
|
261 |
|
public function get(string $name) : AnnotationMetadata |
52
|
|
|
{ |
53
|
261 |
|
if (! isset($this->metadata[$name])) { |
54
|
1 |
|
throw MetadataDoesNotExist::new($name); |
55
|
|
|
} |
56
|
|
|
|
57
|
260 |
|
return $this->metadata[$name]; |
58
|
|
|
} |
59
|
|
|
|
60
|
264 |
|
public function has(string $name) : bool |
61
|
|
|
{ |
62
|
264 |
|
return array_key_exists($name, $this->metadata); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return Traversable<AnnotationMetadata> |
67
|
|
|
*/ |
68
|
2 |
|
public function getIterator() : Traversable |
69
|
|
|
{ |
70
|
2 |
|
yield from array_values($this->metadata); |
71
|
2 |
|
} |
72
|
|
|
|
73
|
3 |
|
public function count() : int |
74
|
|
|
{ |
75
|
3 |
|
return count($this->metadata); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|