-
Notifications
You must be signed in to change notification settings - Fork 1
/
PhpIds.php
113 lines (90 loc) · 2.73 KB
/
PhpIds.php
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
namespace FS\PhpIdsBundle;
use FS\PhpIdsBundle\Monitor\IdsMonitor;
use Symfony\Component\HttpFoundation\Request;
/**
*
* @author Florian Semm
*/
class PhpIds {
/**
*
* @var array
*/
private $configs = array();
/**
*
* @var IdsMonitor
*/
private $monitor = null;
/**
*
* @var Request
*/
private $request;
const REQUEST_POST = 'POST';
const REQUEST_GET = 'GET';
const REQUEST_COOKIE = 'COOKIE';
const REQUEST_ALL = 'REQUEST';
/**
*
* @param Request $request
*/
public function __construct(Request $request) {
$this->request = $request;
}
/**
*
* @param array $configs
*/
public function configureMonitor(array $configs) {
$this->configs = $configs;
$init = \IDS_Init::init();
$init->setConfig($this->configs);
$this->monitor = new IdsMonitor($this->addInputs($this->configs), $init);
}
/**
*
* add input by name: post, get, request, cookie
*
* @param string $input
* @throws RuntimeException
*/
public function addRequest($input) {
if (!isset($this->configs['General'])) {
throw new \RuntimeException('The Monitor is not configured!');
}
$this->configs['General']['inputs'][] = $input;
$this->configureMonitor($this->configs);
}
private function addInputs(array $configs) {
$configuredInputs = $configs['General']['inputs'];
foreach ($configuredInputs as $index => $input) {
$configuredInputs[$index] = strtoupper($input);
}
$concreteInputs = array();
if (in_array(self::REQUEST_POST, $configuredInputs)) {
$concreteInputs[self::REQUEST_POST] = $this->request->request->all();
}
if (in_array(self::REQUEST_GET, $configuredInputs)) {
$concreteInputs[self::REQUEST_GET] = $this->request->query->all();
}
if (in_array(self::REQUEST_COOKIE, $configuredInputs)) {
$concreteInputs[self::REQUEST_COOKIE] = $this->request->cookies->all();
}
if (in_array(self::REQUEST_ALL, $configuredInputs)) {
$concreteInputs[self::REQUEST_ALL] = $this->request->request->all();
}
return $concreteInputs;
}
/**
* @return \IDS_Report
*/
public function run() {
if (count($this->configs) == 0 || $this->monitor === null) {
throw new \RuntimeException('problems with the monitor-object occured, the monitor is not configured correct');
}
return $this->monitor->run();
}
}
?>