-
Notifications
You must be signed in to change notification settings - Fork 0
/
BusBundle.php
77 lines (64 loc) · 2.18 KB
/
BusBundle.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
declare(strict_types=1);
namespace Pandawa\Bundle\BusBundle;
use Illuminate\Bus\BatchFactory;
use Illuminate\Bus\BatchRepository;
use Illuminate\Bus\DatabaseBatchRepository;
use Illuminate\Contracts\Config\Repository as Config;
use Pandawa\Bundle\DependencyInjectionBundle\Plugin\ImportServicesPlugin;
use Pandawa\Bundle\FoundationBundle\Plugin\ImportConfigurationPlugin;
use Pandawa\Component\Foundation\Bundle\Bundle;
use Pandawa\Contracts\Bus\BusInterface;
use Pandawa\Contracts\Bus\Message\RegistryInterface;
use Pandawa\Contracts\Foundation\HasPluginInterface;
/**
* @author Iqbal Maulana <iq.bluejack@gmail.com>
*/
class BusBundle extends Bundle implements HasPluginInterface
{
const MESSAGE_CONFIG_KEY = 'bus.messages';
const HANDLER_CONFIG_KEY = 'bus.handlers';
const PANDAWA_MESSAGE_CONFIG_KEY = 'pandawa.messages';
const PANDAWA_HANDLER_CONFIG_KEY = 'pandawa.handlers';
public function boot(): void
{
$this->app->booted(function () {
$this->registry()->load(
$this->config()->get(static::MESSAGE_CONFIG_KEY, [])
);
$this->bus()->map(
$this->config()->get(static::HANDLER_CONFIG_KEY, [])
);
});
}
public function configure(): void
{
$this->app->singleton(BatchRepository::class, DatabaseBatchRepository::class);
$this->app->singleton(DatabaseBatchRepository::class, function ($app) {
return new DatabaseBatchRepository(
$app->make(BatchFactory::class),
$app->make('db')->connection($app->config->get('queue.batching.database')),
$app->config->get('queue.batching.table', 'job_batches')
);
});
}
public function plugins(): array
{
return [
new ImportConfigurationPlugin(),
new ImportServicesPlugin(),
];
}
protected function config(): Config
{
return $this->app['config'];
}
protected function registry(): RegistryInterface
{
return $this->app[RegistryInterface::class];
}
protected function bus(): BusInterface
{
return $this->app[BusInterface::class];
}
}