-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRequestInputHandler.php
More file actions
98 lines (85 loc) · 2.63 KB
/
RequestInputHandler.php
File metadata and controls
98 lines (85 loc) · 2.63 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
namespace BitSensor\Handler;
use BitSensor\Core\FileContext;
use BitSensor\Core\InputContext;
use BitSensor\Core\SessionContext;
use Proto\Datapoint;
/**
* Collects information about the HTTP request data.
* @package BitSensor\Handler
*/
class RequestInputHandler extends AbstractHandler
{
/**
* @param Datapoint $datapoint
*/
public function doHandle(Datapoint $datapoint)
{
$post = array();
foreach ($_POST as $k => $v) {
if (is_array($v)) {
self::flatten($v, $post, $k);
} else {
$post[$k] = $v;
}
}
foreach ($post as $k => $v) {
$datapoint->getInput()[InputContext::POST . '.' . $k] = $v;
}
$get = array();
foreach ($_GET as $k => $v) {
if (is_array($v)) {
self::flatten($v, $get, $k);
} else {
$get[$k] = $v;
}
}
foreach ($get as $k => $v) {
$datapoint->getInput()[InputContext::GET . '.' . $k] = $v;
}
$cookie = array();
foreach ($_COOKIE as $k => $v) {
if (is_array($v)) {
self::flatten($v, $cookie, $k);
} else {
$cookie[$k] = $v;
}
}
foreach ($cookie as $k => $v) {
if ($k === 'PHPSESSID') {
$datapoint->getContext()['php.' . SessionContext::NAME . '.' . SessionContext::SESSION_ID] = $v;
} else {
$datapoint->getInput()[InputContext::COOKIE . '.' . $k] = $v;
}
}
$files = array();
foreach ($_FILES as $k => $v) {
if (is_array($v)) {
self::flatten($v, $files, $k);
} else {
$files[$k] = $v;
}
}
foreach ($files as $k => $v) {
$datapoint->getInput()[FileContext::NAME . '.' . $k] = $v;
}
}
/**
* Flattens an array into an other array. After execution <code>$output</code> contains
* a flattened version of <code>$input</code>.
*
* @param array $input The original array.
* @param array $output The array in which the flattened elements should be placed.
* @param string $prefix Prefix to add to each element.
*/
public static function flatten($input, &$output, $prefix)
{
foreach ($input as $k => $v) {
if (is_array($v)) {
self::flatten($v, $output, $prefix . ($prefix !== '' ? '.' : '') . $k);
} else {
$output[$prefix . ($prefix !== '' ? '.' : '') . $k] = $v;
}
}
}
}