Skip to content

Commit 895dcc7

Browse files
authored
PHPORM-222 Register the BusServiceProvider when BatchRepository is built (#3071)
1 parent 7e809df commit 895dcc7

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/MongoDBBusServiceProvider.php

+12-2
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

0 commit comments

Comments
 (0)