-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathAbstractValueCollection.php
More file actions
57 lines (42 loc) · 1015 Bytes
/
AbstractValueCollection.php
File metadata and controls
57 lines (42 loc) · 1015 Bytes
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
52
53
54
55
56
57
<?php declare(strict_types = 1);
namespace Spameri\Elastic\Entity;
abstract class AbstractValueCollection implements ValueCollectionInterface
{
/**
* @var array<\Spameri\Elastic\Entity\ValueInterface>
*/
protected array $collection;
public function __construct(
\Spameri\Elastic\Entity\ValueInterface ...$collection,
)
{
$this->collection = [];
foreach ($collection as $value) {
$this->add($value);
}
}
public function add(
\Spameri\Elastic\Entity\ValueInterface $value,
): void
{
$this->collection[$value->value()] = $value;
}
public function remove(mixed $key): void
{
unset($this->collection[$key]);
}
public function get(mixed $key): \Spameri\Elastic\Entity\ValueInterface|null
{
if ( ! isset($this->collection[$key])) {
return NULL;
}
return $this->collection[$key];
}
/**
* @return \ArrayIterator<\Spameri\Elastic\Entity\ValueInterface>
*/
public function getIterator(): \ArrayIterator
{
return new \ArrayIterator($this->collection);
}
}