21
21
use DebugBar \DataCollector \RequestDataCollector ;
22
22
use DebugBar \DataCollector \TimeDataCollector ;
23
23
use DebugBar \DebugBar ;
24
+ use DebugBar \Storage \RedisStorage ;
24
25
use Exception ;
25
26
26
27
use Symfony \Component \HttpFoundation \Request ;
@@ -48,7 +49,7 @@ class LaravelDebugbar extends DebugBar
48
49
* @var \Illuminate\Foundation\Application
49
50
*/
50
51
protected $ app ;
51
-
52
+
52
53
/**
53
54
* Normalized Laravel Version
54
55
*
@@ -104,11 +105,7 @@ public function boot()
104
105
/** @var \Illuminate\Foundation\Application $app */
105
106
$ app = $ this ->app ;
106
107
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 );
112
109
113
110
if ($ this ->shouldCollect ('phpinfo ' , true )) {
114
111
$ this ->addCollector (new PhpInfoCollector ());
@@ -128,7 +125,7 @@ function () use ($debugbar, $startTime) {
128
125
}
129
126
);
130
127
131
- //Check if App::before is already called..
128
+ //Check if App::before is already called..
132
129
if ($ this ->checkVersion ('4.1-dev ' , '>= ' ) && $ this ->app ->isBooted ()) {
133
130
$ debugbar ->startMeasure ('application ' , 'Application ' );
134
131
} else {
@@ -157,11 +154,11 @@ function () use ($debugbar) {
157
154
);
158
155
$ this ->addCollector ($ exceptionCollector );
159
156
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
+ );
165
162
}
166
163
} catch (\Exception $ e ) {
167
164
}
@@ -284,7 +281,7 @@ function ($level, $message, $context) use ($logger) {
284
281
if ($ this ->app ['config ' ]->get ('laravel-debugbar::config.options.db.backtrace ' )) {
285
282
$ queryCollector ->setFindSource (true );
286
283
}
287
-
284
+
288
285
if ($ this ->app ['config ' ]->get ('laravel-debugbar::config.options.db.explain.enabled ' )) {
289
286
$ types = $ this ->app ['config ' ]->get ('laravel-debugbar::config.options.db.explain.types ' );
290
287
$ queryCollector ->setExplainSource (true , $ types );
@@ -520,7 +517,7 @@ public function modifyResponse($request, $response)
520
517
}
521
518
} elseif (
522
519
($ response ->headers ->has ('Content-Type ' ) and
523
- strpos ($ response ->headers ->get ('Content-Type ' ), 'html ' ) === false )
520
+ strpos ($ response ->headers ->get ('Content-Type ' ), 'html ' ) === false )
524
521
|| 'html ' !== $ request ->format ()
525
522
) {
526
523
try {
@@ -747,7 +744,7 @@ public function addMessage($message, $label = 'info')
747
744
$ collector ->addMessage ($ message , $ label );
748
745
}
749
746
}
750
-
747
+
751
748
/**
752
749
* Check the version of Laravel
753
750
*
@@ -757,6 +754,32 @@ public function addMessage($message, $label = 'info')
757
754
*/
758
755
protected function checkVersion ($ version , $ operator = ">= " )
759
756
{
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
+ }
761
784
}
762
785
}
0 commit comments