Skip to content

Commit

Permalink
Invoke the BusServiceProvider when the BatchRepository service is ini…
Browse files Browse the repository at this point in the history
…tialized
  • Loading branch information
GromNaN committed Jul 24, 2024
1 parent 87cba3b commit 38f73ef
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/MongoDBBusServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
use Illuminate\Container\Container;
use Illuminate\Contracts\Support\DeferrableProvider;
use Illuminate\Support\ServiceProvider;
use InvalidArgumentException;
use MongoDB\Laravel\Bus\MongoBatchRepository;

use function sprintf;

class MongoDBBusServiceProvider extends ServiceProvider implements DeferrableProvider
{
/**
Expand All @@ -18,14 +21,21 @@ class MongoDBBusServiceProvider extends ServiceProvider implements DeferrablePro
public function register()
{
$this->app->singleton(MongoBatchRepository::class, function (Container $app) {
$connection = $app->make('db')->connection($app->config->get('queue.batching.database'));

Check failure

Code scanning / PHPStan

Ignored error pattern #^Access to an undefined property Illuminate\Container\Container::$config.$# in path /home/runner/work/laravel-mongodb/laravel-mongodb/src/MongoDBBusServiceProvider.php is expected to occur 3 times, but occurred 4 times. Error

Ignored error pattern #^Access to an undefined property Illuminate\Container\Container::$config.$# in path /home/runner/work/laravel-mongodb/laravel-mongodb/src/MongoDBBusServiceProvider.php is expected to occur 3 times, but occurred 4 times.

if (! $connection instanceof Connection) {
throw new InvalidArgumentException(sprintf('The "mongodb" batch driver requires a MongoDB connection. The "%s" connection uses the "%s" driver.', $connection->getName(), $connection->getDriverName()));
}

return new MongoBatchRepository(
$app->make(BatchFactory::class),
$app->make('db')->connection($app->config->get('queue.batching.database')),
$app->config->get('queue.batching.collection', 'job_batches'),
);
});

/** @see BusServiceProvider::registerBatchServices() */
/** The {@see BatchRepository} service is registered in {@see BusServiceProvider} */
$this->app->register(BusServiceProvider::class);
$this->app->extend(BatchRepository::class, function (BatchRepository $repository, Container $app) {
$driver = $app->config->get('queue.batching.driver');

Expand All @@ -39,6 +49,7 @@ public function register()
public function provides()
{
return [
BatchRepository::class,
MongoBatchRepository::class,
];
}
Expand Down

0 comments on commit 38f73ef

Please sign in to comment.