-
Notifications
You must be signed in to change notification settings - Fork 2
/
controller.php
68 lines (52 loc) · 2.13 KB
/
controller.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
<?php
namespace Concrete\Package\PhpDebugbar;
use DebugBar\StandardDebugBar;
use Illuminate\Filesystem\Filesystem;
use Request;
class Controller extends \Package
{
protected $pkgHandle = 'php_debugbar';
protected $appVersionRequired = '5.7.4';
protected $pkgVersion = '0.9.1';
public function getPackageDescription()
{
return t("Enables the use of PHP Debugbar in concrete5.");
}
public function getPackageName()
{
return t("PHP Debugbar");
}
public function install()
{
if (!file_exists(__DIR__ . '/vendor')) {
throw new \Exception('Please install composer dependencies before you install this package. ' .
'Run `cd "' . __DIR__ . '" && composer install`');
}
parent::install();
// Make sure we load everything.
$this->on_start();
}
public function on_start()
{
$req = Request::getInstance();
if(!$req->isXmlHttpRequest()) {
$filesystem = new Filesystem();
$filesystem->getRequire(__DIR__ . '/vendor/autoload.php');
\Core::make('app')->instance('debugbar', $bar = new StandardDebugBar());
$debugStack = new \Doctrine\DBAL\Logging\DebugStack();
// Cache javascript renderer object.
$renderer = $bar->getJavascriptRenderer(DIR_REL . '/packages/php_debugbar/vendor/maximebf/debugbar/src/DebugBar/Resources');
\Database::connection()->getConfiguration()->setSQLLogger($debugStack);
$bar->addCollector(new \DebugBar\Bridge\DoctrineCollector($debugStack));
\View::getInstance()->addHeaderItem($renderer->renderHead());
\Events::addListener('on_page_output', function ($event) use ($renderer) {
if(is_object(\Page::getCurrentPage())) {
$output = $renderer->render();
$originalContent = $event->getArgument('contents');
$newContent = str_replace('</body>', $output . '</body>', $originalContent);
$event->setArgument('contents', $newContent);
}
});
}
}
}