Skip to content

Commit ec6c6ad

Browse files
committed
Invoke the BusServiceProvider when the BatchRepository service is initialized
1 parent 87cba3b commit ec6c6ad

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/MongoDBBusServiceProvider.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@
88
use Illuminate\Container\Container;
99
use Illuminate\Contracts\Support\DeferrableProvider;
1010
use Illuminate\Support\ServiceProvider;
11+
use InvalidArgumentException;
1112
use MongoDB\Laravel\Bus\MongoBatchRepository;
1213

14+
use function sprintf;
15+
1316
class 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

@@ -39,6 +49,7 @@ public function register()
3949
public function provides()
4050
{
4151
return [
52+
BatchRepository::class,
4253
MongoBatchRepository::class,
4354
];
4455
}

0 commit comments

Comments
 (0)