HorizonServiceProvider::boot()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Noitran\Lumen\Horizon;
4
5
use Noitran\Lumen\Horizon\Connectors\RabbitMQConnector;
6
use Illuminate\Contracts\Events\Dispatcher;
7
use Illuminate\Support\ServiceProvider;
8
9
class HorizonServiceProvider extends ServiceProvider
10
{
11
    /**
12
     * All of the Horizon event / listener mappings.
13
     *
14
     * @var array
15
     */
16
    protected $events = [
17
        \Illuminate\Queue\Events\JobFailed::class => [
18
            Listeners\MarshalFailedEvent::class,
19
        ],
20
    ];
21
22
    /**
23
     * Register the Horizon job events.
24
     *
25
     * @return void
26
     */
27
    protected function registerEvents(): void
28
    {
29
        $events = $this->app->make(Dispatcher::class);
30
31
        foreach ($this->events as $event => $listeners) {
32
            foreach ($listeners as $listener) {
33
                $events->listen($event, $listener);
34
            }
35
        }
36
    }
37
38
    /**
39
     * Register the custom queue connectors for Horizon.
40
     *
41
     * @return void
42
     */
43
    protected function registerQueueConnectors(): void
44
    {
45
        $queue = $this->app['queue'];
46
47
        $queue->addConnector('rabbitmq', function () {
48
            return new RabbitMQConnector($this->app['events']);
49
        });
50
    }
51
52
    /**
53
     * Register any application services.
54
     *
55
     * @return void
56
     */
57
    public function boot(): void
58
    {
59
        $this->registerEvents();
60
        $this->registerQueueConnectors();
61
    }
62
}
63