@@ -144,6 +144,9 @@ public function boot()
144
144
/** @var Application $app */
145
145
$ app = $ this ->app ;
146
146
147
+ /** @var \Illuminate\Events\Dispatcher|null $events */
148
+ $ events = isset ($ app ['events ' ]) ? $ app ['events ' ] : null ;
149
+
147
150
$ this ->editorTemplateLink = $ this ->app ['config ' ]->get ('debugbar.editor ' ) ?: null ;
148
151
$ this ->remoteServerReplacements = $ this ->getRemoteServerReplacements ();
149
152
@@ -220,24 +223,24 @@ function () use ($debugbar, $startTime) {
220
223
$ this ->addCollector (new RequestDataCollector ());
221
224
}
222
225
223
- if ($ this ->shouldCollect ('events ' , false ) && isset ( $ this -> app [ ' events ' ]) ) {
226
+ if ($ this ->shouldCollect ('events ' , false ) && $ events ) {
224
227
try {
225
228
$ startTime = $ app ['request ' ]->server ('REQUEST_TIME_FLOAT ' );
226
229
$ collectData = $ app ['config ' ]->get ('debugbar.options.events.data ' , false );
227
230
$ this ->addCollector (new EventCollector ($ startTime , $ collectData ));
228
- $ this -> app [ ' events ' ] ->subscribe ($ debugbar ['event ' ]);
231
+ $ events ->subscribe ($ this ['event ' ]);
229
232
} catch (Exception $ e ) {
230
233
$ this ->addCollectorException ('Cannot add EventCollector ' , $ e );
231
234
}
232
235
}
233
236
234
- if ($ this ->shouldCollect ('views ' , true ) && isset ( $ this -> app [ ' events ' ]) ) {
237
+ if ($ this ->shouldCollect ('views ' , true ) && $ events ) {
235
238
try {
236
239
$ collectData = $ this ->app ['config ' ]->get ('debugbar.options.views.data ' , true );
237
240
$ excludePaths = $ this ->app ['config ' ]->get ('debugbar.options.views.exclude_paths ' , []);
238
241
$ group = $ this ->app ['config ' ]->get ('debugbar.options.views.group ' , true );
239
242
$ this ->addCollector (new ViewCollector ($ collectData , $ excludePaths , $ group ));
240
- $ this -> app [ ' events ' ] ->listen (
243
+ $ events ->listen (
241
244
'composing:* ' ,
242
245
function ($ event , $ params ) {
243
246
$ this ['views ' ]->addView ($ params [0 ]);
@@ -289,10 +292,7 @@ function (\Illuminate\Log\Events\MessageLogged $log) use ($logger) {
289
292
}
290
293
}
291
294
292
- if ($ this ->shouldCollect ('db ' , true ) && isset ($ this ->app ['db ' ]) && isset ($ this ->app ['events ' ])) {
293
- /** @var \Illuminate\Events\Dispatcher $events */
294
- $ events = $ this ->app ['events ' ];
295
-
295
+ if ($ this ->shouldCollect ('db ' , true ) && isset ($ this ->app ['db ' ]) && $ events ) {
296
296
if (
297
297
$ debugbar ->hasCollector ('time ' ) && $ this ->app ['config ' ]->get (
298
298
'debugbar.options.db.timeline ' ,
@@ -415,10 +415,10 @@ function (\Illuminate\Database\Events\ConnectionEstablished $event) use ($queryC
415
415
}
416
416
}
417
417
418
- if ($ this ->shouldCollect ('models ' , true ) && isset ( $ this -> app [ ' events ' ]) ) {
418
+ if ($ this ->shouldCollect ('models ' , true ) && $ events ) {
419
419
try {
420
420
$ this ->addCollector (new ObjectCountCollector ('models ' ));
421
- $ this -> app [ ' events ' ] ->listen ('eloquent.retrieved:* ' , function ($ event , $ models ) {
421
+ $ events ->listen ('eloquent.retrieved:* ' , function ($ event , $ models ) {
422
422
foreach (array_filter ($ models ) as $ model ) {
423
423
$ this ['models ' ]->countClass ($ model );
424
424
}
@@ -436,11 +436,11 @@ function (\Illuminate\Database\Events\ConnectionEstablished $event) use ($queryC
436
436
}
437
437
}
438
438
439
- if ($ this ->shouldCollect ('mail ' , true ) && class_exists ('Illuminate\Mail\MailServiceProvider ' ) && isset ( $ this -> app [ ' events ' ]) ) {
439
+ if ($ this ->shouldCollect ('mail ' , true ) && class_exists ('Illuminate\Mail\MailServiceProvider ' ) && $ events ) {
440
440
try {
441
441
$ mailCollector = new SymfonyMailCollector ();
442
442
$ this ->addCollector ($ mailCollector );
443
- $ this -> app [ ' events ' ] ->listen (function (MessageSent $ event ) use ($ mailCollector ) {
443
+ $ events ->listen (function (MessageSent $ event ) use ($ mailCollector ) {
444
444
$ mailCollector ->addSymfonyMessage ($ event ->sent ->getSymfonySentMessage ());
445
445
});
446
446
@@ -517,22 +517,22 @@ public function __toString(): string
517
517
}
518
518
}
519
519
520
- if ($ this ->shouldCollect ('cache ' , false ) && isset ( $ this -> app [ ' events ' ]) ) {
520
+ if ($ this ->shouldCollect ('cache ' , false ) && $ events ) {
521
521
try {
522
522
$ collectValues = $ this ->app ['config ' ]->get ('debugbar.options.cache.values ' , true );
523
523
$ startTime = $ this ->app ['request ' ]->server ('REQUEST_TIME_FLOAT ' );
524
524
$ cacheCollector = new CacheCollector ($ startTime , $ collectValues );
525
525
$ this ->addCollector ($ cacheCollector );
526
- $ this -> app [ ' events ' ] ->subscribe ($ cacheCollector );
526
+ $ events ->subscribe ($ cacheCollector );
527
527
} catch (Exception $ e ) {
528
528
$ this ->addCollectorException ('Cannot add CacheCollector ' , $ e );
529
529
}
530
530
}
531
531
532
- if ($ this ->shouldCollect ('jobs ' , false ) && isset ( $ this -> app [ ' events ' ]) ) {
532
+ if ($ this ->shouldCollect ('jobs ' , false ) && $ events ) {
533
533
try {
534
534
$ this ->addCollector (new ObjectCountCollector ('jobs ' , 'briefcase ' ));
535
- $ this -> app [ ' events ' ] ->listen (\Illuminate \Queue \Events \JobQueued::class, function ($ event ) {
535
+ $ events ->listen (\Illuminate \Queue \Events \JobQueued::class, function ($ event ) {
536
536
$ this ['jobs ' ]->countClass ($ event ->job );
537
537
});
538
538
} catch (Exception $ e ) {
0 commit comments