Skip to content

Commit 6eb8034

Browse files
committed
Remove session dependancy
1 parent 71b13b9 commit 6eb8034

File tree

1 file changed

+36
-31
lines changed

1 file changed

+36
-31
lines changed

src/LaravelDebugbar.php

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use Exception;
2828

2929
use Illuminate\Contracts\Foundation\Application;
30+
use Illuminate\Session\SessionManager;
3031
use Symfony\Component\HttpFoundation\Request;
3132
use Symfony\Component\HttpFoundation\Response;
3233

@@ -107,8 +108,8 @@ public function boot()
107108
return;
108109
}
109110

110-
if ($this->isDebugbarRequest()) {
111-
$this->app['session']->reflash();
111+
if ($this->isDebugbarRequest() && $this->app->bound(SessionManager::class)) {
112+
$this->app->make(SessionManager::class)->reflash();
112113
}
113114

114115
/** @var \Barryvdh\Debugbar\LaravelDebugbar $debugbar */
@@ -133,14 +134,14 @@ public function boot()
133134

134135
if ( ! $this->isLumen()) {
135136
$this->app->booted(
136-
function () use ($debugbar, $startTime) {
137-
if ($startTime) {
138-
$debugbar['time']->addMeasure('Booting', $startTime, microtime(true));
139-
}
140-
}
137+
function () use ($debugbar, $startTime) {
138+
if ($startTime) {
139+
$debugbar['time']->addMeasure('Booting', $startTime, microtime(true));
140+
}
141+
}
141142
);
142143
}
143-
144+
144145
$debugbar->startMeasure('application', 'Application');
145146
}
146147

@@ -446,7 +447,6 @@ public function getJavascriptRenderer($baseUrl = null, $basePath = null)
446447
{
447448
if ($this->jsRenderer === null) {
448449
$this->jsRenderer = new JavascriptRenderer($this, $baseUrl, $basePath);
449-
$this->jsRenderer->setUrlGenerator($this->app['url']);
450450
}
451451
return $this->jsRenderer;
452452
}
@@ -464,7 +464,7 @@ public function modifyResponse(Request $request, Response $response)
464464
if ($app->runningInConsole() || !$this->isEnabled() || $this->isDebugbarRequest()) {
465465
return $response;
466466
}
467-
467+
468468
// Show the Http Response Exception in the Debugbar, when available
469469
if (isset($response->exception)) {
470470
$this->addException($response->exception);
@@ -486,23 +486,28 @@ public function modifyResponse(Request $request, Response $response)
486486
}
487487
}
488488

489-
/** @var \Illuminate\Session\SessionManager $sessionManager */
490-
$sessionManager = $app['session'];
491-
$httpDriver = new SymfonyHttpDriver($sessionManager, $response);
492-
$this->setHttpDriver($httpDriver);
489+
if ($this->app->bound(SessionManager::class)){
493490

494-
if ($this->shouldCollect('session')) {
495-
try {
496-
$this->addCollector(new SessionCollector($sessionManager));
497-
} catch (\Exception $e) {
498-
$this->addException(
499-
new Exception(
500-
'Cannot add SessionCollector to Laravel Debugbar: ' . $e->getMessage(),
501-
$e->getCode(),
502-
$e
503-
)
504-
);
491+
/** @var \Illuminate\Session\SessionManager $sessionManager */
492+
$sessionManager = $app->make(SessionManager::class);
493+
$httpDriver = new SymfonyHttpDriver($sessionManager, $response);
494+
$this->setHttpDriver($httpDriver);
495+
496+
if ($this->shouldCollect('session')) {
497+
try {
498+
$this->addCollector(new SessionCollector($sessionManager));
499+
} catch (\Exception $e) {
500+
$this->addException(
501+
new Exception(
502+
'Cannot add SessionCollector to Laravel Debugbar: ' . $e->getMessage(),
503+
$e->getCode(),
504+
$e
505+
)
506+
);
507+
}
505508
}
509+
} else {
510+
$sessionManager = null;
506511
}
507512

508513
if ($this->shouldCollect('symfony_request', true) && !$this->hasCollector('request')) {
@@ -525,11 +530,11 @@ public function modifyResponse(Request $request, Response $response)
525530
$this->addCollector(new ClockworkCollector($request, $response, $sessionManager));
526531
} catch (\Exception $e) {
527532
$this->addException(
528-
new Exception(
529-
'Cannot add ClockworkCollector to Laravel Debugbar: ' . $e->getMessage(),
530-
$e->getCode(),
531-
$e
532-
)
533+
new Exception(
534+
'Cannot add ClockworkCollector to Laravel Debugbar: ' . $e->getMessage(),
535+
$e->getCode(),
536+
$e
537+
)
533538
);
534539
}
535540

@@ -666,7 +671,7 @@ public function injectDebugbar(Response $response)
666671

667672
$renderer = $this->getJavascriptRenderer();
668673
if ($this->getStorage()) {
669-
$openHandlerUrl = $this->app['url']->route('debugbar.openhandler');
674+
$openHandlerUrl = route('debugbar.openhandler');
670675
$renderer->setOpenHandlerUrl($openHandlerUrl);
671676
}
672677

0 commit comments

Comments
 (0)