-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathConsole.php
More file actions
90 lines (81 loc) · 2.14 KB
/
Console.php
File metadata and controls
90 lines (81 loc) · 2.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
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
90
<?php
declare(strict_types=1);
// This class is defined in the console when executing php from a form
class IPSList implements ArrayAccess, IteratorAggregate, JsonSerializable
{
private $position = 0;
private $selected = 0;
private $array = [];
private $default = [];
public function __construct($value)
{
$this->position = 0;
$decodedValue = json_decode($value, true);
$this->array = $decodedValue['list'];
$this->selected = $decodedValue['selected'];
$this->default = $decodedValue['default'] ?? null;
}
public function getIterator(): Traversable
{
return new ArrayIterator($this->array);
}
public function offsetExists(mixed $i): bool
{
if (is_string($i)) {
return isset($this->getRow($this->selected)[$i]);
}
else {
return isset($this->array[$i]);
}
}
public function offsetGet(mixed $i): mixed
{
if (is_string($i)) {
return $this->getRow($this->selected)[$i];
}
else {
return $this->array[$i];
}
}
public function offsetSet(mixed $i, mixed $value): void
{
if (is_string($i)) {
if (isset($this->array[$this->selected])) {
$this->array[$this->selected][$i] = $value;
}
else {
$this->default[$i] = $value;
}
}
else {
$this->array[$i] = $value;
}
}
public function offsetUnset(mixed $i): void
{
if (is_string($i)) {
if (isset($this->array[$this->selected])) {
unset($this->array[$this->selected][$i]);
}
else {
unset($this->default[$i]);
}
}
else {
unset($this->array[$i]);
}
}
public function jsonSerialize(): mixed
{
return $this->getRow($this->selected);
}
private function getRow(mixed $i): ?array
{
if (isset($this->array[$i])) {
return $this->array[$i];
}
else {
return $this->default;
}
}
}