1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Knp\DictionaryBundle\Dictionary; |
6
|
|
|
|
7
|
|
|
use Knp\DictionaryBundle\DataCollector\DictionaryDataCollector; |
8
|
|
|
use Knp\DictionaryBundle\Dictionary; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @template E of mixed |
12
|
|
|
* |
13
|
|
|
* @implements Dictionary<E> |
14
|
|
|
*/ |
15
|
|
|
final class Traceable implements Dictionary |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @param Dictionary<E> $dictionary |
19
|
|
|
*/ |
20
|
|
|
public function __construct( |
21
|
|
|
private readonly Dictionary $dictionary, |
22
|
|
|
private readonly DictionaryDataCollector $dictionaryDataCollector |
23
|
|
|
) {} |
24
|
|
|
|
25
|
|
|
public function getName(): string |
26
|
|
|
{ |
27
|
|
|
return $this->dictionary->getName(); |
28
|
|
|
} |
29
|
11 |
|
|
30
|
|
|
public function getValues(): array |
31
|
11 |
|
{ |
32
|
11 |
|
$this->markAsUsed(); |
33
|
11 |
|
|
34
|
|
|
return $this->dictionary->getValues(); |
35
|
1 |
|
} |
36
|
|
|
|
37
|
1 |
|
public function getKeys(): array |
38
|
|
|
{ |
39
|
|
|
$this->markAsUsed(); |
40
|
1 |
|
|
41
|
|
|
return $this->dictionary->getKeys(); |
42
|
1 |
|
} |
43
|
|
|
|
44
|
1 |
|
public function offsetExists(mixed $offset): bool |
45
|
|
|
{ |
46
|
|
|
$this->markAsUsed(); |
47
|
1 |
|
|
48
|
|
|
return $this->dictionary->offsetExists($offset); |
49
|
1 |
|
} |
50
|
|
|
|
51
|
1 |
|
public function offsetGet(mixed $offset): mixed |
52
|
|
|
{ |
53
|
|
|
$this->markAsUsed(); |
54
|
1 |
|
|
55
|
|
|
return $this->dictionary->offsetGet($offset); |
56
|
1 |
|
} |
57
|
|
|
|
58
|
1 |
|
public function offsetSet(mixed $offset, mixed $value): void |
59
|
|
|
{ |
60
|
|
|
$this->dictionary->offsetSet($offset, $value); |
61
|
1 |
|
|
62
|
|
|
$this->markAsUsed(); |
63
|
1 |
|
} |
64
|
|
|
|
65
|
1 |
|
public function offsetUnset(mixed $offset): void |
66
|
|
|
{ |
67
|
|
|
$this->dictionary->offsetUnset($offset); |
68
|
1 |
|
|
69
|
|
|
$this->markAsUsed(); |
70
|
1 |
|
} |
71
|
|
|
|
72
|
1 |
|
/** |
73
|
1 |
|
* @return Dictionary<E> |
74
|
|
|
*/ |
75
|
1 |
|
public function getIterator(): Dictionary |
76
|
|
|
{ |
77
|
1 |
|
$this->markAsUsed(); |
78
|
|
|
|
79
|
1 |
|
return $this->dictionary; |
80
|
1 |
|
} |
81
|
|
|
|
82
|
|
|
public function count(): int |
83
|
|
|
{ |
84
|
|
|
$this->markAsUsed(); |
85
|
1 |
|
|
86
|
|
|
return $this->dictionary->count(); |
87
|
1 |
|
} |
88
|
|
|
|
89
|
1 |
|
/** |
90
|
|
|
* Mark this dictionary as used. |
91
|
|
|
*/ |
92
|
1 |
|
private function markAsUsed(): void |
93
|
|
|
{ |
94
|
1 |
|
$this->dictionaryDataCollector->addDictionary( |
95
|
|
|
$this->dictionary->getName(), |
96
|
1 |
|
$this->dictionary->getKeys(), |
97
|
|
|
array_values($this->dictionary->getValues()) |
98
|
|
|
); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|