forked from codeigniter4/CodeIgniter4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDebugToolbar.php
More file actions
76 lines (62 loc) · 1.88 KB
/
Copy pathDebugToolbar.php
File metadata and controls
76 lines (62 loc) · 1.88 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
<?php namespace App\Filters;
use CodeIgniter\Filters\FilterInterface;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Config\App;
use Config\Services;
class DebugToolbar implements FilterInterface
{
/**
* We don't need to do anything here.
*
* @param RequestInterface|\CodeIgniter\HTTP\IncomingRequest $request
*
* @return mixed
*/
public function before(RequestInterface $request)
{
}
//--------------------------------------------------------------------
/**
* If the debug flag is set (CI_DEBUG) then collect performance
* and debug information and display it in a toolbar.
*
* @param RequestInterface|\CodeIgniter\HTTP\IncomingRequest $request
* @param ResponseInterface|\CodeIgniter\HTTP\Response $response
*
* @return mixed
*/
public function after(RequestInterface $request, ResponseInterface $response)
{
$format = $response->getHeaderLine('content-type');
if ( ! is_cli() && CI_DEBUG && strpos($format, 'html') !== false)
{
global $app;
$toolbar = Services::toolbar(new App());
$stats = $app->getPerformanceStats();
$output = $toolbar->run(
$stats['startTime'],
$stats['totalTime'],
$stats['startMemory'],
$request,
$response
);
helper(['filesystem', 'url']);
// Updated to time() so we can get history
$time = time();
write_file(WRITEPATH .'debugbar/'.'debugbar_' . $time, $output, 'w+');
$script = PHP_EOL
. '<script type="text/javascript" id="debugbar_loader" '
. 'data-time="' . $time . '" '
. 'src="' . rtrim(site_url(), '/') . '?debugbar"></script>'
. PHP_EOL;
if (strpos($response->getBody(), '</body>') !== false)
{
return $response->setBody(str_replace('</body>', $script . '</body>',
$response->getBody()));
}
return $response->appendBody($script);
}
}
//--------------------------------------------------------------------
}