Completed
Push — master ( 3beeb1...c0c19b )
by Beñat
01:48
created

DomainEventsPublicationMiddleware::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 9
nc 2
nop 2
1
<?php
2
3
/*
4
 * This file is part of the Shared Kernel library.
5
 *
6
 * Copyright (c) 2016-present LIN3S <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace LIN3S\SharedKernel\Infrastructure\Application\Tactician;
13
14
use League\Tactician\Middleware;
15
use LIN3S\SharedKernel\Domain\Event\CollectlDomainEventsSubscriber;
16
use LIN3S\SharedKernel\Domain\Event\DomainEventPublisher;
17
18
/**
19
 * @author Beñat Espiña <[email protected]>
20
 */
21
class DomainEventsPublicationMiddleware implements Middleware
22
{
23
    public function execute($command, callable $next)
24
    {
25
        $domainEventPublisher = DomainEventPublisher::instance();
26
        $collectDomainEventsSubscriber = new CollectlDomainEventsSubscriber();
27
        $domainEventPublisher->subscribe($collectDomainEventsSubscriber);
28
29
        $returnValue = $next($command);
30
31
        $domainEvents = $collectDomainEventsSubscriber->events();
32
        foreach ($domainEvents as $domainEvent) {
33
            $domainEventPublisher->publish($domainEvent);
34
        }
35
36
        return $returnValue;
37
    }
38
}
39