|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace WhoopsSilex; |
|
4
|
|
|
|
|
5
|
|
|
use Pimple\Container; |
|
6
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
7
|
|
|
use Whoops\Handler\Handler; |
|
8
|
|
|
use Whoops\Handler\PrettyPageHandler; |
|
9
|
|
|
|
|
10
|
|
|
class RequestHandler extends Handler |
|
11
|
|
|
{ |
|
12
|
|
|
private $container; |
|
13
|
|
|
|
|
14
|
|
|
public function __construct(Container $container) |
|
15
|
|
|
{ |
|
16
|
|
|
$this->container = $container; |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @inherit |
|
21
|
|
|
*/ |
|
22
|
|
|
public function handle() |
|
23
|
|
|
{ |
|
24
|
|
|
$errorPageHandler = $this->container["whoops.error_page_handler"]; |
|
25
|
|
|
if (!($errorPageHandler instanceof PrettyPageHandler)) { |
|
26
|
|
|
return; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
$request = $this->request(); |
|
30
|
|
|
|
|
31
|
|
|
if ($request === null) { |
|
32
|
|
|
// This error occurred too early in the application's life |
|
33
|
|
|
// and the request instance is not yet available. |
|
34
|
|
|
return; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
$this->addRequestInfo($request, $errorPageHandler); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
private function request() |
|
41
|
|
|
{ |
|
42
|
|
|
$container = $this->container; |
|
43
|
|
|
|
|
44
|
|
|
if (!$container->offsetExists('request_stack')) { |
|
45
|
|
|
// This error occurred too early in the application's life |
|
46
|
|
|
// and the request stack instance is not yet available. |
|
47
|
|
|
return; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
return $container['request_stack']->getCurrentRequest(); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
private function addRequestInfo(Request $request, PrettyPageHandler $handler) |
|
54
|
|
|
{ |
|
55
|
|
|
$handler->addDataTable('Request', array( |
|
56
|
|
|
'URI' => $request->getUri(), |
|
57
|
|
|
'Request URI' => $request->getRequestUri(), |
|
58
|
|
|
'Path Info' => $request->getPathInfo(), |
|
59
|
|
|
'Query String' => $request->getQueryString() ?: '<none>', |
|
60
|
|
|
'HTTP Method' => $request->getMethod(), |
|
61
|
|
|
'Script Name' => $request->getScriptName(), |
|
62
|
|
|
'Base Path' => $request->getBasePath(), |
|
63
|
|
|
'Base URL' => $request->getBaseUrl(), |
|
64
|
|
|
'Scheme' => $request->getScheme(), |
|
65
|
|
|
'Port' => $request->getPort(), |
|
66
|
|
|
'Host' => $request->getHost(), |
|
67
|
|
|
)); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|