forked from mongodb/laravel-mongodb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMongoDBBusServiceProvider.php
46 lines (40 loc) · 1.41 KB
/
MongoDBBusServiceProvider.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
namespace MongoDB\Laravel;
use Illuminate\Bus\BatchFactory;
use Illuminate\Bus\BatchRepository;
use Illuminate\Bus\BusServiceProvider;
use Illuminate\Container\Container;
use Illuminate\Contracts\Support\DeferrableProvider;
use Illuminate\Support\ServiceProvider;
use MongoDB\Laravel\Bus\MongoBatchRepository;
class MongoDBBusServiceProvider extends ServiceProvider implements DeferrableProvider
{
/**
* Register the service provider.
*/
public function register()
{
$this->app->singleton(MongoBatchRepository::class, function (Container $app) {
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() */
$this->app->extend(BatchRepository::class, function (BatchRepository $repository, Container $app) {
$driver = $app->config->get('queue.batching.driver');
return match ($driver) {
'mongodb' => $app->make(MongoBatchRepository::class),
default => $repository,
};
});
}
public function provides()
{
return [
BatchRepository::class,
MongoBatchRepository::class,
];
}
}