88use Illuminate \Container \Container ;
99use Illuminate \Contracts \Support \DeferrableProvider ;
1010use Illuminate \Support \ServiceProvider ;
11+ use InvalidArgumentException ;
1112use MongoDB \Laravel \Bus \MongoBatchRepository ;
1213
14+ use function sprintf ;
15+
1316class MongoDBBusServiceProvider extends ServiceProvider implements DeferrableProvider
1417{
1518 /**
@@ -18,14 +21,21 @@ class MongoDBBusServiceProvider extends ServiceProvider implements DeferrablePro
1821 public function register ()
1922 {
2023 $ this ->app ->singleton (MongoBatchRepository::class, function (Container $ app ) {
24+ $ connection = $ app ->make ('db ' )->connection ($ app ->config ->get ('queue.batching.database ' ));
25+
26+ if (! $ connection instanceof Connection) {
27+ throw new InvalidArgumentException (sprintf ('The "mongodb" batch driver requires a MongoDB connection. The "%s" connection uses the "%s" driver. ' , $ connection ->getName (), $ connection ->getDriverName ()));
28+ }
29+
2130 return new MongoBatchRepository (
2231 $ app ->make (BatchFactory::class),
23- $ app -> make ( ' db ' )-> connection ( $ app -> config -> get ( ' queue.batching.database ' )) ,
32+ $ connection ,
2433 $ app ->config ->get ('queue.batching.collection ' , 'job_batches ' ),
2534 );
2635 });
2736
28- /** @see BusServiceProvider::registerBatchServices() */
37+ /** The {@see BatchRepository} service is registered in {@see BusServiceProvider} */
38+ $ this ->app ->register (BusServiceProvider::class);
2939 $ this ->app ->extend (BatchRepository::class, function (BatchRepository $ repository , Container $ app ) {
3040 $ driver = $ app ->config ->get ('queue.batching.driver ' );
3141
0 commit comments