8
8
use Illuminate \Container \Container ;
9
9
use Illuminate \Contracts \Support \DeferrableProvider ;
10
10
use Illuminate \Support \ServiceProvider ;
11
+ use InvalidArgumentException ;
11
12
use MongoDB \Laravel \Bus \MongoBatchRepository ;
12
13
14
+ use function sprintf ;
15
+
13
16
class MongoDBBusServiceProvider extends ServiceProvider implements DeferrableProvider
14
17
{
15
18
/**
@@ -18,14 +21,21 @@ class MongoDBBusServiceProvider extends ServiceProvider implements DeferrablePro
18
21
public function register ()
19
22
{
20
23
$ 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
+
21
30
return new MongoBatchRepository (
22
31
$ app ->make (BatchFactory::class),
23
- $ app -> make ( ' db ' )-> connection ( $ app -> config -> get ( ' queue.batching.database ' )) ,
32
+ $ connection ,
24
33
$ app ->config ->get ('queue.batching.collection ' , 'job_batches ' ),
25
34
);
26
35
});
27
36
28
- /** @see BusServiceProvider::registerBatchServices() */
37
+ /** The {@see BatchRepository} service is registered in {@see BusServiceProvider} */
38
+ $ this ->app ->register (BusServiceProvider::class);
29
39
$ this ->app ->extend (BatchRepository::class, function (BatchRepository $ repository , Container $ app ) {
30
40
$ driver = $ app ->config ->get ('queue.batching.driver ' );
31
41
0 commit comments