1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Recca0120\LaravelTracy; |
4
|
|
|
|
5
|
|
|
use Tracy\Bar; |
6
|
|
|
use Tracy\Debugger; |
7
|
|
|
use Tracy\BlueScreen; |
8
|
|
|
use Illuminate\Support\Arr; |
9
|
|
|
use Illuminate\Routing\Router; |
10
|
|
|
use Illuminate\Contracts\Http\Kernel; |
11
|
|
|
use Illuminate\Support\ServiceProvider; |
12
|
|
|
use Illuminate\Contracts\View\Factory as View; |
13
|
|
|
use Recca0120\LaravelTracy\Exceptions\Handler; |
14
|
|
|
use Recca0120\Terminal\TerminalServiceProvider; |
15
|
|
|
use Illuminate\Contracts\Debug\ExceptionHandler; |
16
|
|
|
use Recca0120\LaravelTracy\Middleware\RenderBar; |
17
|
|
|
|
18
|
|
|
class LaravelTracyServiceProvider extends ServiceProvider |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* Indicates if loading of the provider is deferred. |
22
|
|
|
* |
23
|
|
|
* @var bool |
24
|
|
|
*/ |
25
|
|
|
protected $defer = false; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* namespace. |
29
|
|
|
* |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
protected $namespace = 'Recca0120\LaravelTracy\Http\Controllers'; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* boot. |
36
|
|
|
* |
37
|
|
|
* @param DebuggerManager $debuggerManager |
|
|
|
|
38
|
|
|
* @param \Illuminate\Contracts\Http\Kernel $kernel |
39
|
|
|
* @param \Illuminate\Contracts\View\Factory $view |
40
|
|
|
* @param \Illuminate\Routing\Router $router |
41
|
|
|
*/ |
42
|
2 |
|
public function boot(Kernel $kernel, View $view, Router $router) |
43
|
|
|
{ |
44
|
2 |
|
$view->getEngineResolver() |
45
|
2 |
|
->resolve('blade') |
46
|
2 |
|
->getCompiler() |
47
|
|
|
->directive('bdump', function ($expression) { |
48
|
2 |
|
return "<?php \Tracy\Debugger::barDump({$expression}); ?>"; |
49
|
2 |
|
}); |
50
|
|
|
|
51
|
2 |
|
if ($this->app->runningInConsole() === true) { |
52
|
1 |
|
$this->publishes([__DIR__.'/../config/tracy.php' => config_path('tracy.php')], 'config'); |
53
|
|
|
|
54
|
1 |
|
return; |
55
|
|
|
} |
56
|
|
|
|
57
|
2 |
|
$config = $this->app['config']['tracy']; |
58
|
1 |
|
$enabled = Arr::get($config, 'enabled', true) === true; |
59
|
2 |
|
if ($enabled === false) { |
60
|
|
|
return; |
61
|
|
|
} |
62
|
|
|
|
63
|
1 |
|
$showException = Arr::get($config, 'showException', true); |
64
|
1 |
|
if ($showException === true) { |
65
|
|
|
$this->app->extend(ExceptionHandler::class, function ($exceptionHandler, $app) { |
66
|
1 |
|
return new Handler($exceptionHandler, $app[DebuggerManager::class]); |
67
|
1 |
|
}); |
68
|
1 |
|
} |
69
|
|
|
|
70
|
1 |
|
$showBar = Arr::get($config, 'showBar', true); |
71
|
1 |
|
if ($showBar === true) { |
72
|
1 |
|
$this->handleRoutes($router, Arr::get($config, 'route', [])); |
73
|
1 |
|
$kernel->prependMiddleware(RenderBar::class); |
74
|
1 |
|
} |
75
|
1 |
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Register the service provider. |
79
|
|
|
*/ |
80
|
1 |
|
public function register() |
81
|
|
|
{ |
82
|
1 |
|
$this->mergeConfigFrom(__DIR__.'/../config/tracy.php', 'tracy'); |
83
|
|
|
|
84
|
1 |
|
$config = Arr::get($this->app['config'], 'tracy'); |
85
|
|
|
|
86
|
1 |
|
if (Arr::get($config, 'panels.terminal') === true) { |
87
|
1 |
|
$this->app->register(TerminalServiceProvider::class); |
88
|
1 |
|
} |
89
|
|
|
|
90
|
|
|
$this->app->singleton(BlueScreen::class, function () { |
91
|
1 |
|
return Debugger::getBlueScreen(); |
92
|
1 |
|
}); |
93
|
|
|
|
94
|
|
|
$this->app->singleton(Bar::class, function ($app) use ($config) { |
95
|
1 |
|
return (new BarManager(Debugger::getBar(), $app['request'], $app)) |
96
|
1 |
|
->loadPanels(Arr::get($config, 'panels', [])) |
97
|
1 |
|
->getBar(); |
98
|
1 |
|
}); |
99
|
|
|
|
100
|
|
|
$this->app->singleton(DebuggerManager::class, function ($app) use ($config) { |
101
|
1 |
|
return (new DebuggerManager( |
102
|
1 |
|
DebuggerManager::init($config), |
103
|
1 |
|
$app[Bar::class], |
104
|
1 |
|
$app[BlueScreen::class], |
105
|
|
|
new Session |
106
|
1 |
|
))->setUrlGenerator($app['url']); |
107
|
1 |
|
}); |
108
|
1 |
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Get the services provided by the provider. |
112
|
|
|
* |
113
|
|
|
* @return array |
114
|
|
|
*/ |
115
|
1 |
|
public function provides() |
116
|
|
|
{ |
117
|
1 |
|
return [ExceptionHandler::class]; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* register routes. |
122
|
|
|
* |
123
|
|
|
* @param \Illuminate\Routing\Router $router |
124
|
|
|
* @param array $config |
125
|
|
|
*/ |
126
|
1 |
|
protected function handleRoutes(Router $router, $config = []) |
127
|
|
|
{ |
128
|
1 |
|
if ($this->app->routesAreCached() === false) { |
129
|
1 |
|
$router->group(array_merge([ |
130
|
1 |
|
'namespace' => $this->namespace, |
131
|
1 |
|
], $config), function (Router $router) { |
132
|
|
|
require __DIR__.'/../routes/web.php'; |
133
|
1 |
|
}); |
134
|
1 |
|
} |
135
|
1 |
|
} |
136
|
|
|
} |
137
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.