ServiceProvider::boot()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 9
cp 0
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Softonic\AmqpConsumer;
4
5
use Illuminate\Support\Arr;
6
use Illuminate\Support\ServiceProvider as LaravelServiceProvider;
7
8
class ServiceProvider extends LaravelServiceProvider
9
{
10
    /**
11
     * @var string
12
     */
13
    protected $packageName = 'amqp-consumer';
14
15
    /**
16
     * Bootstrap the application services.
17
     */
18
    public function boot()
19
    {
20
        $this->publishes(
21
            [
22
                __DIR__ . '/../config/' . $this->packageName . '.php' => config_path($this->packageName . '.php'),
23
            ],
24
            'config'
25
        );
26
    }
27
28
    /**
29
     * Register the application services.
30
     */
31
    public function register()
32
    {
33
        $this->mergeConfigFrom(__DIR__ . '/../config/' . $this->packageName . '.php', $this->packageName);
34
35
        $this->app->bind(AmqpListener::class, function () {
36
            $amqpProperties  = config('amqp-consumer')['properties'];
37
            $messageHandlers = config('amqp-consumer')['message_handlers'];
38
39
            $routingKeys = array_unique(Arr::flatten($messageHandlers));
40
41
            $amqpProperties['routing'] = $routingKeys;
42
43
            return new AmqpListener(
44
                config('amqp-consumer')['queue'],
45
                $amqpProperties
46
            );
47
        });
48
49
        $this->app->bind(AmqpHandler::class, function () {
50
            return new AmqpHandler(
51
                config('amqp-consumer')['message_handlers']
52
            );
53
        });
54
55
        $this->commands([AmqpListener::class]);
56
    }
57
}
58