1
|
|
|
<?php
|
2
|
|
|
|
3
|
|
|
namespace Nip\DebugBar;
|
4
|
|
|
|
5
|
|
|
use Nip\Container\ServiceProviders\Providers\AbstractSignatureServiceProvider;
|
6
|
|
|
use Nip\Container\ServiceProviders\Providers\BootableServiceProviderInterface;
|
7
|
|
|
use Nip\DebugBar\Middleware\DebugbarMiddleware;
|
8
|
|
|
use Nip\Http\Kernel\Kernel;
|
9
|
|
|
use Nip\Http\Kernel\KernelInterface;
|
10
|
|
|
|
11
|
|
|
/**
|
12
|
|
|
* Class DebugBarServiceProvider
|
13
|
|
|
* @package Nip\DebugBar
|
14
|
|
|
*/
|
15
|
|
|
class DebugBarServiceProvider extends AbstractSignatureServiceProvider implements BootableServiceProviderInterface
|
16
|
|
|
{
|
17
|
|
|
|
18
|
|
|
/**
|
19
|
|
|
* @inheritdoc
|
20
|
|
|
*/
|
21
|
|
|
public function provides()
|
22
|
|
|
{
|
23
|
|
|
return ['debugbar'];
|
24
|
|
|
}
|
25
|
|
|
|
26
|
|
|
/**
|
27
|
|
|
* @inheritdoc
|
28
|
|
|
*/
|
29
|
|
|
public function register()
|
30
|
|
|
{
|
31
|
|
|
$this->getContainer()->alias(StandardDebugBar::class, DebugBar::class);
|
32
|
|
|
|
33
|
|
|
$this->getContainer()->share('debugbar', function () {
|
34
|
|
|
$debugbar = $this->getContainer()->get(DebugBar::class);
|
35
|
|
|
return $debugbar;
|
36
|
|
|
});
|
37
|
|
|
}
|
38
|
|
|
|
39
|
|
|
/**
|
40
|
|
|
* Bootstrap the application events.
|
41
|
|
|
*
|
42
|
|
|
* @return void
|
43
|
|
|
*/
|
44
|
|
|
public function boot()
|
45
|
|
|
{
|
46
|
|
|
$app = $this->getContainer()->get('app');
|
47
|
|
|
|
48
|
|
|
// If enabled is null, set from the app.debug value
|
|
|
|
|
49
|
|
|
// $enabled = $this->app['config']->get('debugbar.enabled');
|
50
|
|
|
|
51
|
|
|
// if (is_null($enabled)) {
|
|
|
|
|
52
|
|
|
$enabled = $this->checkAppDebug();
|
53
|
|
|
// }
|
54
|
|
|
|
55
|
|
|
if (!$enabled) {
|
56
|
|
|
return;
|
57
|
|
|
}
|
58
|
|
|
|
59
|
|
|
/** @var DebugBar $debugBar */
|
60
|
|
|
$debugBar = $app->get('debugbar');
|
61
|
|
|
$debugBar->enable();
|
62
|
|
|
$debugBar->boot();
|
63
|
|
|
|
64
|
|
|
$this->registerMiddleware(DebugbarMiddleware::class);
|
65
|
|
|
}
|
66
|
|
|
|
67
|
|
|
/**
|
68
|
|
|
* Check the App Debug status
|
69
|
|
|
*/
|
70
|
|
|
protected function checkAppDebug()
|
71
|
|
|
{
|
72
|
|
|
return $this->getContainer()->get('config')->get('app.debug');
|
73
|
|
|
}
|
74
|
|
|
|
75
|
|
|
/**
|
76
|
|
|
* Register the Debugbar Middleware
|
77
|
|
|
*
|
78
|
|
|
* @param string $middleware
|
79
|
|
|
*/
|
80
|
|
|
protected function registerMiddleware($middleware)
|
81
|
|
|
{
|
82
|
|
|
/** @var Kernel $kernel */
|
83
|
|
|
$kernel = $this->getContainer()->get(KernelInterface::class);
|
84
|
|
|
$kernel->prependMiddleware($middleware);
|
85
|
|
|
}
|
86
|
|
|
}
|
87
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.