-
Notifications
You must be signed in to change notification settings - Fork 0
/
EventBundle.php
61 lines (50 loc) · 1.79 KB
/
EventBundle.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
<?php
declare(strict_types=1);
namespace Pandawa\Bundle\EventBundle;
use Illuminate\Contracts\Events\Dispatcher as DispatcherContract;
use Illuminate\Events\Dispatcher;
use Pandawa\Bundle\FoundationBundle\Plugin\ImportConfigurationPlugin;
use Pandawa\Component\Event\EventBus;
use Pandawa\Component\Foundation\Bundle\Bundle;
use Pandawa\Contracts\Event\EventBusInterface;
use Pandawa\Contracts\Foundation\HasPluginInterface;
use RuntimeException;
/**
* @author Iqbal Maulana <iq.bluejack@gmail.com>
*/
class EventBundle extends Bundle implements HasPluginInterface
{
const EVENT_CACHE_CONFIG_KEY = 'pandawa.events';
public function boot(): void
{
$this->registerAliases();
}
public function configure(): void
{
$this->app->singleton('bus.event', function ($app) {
return tap(new EventBus($app['bus.factory.envelope'], $app), function (EventBus $eventBus) use ($app) {
$eventBus->setQueueResolver(function () use ($app) {
if (!$app->bound('queue')) {
throw new RuntimeException('Please install "pandawa/queue-bundle" to enable queue.');
}
return $app['queue'];
});
$eventBus->mergeMiddlewares($app['config']->get('event.middlewares', []));
});
});
$this->registerAliases();
}
protected function registerAliases(): void
{
$this->app->alias('bus.event', EventBusInterface::class);
$this->app->alias('bus.event', DispatcherContract::class);
$this->app->alias('bus.event', Dispatcher::class);
$this->app->alias('bus.event', 'events');
}
public function plugins(): array
{
return [
new ImportConfigurationPlugin(),
];
}
}