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

Bus   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 35
c 0
b 0
f 0
ccs 0
cts 14
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A publish() 0 6 2
A getRegisteredEventListeners() 0 4 1
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