Skip to content

Commit 2f2685c

Browse files
committed
added redis storage
fixed namespace reviewed fixed namespace new line reviewed used original redisstorage class removed duplicated redisstorage
1 parent 64a7a5e commit 2f2685c

File tree

2 files changed

+40
-16
lines changed

2 files changed

+40
-16
lines changed

src/LaravelDebugBar.php

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use DebugBar\DataCollector\RequestDataCollector;
2222
use DebugBar\DataCollector\TimeDataCollector;
2323
use DebugBar\DebugBar;
24+
use DebugBar\Storage\RedisStorage;
2425
use Exception;
2526

2627
use Symfony\Component\HttpFoundation\Request;
@@ -48,7 +49,7 @@ class LaravelDebugbar extends DebugBar
4849
* @var \Illuminate\Foundation\Application
4950
*/
5051
protected $app;
51-
52+
5253
/**
5354
* Normalized Laravel Version
5455
*
@@ -104,11 +105,7 @@ public function boot()
104105
/** @var \Illuminate\Foundation\Application $app */
105106
$app = $this->app;
106107

107-
if ($this->app['config']->get('laravel-debugbar::config.storage.enabled')) {
108-
$path = $this->app['config']->get('laravel-debugbar::config.storage.path');
109-
$storage = new FilesystemStorage($this->app['files'], $path);
110-
$debugbar->setStorage($storage);
111-
}
108+
$this->selectStorage($debugbar);
112109

113110
if ($this->shouldCollect('phpinfo', true)) {
114111
$this->addCollector(new PhpInfoCollector());
@@ -128,7 +125,7 @@ function () use ($debugbar, $startTime) {
128125
}
129126
);
130127

131-
//Check if App::before is already called..
128+
//Check if App::before is already called..
132129
if ($this->checkVersion('4.1-dev', '>=') && $this->app->isBooted()) {
133130
$debugbar->startMeasure('application', 'Application');
134131
} else {
@@ -157,11 +154,11 @@ function () use ($debugbar) {
157154
);
158155
$this->addCollector($exceptionCollector);
159156
if ($this->checkVersion('5.0-dev', '<')) {
160-
$this->app->error(
161-
function (Exception $exception) use ($exceptionCollector) {
162-
$exceptionCollector->addException($exception);
163-
}
164-
);
157+
$this->app->error(
158+
function (Exception $exception) use ($exceptionCollector) {
159+
$exceptionCollector->addException($exception);
160+
}
161+
);
165162
}
166163
} catch (\Exception $e) {
167164
}
@@ -284,7 +281,7 @@ function ($level, $message, $context) use ($logger) {
284281
if ($this->app['config']->get('laravel-debugbar::config.options.db.backtrace')) {
285282
$queryCollector->setFindSource(true);
286283
}
287-
284+
288285
if ($this->app['config']->get('laravel-debugbar::config.options.db.explain.enabled')) {
289286
$types = $this->app['config']->get('laravel-debugbar::config.options.db.explain.types');
290287
$queryCollector->setExplainSource(true, $types);
@@ -520,7 +517,7 @@ public function modifyResponse($request, $response)
520517
}
521518
} elseif (
522519
($response->headers->has('Content-Type') and
523-
strpos($response->headers->get('Content-Type'), 'html') === false)
520+
strpos($response->headers->get('Content-Type'), 'html') === false)
524521
|| 'html' !== $request->format()
525522
) {
526523
try {
@@ -747,7 +744,7 @@ public function addMessage($message, $label = 'info')
747744
$collector->addMessage($message, $label);
748745
}
749746
}
750-
747+
751748
/**
752749
* Check the version of Laravel
753750
*
@@ -757,6 +754,32 @@ public function addMessage($message, $label = 'info')
757754
*/
758755
protected function checkVersion($version, $operator = ">=")
759756
{
760-
return version_compare($this->version, $version, $operator);
757+
return version_compare($this->version, $version, $operator);
758+
}
759+
760+
/**
761+
* @param $debugbar
762+
*/
763+
protected function selectStorage($debugbar)
764+
{
765+
if ($this->app['config']->get('laravel-debugbar::config.storage.enabled')) {
766+
if ($this->app['config']->get('laravel-debugbar::config.storage.driver')) {
767+
$driver = $this->app['config']->get('laravel-debugbar::config.storage.driver');
768+
769+
switch ($driver) {
770+
case 'redis':
771+
$storage = new RedisStorage($this->app['redis']->connection());
772+
break;
773+
774+
case 'file':
775+
default:
776+
$path = $this->app['config']->get('laravel-debugbar::config.storage.path');
777+
$storage = new FilesystemStorage($this->app['files'], $path);
778+
break;
779+
}
780+
}
781+
782+
$debugbar->setStorage($storage);
783+
}
761784
}
762785
}

src/config/config.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
|
2727
*/
2828
'storage' => array(
29+
'driver' => 'file', // redis, file
2930
'enabled' => true,
3031
'path' => storage_path() . '/debugbar',
3132
),

0 commit comments

Comments
 (0)