-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathInput.php
More file actions
58 lines (50 loc) · 1.35 KB
/
Input.php
File metadata and controls
58 lines (50 loc) · 1.35 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
<?php
namespace Equip;
use Equip\Adr\InputInterface;
use Psr\Http\Message\ServerRequestInterface;
class Input implements InputInterface
{
/**
* Flatten all input from the request.
*
* @param ServerRequestInterface $request
*
* @return array
*/
public function __invoke(
ServerRequestInterface $request
) {
$attrs = $request->getAttributes();
$body = $this->body($request);
$cookies = $request->getCookieParams();
$query = $request->getQueryParams();
$uploads = $request->getUploadedFiles();
// Order matters here! Important values go last!
return array_replace(
$query,
$body,
$uploads,
$cookies,
$attrs
);
}
/**
* @param ServerRequestInterface $request
*
* @return array
*/
private function body(ServerRequestInterface $request)
{
$body = $request->getParsedBody();
if (empty($body)) {
return [];
}
if (is_object($body)) {
// Because the parsed body may also be represented as an object,
// additional parsing is required. This is a bit dirty but works
// very well for anonymous objects.
$body = json_decode(json_encode($body), true);
}
return $body;
}
}