Repository navigation
Expand file tree
/
Copy pathRequestInput.php
More file actions
74 lines (61 loc) · 1.67 KB
/
Copy pathRequestInput.php
File metadata and controls
74 lines (61 loc) · 1.67 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
<?php
declare(strict_types=1);
/**
* This file is part of CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace CodeIgniter\HTTP;
use CodeIgniter\HTTP\Exceptions\HTTPException;
use CodeIgniter\Input\InputData;
use CodeIgniter\Input\InputDataFactory;
/**
* Provides typed input access for request data sources.
*
* @see \CodeIgniter\HTTP\RequestInputTest
*/
final readonly class RequestInput
{
public function __construct(
private IncomingRequest $request,
private InputDataFactory $factory,
) {
}
/**
* Returns GET parameters as a typed input object.
*/
public function get(): InputData
{
$data = $this->request->getGet();
return $this->factory->create(is_array($data) ? $data : []);
}
/**
* Returns POST body parameters as a typed input object.
*/
public function post(): InputData
{
$data = $this->request->getPost();
return $this->factory->create(is_array($data) ? $data : []);
}
/**
* Returns JSON body parameters as a typed input object.
*/
public function json(): InputData
{
$data = $this->request->getJSON(true) ?? [];
if (! is_array($data)) {
throw HTTPException::forUnsupportedJSONFormat();
}
return $this->factory->create($data);
}
/**
* Returns raw input parameters as a typed input object.
*/
public function raw(): InputData
{
return $this->factory->create($this->request->getRawInput());
}
}