-
Notifications
You must be signed in to change notification settings - Fork 446
Expand file tree
/
Copy pathAbstractCollectionMutator.php
More file actions
89 lines (71 loc) · 1.65 KB
/
AbstractCollectionMutator.php
File metadata and controls
89 lines (71 loc) · 1.65 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
declare(strict_types=1);
namespace BitWasp\Bitcoin\Transaction\Mutator;
use ArrayAccess;
use Countable;
use Iterator;
use SplFixedArray;
abstract class AbstractCollectionMutator implements Iterator, ArrayAccess, Countable
{
protected $set;
private $position;
public function __construct(int $size)
{
$this->set = new SplFixedArray($size);
$this->position = 0;
}
public function all(): array
{
return $this->set->toArray();
}
public function isNull(): bool
{
return count($this->set) === 0;
}
public function rewind()
{
$this->position = 0;
}
public function current()
{
return $this->set[$this->position];
}
public function key()
{
return $this->position;
}
public function next()
{
$this->position++;
}
public function valid()
{
return isset($this->set[$this->position]);
}
public function offsetExists($offset)
{
return isset($this->set[$offset]);
}
public function offsetGet($offset)
{
return $this->set[$offset];
}
public function offsetSet($offset, $value)
{
if (!$this->set->offsetExists($offset)) {
throw new \OutOfRangeException('Nothing found at this offset');
}
$this->set[$offset] = $value;
}
public function offsetUnset($offset)
{
if (!$this->offsetExists($offset)) {
throw new \InvalidArgumentException('Offset does not exist');
}
unset($this->set[$offset]);
}
public function count()
{
return $this->set->count();
}
}