Skip to content

Commit 51308c7

Browse files
flibidi67J-P
and
J-P
authored
fix debugbar for Lumen usage (#1796)
Co-authored-by: J-P <jpschreiber@sdv.fr>
1 parent 6a0c40a commit 51308c7

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

src/LaravelDebugbar.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,9 @@ public function __construct($app = null)
125125
$this->is_lumen = Str::contains($this->version, 'Lumen');
126126
if ($this->is_lumen) {
127127
$this->version = Str::betweenFirst($app->version(), '(', ')');
128+
} else {
129+
$this->setRequestIdGenerator(new RequestIdGenerator());
128130
}
129-
$this->setRequestIdGenerator(new RequestIdGenerator());
130131
}
131132

132133
/**
@@ -209,13 +210,16 @@ public function boot()
209210

210211
if ($this->shouldCollect('time', true)) {
211212
$startTime = $app['request']->server('REQUEST_TIME_FLOAT');
212-
$this->addCollector(new TimeDataCollector($startTime));
213+
214+
if (!$this->hasCollector('time')) {
215+
$this->addCollector(new TimeDataCollector($startTime));
216+
}
213217

214218
if ($config->get('debugbar.options.time.memory_usage')) {
215219
$this['time']->showMemoryUsage();
216220
}
217221

218-
if ($startTime) {
222+
if ($startTime && !$this->isLumen()) {
219223
$app->booted(
220224
function () use ($startTime) {
221225
$this->addMeasure('Booting', $startTime, microtime(true), [], 'time');

src/LumenServiceProvider.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,39 @@
33
namespace Barryvdh\Debugbar;
44

55
use Laravel\Lumen\Application;
6+
use DebugBar\DataCollector\TimeDataCollector;
67

78
class LumenServiceProvider extends ServiceProvider
89
{
910
/** @var Application */
1011
protected $app;
1112

13+
public function boot()
14+
{
15+
parent::boot();
16+
17+
$this->app->call(
18+
function () {
19+
$debugBar = $this->app->get(LaravelDebugbar::class);
20+
if ($debugBar->shouldCollect('time', true)) {
21+
$startTime = $this->app['request']->server('REQUEST_TIME_FLOAT');
22+
23+
if (!$debugBar->hasCollector('time')) {
24+
$debugBar->addCollector(new TimeDataCollector($startTime));
25+
}
26+
27+
if ($this->app['config']->get('debugbar.options.time.memory_usage')) {
28+
$debugBar['time']->showMemoryUsage();
29+
}
30+
31+
if ($startTime) {
32+
$debugBar->addMeasure('Booting', $startTime, microtime(true), [], 'time');
33+
}
34+
}
35+
}
36+
);
37+
}
38+
1239
/**
1340
* Get the active router.
1441
*

0 commit comments

Comments
 (0)