Completed
Push — master ( 38f90d...223a4c )
by Peter
02:18
created

Bus::publish()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
ccs 0
cts 6
cp 0
rs 9.4285
cc 2
eloc 3
nc 2
nop 1
crap 6
1
<?php
2
/**
3
 * GpsLab component.
4
 *
5
 * @author    Peter Gribanov <[email protected]>
6
 * @copyright Copyright (c) 2016, Peter Gribanov
7
 * @license   http://opensource.org/licenses/MIT
8
 */
9
namespace GpsLab\Domain\Event\Bus;
10
11
use GpsLab\Domain\Event\EventInterface;
12
use GpsLab\Domain\Event\Listener\ListenerCollection;
13
use GpsLab\Domain\Event\Listener\Locator\LocatorInterface;
14
15
class Bus implements BusInterface
16
{
17
    /**
18
     * @var LocatorInterface
19
     */
20
    private $locator;
21
22
    /**
23
     * @param LocatorInterface $locator
24
     */
25
    public function __construct(LocatorInterface $locator)
26
    {
27
        $this->locator = $locator;
28
    }
29
30
    /**
31
     * Publishes the event $event to every EventListener that wants to.
32
     *
33
     * @param EventInterface $event
34
     */
35
    public function publish(EventInterface $event)
36
    {
37
        foreach ($this->locator->getListenersForEvent($event) as $listener) {
38
            $listener->handle($event);
39
        }
40
    }
41
42
    /**
43
     * @return ListenerCollection
44
     */
45
    public function getRegisteredEventListeners()
46
    {
47
        return $this->locator->getRegisteredEventListeners();
48
    }
49
}
50