1 | <?php |
||
13 | final class ProjectEnabledDispatcher implements EventDispatcher |
||
14 | { |
||
15 | /** |
||
16 | * @var array |
||
17 | */ |
||
18 | private $listeners = []; |
||
19 | |||
20 | /** |
||
21 | * @param string $eventName |
||
22 | * @param array $arguments |
||
23 | * @param bool $runProjectionsOnly |
||
24 | */ |
||
25 | 21 | public function dispatch($eventName, array $arguments, $runProjectionsOnly = false) |
|
36 | |||
37 | /** |
||
38 | * @param string $eventName |
||
39 | * @param callable $callable |
||
40 | * @param int $priority |
||
41 | */ |
||
42 | 21 | public function addListener($eventName, callable $callable, $priority = 0) |
|
48 | |||
49 | |||
50 | /** |
||
51 | * @param Subscriber $subscriber |
||
52 | * @return void |
||
53 | */ |
||
54 | 6 | public function addSubscriber(Subscriber $subscriber) |
|
55 | { |
||
56 | 6 | foreach ($subscriber->getSubscribedEvents() as $eventName => $params) { |
|
57 | 6 | if (is_string($params)) { |
|
58 | 3 | $this->addListener($eventName, array($subscriber, $params)); |
|
59 | 6 | } elseif (is_string($params[0])) { |
|
60 | 6 | $this->addListener($eventName, array($subscriber, $params[0]), isset($params[1]) ? $params[1] : 0); |
|
61 | 6 | } else { |
|
62 | 3 | foreach ($params as $listener) { |
|
63 | 3 | $this->addListener($eventName, array($subscriber, $listener[0]), isset($listener[1]) ? $listener[1] : 0); |
|
64 | 3 | } |
|
65 | } |
||
66 | 6 | } |
|
67 | 6 | } |
|
68 | |||
69 | /** |
||
70 | * @param $runProjectionsOnly |
||
71 | * @param $listener |
||
72 | * @return bool |
||
73 | */ |
||
74 | 18 | protected function listenerCanRun($runProjectionsOnly, $listener) |
|
78 | |||
79 | /** |
||
80 | * @param $eventName |
||
81 | * @return array |
||
82 | */ |
||
83 | 18 | protected function getListenersInOrder($eventName) |
|
94 | |||
95 | /** |
||
96 | * Sorts the internal list of listeners for the given event by priority. |
||
97 | * |
||
98 | * @param string $eventName The name of the event. |
||
99 | */ |
||
100 | 18 | private function sortListeners($eventName) |
|
107 | } |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: