-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathListScreenCollection.php
82 lines (62 loc) · 1.42 KB
/
ListScreenCollection.php
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
<?php
declare(strict_types=1);
namespace AC;
use Countable;
use Iterator;
final class ListScreenCollection implements Iterator, Countable
{
/**
* @var ListScreen[]
*/
private $data = [];
public function __construct(array $list_screens = [])
{
array_map([$this, 'add'], $list_screens);
}
public function add(ListScreen $list_screen): void
{
$this->data[(string)$list_screen->get_id()] = $list_screen;
}
public function remove(ListScreen $list_screen): void
{
unset($this->data[(string)$list_screen->get_id()]);
}
public function contains(ListScreen $list_screen): bool
{
return isset($this->data[(string)$list_screen->get_id()]);
}
public function rewind(): void
{
reset($this->data);
}
public function current(): ListScreen
{
return current($this->data);
}
public function get_first(): ListScreen
{
return reset($this->data);
}
public function key(): string
{
return key($this->data);
}
public function next(): void
{
next($this->data);
}
public function valid(): bool
{
return key($this->data) !== null;
}
public function count(): int
{
return count($this->data);
}
public function get_copy(): array
{
$copy = $this->data;
reset($copy);
return $copy;
}
}