1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace kalanis\kw_forms\Adapters; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use kalanis\kw_forms\Exceptions\FormsException; |
7
|
|
|
use kalanis\kw_input\Interfaces\IEntry; |
8
|
|
|
use kalanis\kw_input\Interfaces\IFiltered; |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class InputVarsAdapter |
13
|
|
|
* @package kalanis\kw_forms\Adapters |
14
|
|
|
*/ |
15
|
|
|
class InputVarsAdapter extends VarsAdapter |
16
|
|
|
{ |
17
|
|
|
protected IFiltered $inputs; |
18
|
|
|
|
19
|
4 |
|
public function __construct(IFiltered $inputs) |
20
|
|
|
{ |
21
|
4 |
|
$this->inputs = $inputs; |
22
|
4 |
|
} |
23
|
|
|
|
24
|
4 |
|
public function loadEntries(string $inputType): void |
25
|
|
|
{ |
26
|
4 |
|
if (IEntry::SOURCE_POST == $inputType) { |
27
|
1 |
|
$this->vars = $this->inputs->getInArray(null, [IEntry::SOURCE_POST]); |
28
|
4 |
|
} elseif (IEntry::SOURCE_GET == $inputType) { |
29
|
1 |
|
$this->vars = $this->inputs->getInArray(null, [IEntry::SOURCE_GET]); |
30
|
4 |
|
} elseif (IEntry::SOURCE_CLI == $inputType) { |
31
|
2 |
|
$this->vars = $this->inputs->getInArray(null, [IEntry::SOURCE_CLI]); |
32
|
3 |
|
} elseif (IEntry::SOURCE_JSON == $inputType) { |
33
|
2 |
|
$this->vars = $this->inputs->getInArray(null, [IEntry::SOURCE_JSON]); |
34
|
|
|
} else { |
35
|
1 |
|
throw new FormsException(sprintf('Unknown input type - %s', $inputType)); |
36
|
|
|
} |
37
|
3 |
|
$this->inputType = $inputType; |
38
|
3 |
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @throws FormsException |
42
|
|
|
* @return mixed|string|null |
43
|
|
|
*/ |
44
|
2 |
|
public function getValue() |
45
|
|
|
{ |
46
|
2 |
|
return $this->current()->getValue(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
#[\ReturnTypeWillChange] |
50
|
3 |
|
public function current() |
51
|
|
|
{ |
52
|
3 |
|
if ($this->valid()) { |
53
|
2 |
|
return $this->offsetGet($this->key); |
54
|
|
|
} |
55
|
1 |
|
throw new FormsException(sprintf('Unknown offset %s', $this->key)); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|