/
RabbitEventsServiceProvider.php
66 lines (56 loc) · 1.48 KB
/
RabbitEventsServiceProvider.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
<?php
namespace RabbitEvents\Foundation;
use Illuminate\Support\Arr;
use Illuminate\Support\ServiceProvider;
use RabbitEvents\Foundation\Commands\InstallCommand;
use RabbitEvents\Foundation\Support\Sender;
class RabbitEventsServiceProvider extends ServiceProvider
{
/**
* Register any events for your application.
*
* @return void
*/
public function boot(): void
{
$config = $this->resolveConfig();
$this->app->singleton(
Context::class,
static fn($app) => new Context(new Connection($config))
);
}
public function register(): void
{
$this->registerCommands();
$this->registerPublishing();
}
/**
* @return array
* @throws \RuntimeException
*/
protected function resolveConfig(): array
{
$config = $this->app['config']['rabbitevents'];
$defaultConnection = Arr::get($config, 'default');
return Arr::get($config, "connections.$defaultConnection", []);
}
/**
* Register RabbitEvent's publishing.
*
* @return void
*/
protected function registerPublishing()
{
if ($this->app->runningInConsole()) {
$this->publishes([
__DIR__ . '/config/rabbitevents.php' => config_path('rabbitevents.php'),
], 'rabbitevents-config');
}
}
protected function registerCommands()
{
$this->commands([
InstallCommand::class
]);
}
}