-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeCollection.php
More file actions
51 lines (37 loc) · 1.14 KB
/
Copy pathCodeCollection.php
File metadata and controls
51 lines (37 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
declare(strict_types=1);
namespace Echron\DataTypes;
use Echron\Tools\Normalize\NormalizeConfig;
class CodeCollection extends BasicCollection
{
private KeyValueStore $codeValueStore;
public function __construct(NormalizeConfig $normalizeConfig = null)
{
parent::__construct();
$this->codeValueStore = new KeyValueStore($normalizeConfig);
}
public function add(string $code, mixed $value): void
{
$index = $this->addToCollection($value);
$this->codeValueStore->add($code, $index);
}
public function removeByCode(string $code): void
{
$index = $this->codeValueStore->getValueByKey($code);
$this->codeValueStore->removeByValue($index);
$this->removeFromCollection($index);
}
public function getByCode(string $code): mixed
{
$index = $this->codeValueStore->getValueByKey($code);
return $this->getByIndex($index);
}
public function hasCode(string $code): bool
{
return $this->codeValueStore->hasKey($code);
}
public function getCodes(): array
{
return $this->codeValueStore->getKeys();
}
}