1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LeKoala\DebugBar; |
4
|
|
|
|
5
|
|
|
use LeKoala\DebugBar\DebugBar; |
6
|
|
|
use SilverStripe\Control\Director; |
7
|
|
|
use SilverStripe\Control\HTTPRequest; |
8
|
|
|
use SilverStripe\Control\HTTPResponse; |
9
|
|
|
use SilverStripe\Control\RequestFilter as BaseRequestFilter; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* A request filter to log pre request time |
13
|
|
|
*/ |
14
|
|
|
class RequestFilter implements BaseRequestFilter |
|
|
|
|
15
|
|
|
{ |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Filter executed before a request processes |
19
|
|
|
* |
20
|
|
|
* {@inheritDoc} |
21
|
|
|
*/ |
22
|
|
|
public function preRequest(HTTPRequest $request) |
|
|
|
|
23
|
|
|
{ |
24
|
|
|
DebugBar::withDebugBar(function (DebugBar\DebugBar $debugbar) { |
25
|
|
|
/* @var $timeData DebugBar\DataCollector\TimeDataCollector */ |
26
|
|
|
$timeData = $debugbar['time']; |
27
|
|
|
if (!$timeData) { |
28
|
|
|
return; |
29
|
|
|
} |
30
|
|
|
if (isset($_SERVER['REQUEST_TIME_FLOAT'])) { |
31
|
|
|
$timeData = $debugbar['time']; |
32
|
|
|
$timeData->addMeasure( |
33
|
|
|
"framework boot", |
34
|
|
|
$_SERVER['REQUEST_TIME_FLOAT'], |
35
|
|
|
microtime(true) |
36
|
|
|
); |
37
|
|
|
} |
38
|
|
|
$timeData->startMeasure("pre_request", "pre request"); |
39
|
|
|
}); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Filter executed AFTER a request |
44
|
|
|
* |
45
|
|
|
* {@inheritDoc} |
46
|
|
|
*/ |
47
|
|
|
public function postRequest(HTTPRequest $request, HTTPResponse $response) |
48
|
|
|
{ |
49
|
|
|
$debugbar = DebugBar::getDebugBar(); |
50
|
|
|
if (!$debugbar) { |
51
|
|
|
return; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
// All queries have been displayed |
55
|
|
|
if (DebugBar::getShowQueries()) { |
56
|
|
|
exit(); |
|
|
|
|
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$script = DebugBar::renderDebugBar(); |
60
|
|
|
|
61
|
|
|
// If the bar is not renderable, return early |
62
|
|
|
if (!$script) { |
63
|
|
|
return; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
// Inject init script into the HTML response |
67
|
|
|
$body = $response->getBody(); |
68
|
|
|
if (strpos($body, '</body>') !== false) { |
69
|
|
|
$body = str_replace('</body>', $script . '</body>', $body); |
70
|
|
|
$response->setBody($body); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
// Ajax support |
74
|
|
|
if (Director::is_ajax() && !headers_sent()) { |
75
|
|
|
if (DebugBar::isAdminUrl() && !DebugBar::config()->enabled_in_admin) { |
76
|
|
|
return; |
77
|
|
|
} |
78
|
|
|
// Skip anything that is not a GET request |
79
|
|
|
if (!$request->isGET()) { |
80
|
|
|
return; |
81
|
|
|
} |
82
|
|
|
// Always enable in admin because everything is mostly loaded through ajax |
83
|
|
|
if (DebugBar::config()->ajax || DebugBar::isAdminUrl()) { |
84
|
|
|
$headers = $debugbar->getDataAsHeaders(); |
85
|
|
|
|
86
|
|
|
// Prevent throwing js errors in case header size is too large |
87
|
|
|
if (is_array($headers)) { |
88
|
|
|
$debugbar->sendDataInHeaders(); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.