1 | <?php |
||
10 | class SimpleEmitter implements MutableEmitter |
||
11 | { |
||
12 | |||
13 | /** @var array */ |
||
14 | private $listeners = []; |
||
15 | |||
16 | /** @var EventNameExtractor */ |
||
17 | private $eventNameExtractor; |
||
18 | |||
19 | /** |
||
20 | * SimpleEventBus constructor. |
||
21 | * @param EventNameExtractor $eventNameExtractor |
||
22 | * @param Listener[][] $listeners |
||
23 | */ |
||
24 | 8 | public function __construct(EventNameExtractor $eventNameExtractor, array $listeners = []) |
|
33 | |||
34 | /** |
||
35 | * @param object $event |
||
36 | * @return void |
||
37 | */ |
||
38 | 7 | public function emit($event) |
|
47 | |||
48 | /** |
||
49 | * @param string $eventName |
||
50 | * @param Listener $listener |
||
51 | * @return Subscription |
||
52 | */ |
||
53 | 8 | public function addListener($eventName, Listener $listener) |
|
61 | |||
62 | /** |
||
63 | * @param string $eventName |
||
64 | * @param Listener $listener |
||
65 | * @return bool |
||
66 | */ |
||
67 | 4 | public function removeListener($eventName, Listener $listener) |
|
78 | |||
79 | /** |
||
80 | * @param $event |
||
81 | * @return string |
||
82 | */ |
||
83 | 7 | private function extractEventName($event) |
|
87 | |||
88 | /** |
||
89 | * @param string $eventName |
||
90 | * @return Listener[] |
||
91 | */ |
||
92 | 8 | private function getEventListeners($eventName) |
|
97 | } |
||
98 |