DomainEventListener::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Damax\Common\Bridge\Symfony\Bundle\Listener;
6
7
use Damax\Common\Domain\EventPublisher\EventPublisher;
8
use Symfony\Component\Console\ConsoleEvents;
9
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
10
use Symfony\Component\HttpKernel\KernelEvents;
11
12
class DomainEventListener implements EventSubscriberInterface
13
{
14
    private $publisher;
15
16
    public function __construct(EventPublisher $publisher)
17
    {
18
        $this->publisher = $publisher;
19
    }
20
21
    public static function getSubscribedEvents(): array
22
    {
23
        return [
24
            KernelEvents::RESPONSE => ['onKernelResponse', 1024],
25
            KernelEvents::EXCEPTION => ['onKernelException', 1024],
26
            ConsoleEvents::TERMINATE => ['onConsoleTerminate', 1024],
27
            ConsoleEvents::ERROR => ['onConsoleError', 1024],
28
        ];
29
    }
30
31
    public function onKernelResponse(): void
32
    {
33
        $this->publisher->publish();
34
    }
35
36
    public function onKernelException(): void
37
    {
38
        $this->publisher->discard();
39
    }
40
41
    public function onConsoleTerminate(): void
42
    {
43
        $this->publisher->publish();
44
    }
45
46
    public function onConsoleError(): void
47
    {
48
        $this->publisher->discard();
49
    }
50
}
51