|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Honeybadger; |
|
4
|
|
|
|
|
5
|
|
|
use Honeybadger\Concerns\FiltersData; |
|
6
|
|
|
use Symfony\Component\HttpFoundation\Request as FoundationRequest; |
|
7
|
|
|
|
|
8
|
|
|
class Request |
|
9
|
|
|
{ |
|
10
|
|
|
use FiltersData; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @var \Symfony\Component\HttpFoundation\Request |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $request; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var array |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $options; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
|
24
|
|
|
* @param array $options |
|
25
|
|
|
*/ |
|
26
|
|
|
public function __construct(FoundationRequest $request = null, array $options = []) |
|
27
|
|
|
{ |
|
28
|
|
|
$this->request = $request ?? FoundationRequest::createFromGlobals(); |
|
29
|
|
|
$this->options = $options; |
|
30
|
|
|
|
|
31
|
|
|
$this->keysToFilter = [ |
|
32
|
|
|
'password', |
|
33
|
|
|
'password_confirmation', |
|
34
|
|
|
]; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @return string |
|
39
|
|
|
*/ |
|
40
|
|
|
public function url() : string |
|
41
|
|
|
{ |
|
42
|
|
|
return $this->httpRequest() |
|
43
|
|
|
? $this->request->getUri() |
|
44
|
|
|
: ''; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @return array |
|
49
|
|
|
*/ |
|
50
|
|
|
public function params() : array |
|
51
|
|
|
{ |
|
52
|
|
|
if (! $this->httpRequest()) { |
|
53
|
|
|
return []; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
return [ |
|
57
|
|
|
'method' => $this->request->getMethod(), |
|
58
|
|
|
'query' => $this->filter($this->request->query->all()), |
|
59
|
|
|
'data' => $this->filter($this->data()), |
|
60
|
|
|
]; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @return array |
|
65
|
|
|
*/ |
|
66
|
|
|
public function session() : array |
|
67
|
|
|
{ |
|
68
|
|
|
return $this->request->hasSession() && $this->request->getSession() |
|
69
|
|
|
? $this->filter($this->request->getSession()->all()) |
|
70
|
|
|
: []; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @return string |
|
75
|
|
|
*/ |
|
76
|
|
|
public function component() : string |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->getOptionsByKey('component'); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @return string |
|
83
|
|
|
*/ |
|
84
|
|
|
public function action() : string |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->getOptionsByKey('action'); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @return bool |
|
91
|
|
|
*/ |
|
92
|
|
|
private function httpRequest() : bool |
|
93
|
|
|
{ |
|
94
|
|
|
return isset($_SERVER['REQUEST_METHOD']); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @return array |
|
99
|
|
|
*/ |
|
100
|
|
|
private function data() : array |
|
101
|
|
|
{ |
|
102
|
|
|
if ($this->request->getContentType() === 'json') { |
|
103
|
|
|
return json_decode($this->request->getContent(), true) ?: []; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
if ($this->request->getContentType() === 'form') { |
|
107
|
|
|
return $this->request->request->all(); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
return []; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
private function getOptionsByKey($key) : string |
|
114
|
|
|
{ |
|
115
|
|
|
return isset($this->options[$key]) ? $this->options[$key] : ''; |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|