1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\Annotations\Parser; |
6
|
|
|
|
7
|
|
|
use ArrayAccess; |
8
|
|
|
use IteratorAggregate; |
9
|
|
|
use function assert; |
10
|
|
|
use function in_array; |
11
|
|
|
use function is_string; |
12
|
|
|
use function strtolower; |
13
|
|
|
|
14
|
|
|
final class Imports implements ArrayAccess, IteratorAggregate |
15
|
|
|
{ |
16
|
|
|
/** @var string[] array<string, string> alias => FCQN */ |
17
|
|
|
private $map = []; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @param string[] $map iterable<string, string> |
21
|
|
|
*/ |
22
|
45 |
|
public function __construct(iterable $map) |
23
|
|
|
{ |
24
|
45 |
|
foreach ($map as $alias => $name) { |
25
|
30 |
|
assert(is_string($alias) && is_string($name)); |
26
|
30 |
|
assert(! isset($this[strtolower($alias)])); |
27
|
|
|
|
28
|
30 |
|
$this->map[strtolower($alias)] = $name; |
29
|
|
|
} |
30
|
45 |
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @return string[] alias => FCQN |
34
|
|
|
*/ |
35
|
|
|
public function getIterator() : iterable |
36
|
|
|
{ |
37
|
|
|
yield from $this->map; |
|
|
|
|
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param string $offset |
42
|
|
|
* |
43
|
|
|
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint |
44
|
|
|
*/ |
45
|
9 |
|
public function offsetGet($offset) : string |
46
|
|
|
{ |
47
|
9 |
|
assert(isset($this[strtolower($offset)])); |
48
|
|
|
|
49
|
9 |
|
return $this->map[strtolower($offset)]; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param string $offset |
54
|
|
|
* @param mixed $value |
55
|
|
|
* |
56
|
|
|
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint |
57
|
|
|
*/ |
58
|
|
|
public function offsetSet($offset, $value) : void |
59
|
|
|
{ |
60
|
|
|
assert(false, 'immutable'); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param string $offset |
65
|
|
|
* |
66
|
|
|
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint |
67
|
|
|
*/ |
68
|
39 |
|
public function offsetExists($offset) : bool |
69
|
|
|
{ |
70
|
39 |
|
return isset($this->map[strtolower($offset)]); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param string $offset |
75
|
|
|
* |
76
|
|
|
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint |
77
|
|
|
*/ |
78
|
|
|
public function offsetUnset($offset) : void |
79
|
|
|
{ |
80
|
|
|
assert(false, 'immutable'); |
81
|
|
|
} |
82
|
|
|
|
83
|
2 |
|
public function isKnown(string $name) : bool |
84
|
|
|
{ |
85
|
2 |
|
return in_array($name, $this->map, true); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|