@@ -144,6 +144,9 @@ public function boot()
144144 /** @var Application $app */
145145 $ app = $ this ->app ;
146146
147+ /** @var \Illuminate\Events\Dispatcher|null $events */
148+ $ events = isset ($ app ['events ' ]) ? $ app ['events ' ] : null ;
149+
147150 $ this ->editorTemplateLink = $ this ->app ['config ' ]->get ('debugbar.editor ' ) ?: null ;
148151 $ this ->remoteServerReplacements = $ this ->getRemoteServerReplacements ();
149152
@@ -220,24 +223,24 @@ function () use ($debugbar, $startTime) {
220223 $ this ->addCollector (new RequestDataCollector ());
221224 }
222225
223- if ($ this ->shouldCollect ('events ' , false ) && isset ( $ this -> app [ ' events ' ]) ) {
226+ if ($ this ->shouldCollect ('events ' , false ) && $ events ) {
224227 try {
225228 $ startTime = $ app ['request ' ]->server ('REQUEST_TIME_FLOAT ' );
226229 $ collectData = $ app ['config ' ]->get ('debugbar.options.events.data ' , false );
227230 $ this ->addCollector (new EventCollector ($ startTime , $ collectData ));
228- $ this -> app [ ' events ' ] ->subscribe ($ debugbar ['event ' ]);
231+ $ events ->subscribe ($ this ['event ' ]);
229232 } catch (Exception $ e ) {
230233 $ this ->addCollectorException ('Cannot add EventCollector ' , $ e );
231234 }
232235 }
233236
234- if ($ this ->shouldCollect ('views ' , true ) && isset ( $ this -> app [ ' events ' ]) ) {
237+ if ($ this ->shouldCollect ('views ' , true ) && $ events ) {
235238 try {
236239 $ collectData = $ this ->app ['config ' ]->get ('debugbar.options.views.data ' , true );
237240 $ excludePaths = $ this ->app ['config ' ]->get ('debugbar.options.views.exclude_paths ' , []);
238241 $ group = $ this ->app ['config ' ]->get ('debugbar.options.views.group ' , true );
239242 $ this ->addCollector (new ViewCollector ($ collectData , $ excludePaths , $ group ));
240- $ this -> app [ ' events ' ] ->listen (
243+ $ events ->listen (
241244 'composing:* ' ,
242245 function ($ event , $ params ) {
243246 $ this ['views ' ]->addView ($ params [0 ]);
@@ -289,10 +292,7 @@ function (\Illuminate\Log\Events\MessageLogged $log) use ($logger) {
289292 }
290293 }
291294
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 ) {
296296 if (
297297 $ debugbar ->hasCollector ('time ' ) && $ this ->app ['config ' ]->get (
298298 'debugbar.options.db.timeline ' ,
@@ -415,10 +415,10 @@ function (\Illuminate\Database\Events\ConnectionEstablished $event) use ($queryC
415415 }
416416 }
417417
418- if ($ this ->shouldCollect ('models ' , true ) && isset ( $ this -> app [ ' events ' ]) ) {
418+ if ($ this ->shouldCollect ('models ' , true ) && $ events ) {
419419 try {
420420 $ this ->addCollector (new ObjectCountCollector ('models ' ));
421- $ this -> app [ ' events ' ] ->listen ('eloquent.retrieved:* ' , function ($ event , $ models ) {
421+ $ events ->listen ('eloquent.retrieved:* ' , function ($ event , $ models ) {
422422 foreach (array_filter ($ models ) as $ model ) {
423423 $ this ['models ' ]->countClass ($ model );
424424 }
@@ -436,11 +436,11 @@ function (\Illuminate\Database\Events\ConnectionEstablished $event) use ($queryC
436436 }
437437 }
438438
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 ) {
440440 try {
441441 $ mailCollector = new SymfonyMailCollector ();
442442 $ this ->addCollector ($ mailCollector );
443- $ this -> app [ ' events ' ] ->listen (function (MessageSent $ event ) use ($ mailCollector ) {
443+ $ events ->listen (function (MessageSent $ event ) use ($ mailCollector ) {
444444 $ mailCollector ->addSymfonyMessage ($ event ->sent ->getSymfonySentMessage ());
445445 });
446446
@@ -517,22 +517,22 @@ public function __toString(): string
517517 }
518518 }
519519
520- if ($ this ->shouldCollect ('cache ' , false ) && isset ( $ this -> app [ ' events ' ]) ) {
520+ if ($ this ->shouldCollect ('cache ' , false ) && $ events ) {
521521 try {
522522 $ collectValues = $ this ->app ['config ' ]->get ('debugbar.options.cache.values ' , true );
523523 $ startTime = $ this ->app ['request ' ]->server ('REQUEST_TIME_FLOAT ' );
524524 $ cacheCollector = new CacheCollector ($ startTime , $ collectValues );
525525 $ this ->addCollector ($ cacheCollector );
526- $ this -> app [ ' events ' ] ->subscribe ($ cacheCollector );
526+ $ events ->subscribe ($ cacheCollector );
527527 } catch (Exception $ e ) {
528528 $ this ->addCollectorException ('Cannot add CacheCollector ' , $ e );
529529 }
530530 }
531531
532- if ($ this ->shouldCollect ('jobs ' , false ) && isset ( $ this -> app [ ' events ' ]) ) {
532+ if ($ this ->shouldCollect ('jobs ' , false ) && $ events ) {
533533 try {
534534 $ 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 ) {
536536 $ this ['jobs ' ]->countClass ($ event ->job );
537537 });
538538 } catch (Exception $ e ) {
0 commit comments