1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace kalanis\kw_input\Sources; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use kalanis\kw_input\Interfaces; |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class Basic |
11
|
|
|
* @package kalanis\kw_input\Sources |
12
|
|
|
* Source of values to parse and use |
13
|
|
|
* @codeCoverageIgnore because this is access to php internals |
14
|
|
|
*/ |
15
|
|
|
class Basic implements Interfaces\ISource |
16
|
|
|
{ |
17
|
|
|
/** @var string[]|int[]|array<string|int, string|int|bool> */ |
18
|
|
|
protected $cliArgs = []; |
19
|
|
|
/** @var string[]|int[]|array<string|int, string|int|bool> */ |
20
|
|
|
protected $externalArgs = []; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @param array<string|int, string|int> $cliArgs |
24
|
|
|
* @return $this |
25
|
|
|
*/ |
26
|
|
|
public function setCli(array $cliArgs = []): self |
27
|
|
|
{ |
28
|
|
|
$this->cliArgs = $cliArgs; |
29
|
|
|
return $this; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function cli(): ?array |
33
|
|
|
{ |
34
|
|
|
return $this->cliArgs; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function get(): ?array |
38
|
|
|
{ |
39
|
|
|
return $_GET; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function post(): ?array |
43
|
|
|
{ |
44
|
|
|
return $_POST; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function files(): ?array |
48
|
|
|
{ |
49
|
|
|
return $_FILES; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function cookie(): ?array |
53
|
|
|
{ |
54
|
|
|
return $_COOKIE; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function session(): ?array |
58
|
|
|
{ |
59
|
|
|
return PHP_SESSION_ACTIVE == session_status() ? $_SESSION : []; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function server(): ?array |
63
|
|
|
{ |
64
|
|
|
return $_SERVER; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function env(): ?array |
68
|
|
|
{ |
69
|
|
|
return $_ENV; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function external(): ?array |
73
|
|
|
{ |
74
|
|
|
return $this->externalArgs; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function inputRawPaths(): ?array |
78
|
|
|
{ |
79
|
|
|
return ['php://input']; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param string[]|int[]|array<string|int, string|int|bool> $externalArgs |
84
|
|
|
* @return $this |
85
|
|
|
*/ |
86
|
|
|
public function setExternal(array $externalArgs = []): self |
87
|
|
|
{ |
88
|
|
|
$this->externalArgs = $externalArgs; |
89
|
|
|
return $this; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|