|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace kalanis\kw_forms\Adapters; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use ArrayAccess; |
|
7
|
|
|
use Countable; |
|
8
|
|
|
use Iterator; |
|
9
|
|
|
use kalanis\kw_forms\Exceptions\FormsException; |
|
10
|
|
|
use kalanis\kw_input\Interfaces\IEntry; |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
abstract class AAdapter implements ArrayAccess, Countable, Iterator, IEntry |
|
14
|
|
|
{ |
|
15
|
|
|
protected ?string $key = null; |
|
16
|
|
|
/** @var array<string, string|int|float|null|IEntry> */ |
|
17
|
|
|
protected array $vars = []; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @param string $inputType |
|
21
|
|
|
* @throws FormsException |
|
22
|
|
|
*/ |
|
23
|
|
|
abstract public function loadEntries(string $inputType): void; |
|
24
|
|
|
|
|
25
|
7 |
|
public function getKey(): string |
|
26
|
|
|
{ |
|
27
|
7 |
|
return strval($this->key); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @return mixed|string|null |
|
32
|
|
|
*/ |
|
33
|
5 |
|
public function getValue() |
|
34
|
|
|
{ |
|
35
|
5 |
|
return $this->current(); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
#[\ReturnTypeWillChange] |
|
39
|
8 |
|
public function current() |
|
40
|
|
|
{ |
|
41
|
8 |
|
return $this->valid() ? $this->offsetGet($this->key) : null ; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
15 |
|
public function next(): void |
|
45
|
|
|
{ |
|
46
|
15 |
|
next($this->vars); |
|
47
|
15 |
|
$this->key = key($this->vars); |
|
48
|
15 |
|
} |
|
49
|
|
|
|
|
50
|
|
|
#[\ReturnTypeWillChange] |
|
51
|
11 |
|
public function key() |
|
52
|
|
|
{ |
|
53
|
11 |
|
return $this->key; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
16 |
|
public function valid(): bool |
|
57
|
|
|
{ |
|
58
|
16 |
|
return $this->offsetExists($this->key); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
16 |
|
public function rewind(): void |
|
62
|
|
|
{ |
|
63
|
16 |
|
reset($this->vars); |
|
64
|
16 |
|
$this->key = key($this->vars); |
|
65
|
16 |
|
} |
|
66
|
|
|
|
|
67
|
18 |
|
public function offsetExists($offset): bool |
|
68
|
|
|
{ |
|
69
|
18 |
|
return isset($this->vars[$offset]); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
#[\ReturnTypeWillChange] |
|
73
|
15 |
|
public function offsetGet($offset) |
|
74
|
|
|
{ |
|
75
|
15 |
|
return $this->vars[$offset]; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @param string $offset |
|
80
|
|
|
* @param mixed $value |
|
81
|
|
|
*/ |
|
82
|
8 |
|
public function offsetSet($offset, $value): void |
|
83
|
|
|
{ |
|
84
|
8 |
|
$this->vars[$offset] = $value; |
|
85
|
8 |
|
} |
|
86
|
|
|
|
|
87
|
8 |
|
public function offsetUnset($offset): void |
|
88
|
|
|
{ |
|
89
|
8 |
|
unset($this->vars[$offset]); |
|
90
|
8 |
|
} |
|
91
|
|
|
|
|
92
|
8 |
|
public function count(): int |
|
93
|
|
|
{ |
|
94
|
8 |
|
return count($this->vars); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
10 |
|
protected function removeNullBytes(string $string, string $nullTo = ''): string |
|
98
|
|
|
{ |
|
99
|
10 |
|
return strval(str_replace(chr(0), $nullTo, $string)); |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|