Completed
Push — master ( 67a91e...657487 )
by Peter
06:52
created

DomainEventMiddlewareHandler::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
/**
4
 * GpsLab component.
5
 *
6
 * @author    Peter Gribanov <[email protected]>
7
 * @copyright Copyright (c) 2011, Peter Gribanov
8
 * @license   http://opensource.org/licenses/MIT
9
 */
10
11
namespace GpsLab\Component\Middleware\DomainEvent\Handler;
12
13
use GpsLab\Component\Middleware\Handler\MiddlewareHandler;
14
use GpsLab\Domain\Event\Bus\EventBusInterface;
15
use GpsLab\Domain\Event\EventInterface;
16
17
class DomainEventMiddlewareHandler implements MiddlewareHandler
18
{
19
    /**
20
     * @var EventBusInterface
21
     */
22
    private $bus;
23
24
    /**
25
     * @param EventBusInterface $bus
26
     */
27
    public function __construct(EventBusInterface $bus)
28
    {
29
        $this->bus = $bus;
30
    }
31
32
    /**
33
     * @param mixed    $message
34
     * @param callable $next
35
     *
36
     * @return mixed
37
     */
38
    public function handle($message, callable $next)
39
    {
40
        if ($message instanceof EventInterface) {
41
            return $next($this->bus->publish($message));
42
        }
43
44
        return $next($message);
45
    }
46
}
47