1 | <?php |
||
56 | class EventDispatcher |
||
57 | { |
||
58 | /** |
||
59 | * @var array |
||
60 | */ |
||
61 | protected $observers; |
||
62 | |||
63 | /** |
||
64 | * @var EventDispatcher |
||
65 | */ |
||
66 | protected static $instance; |
||
67 | |||
68 | /** |
||
69 | * The __constructor is private because the dispatcher is a singleton |
||
70 | * |
||
71 | * @return void |
||
|
|||
72 | */ |
||
73 | protected function __construct() |
||
85 | |||
86 | /** |
||
87 | * Returns all registered event types. |
||
88 | * |
||
89 | * @return array array with registered events. |
||
90 | */ |
||
91 | protected function getEvents() |
||
95 | |||
96 | /** |
||
97 | * This method can be used to add an observer for an event to the dispatcher |
||
98 | * |
||
99 | * @param EventObserverInterface $observer_object |
||
100 | * @param string $observer_method |
||
101 | * @param string $event |
||
102 | * |
||
103 | * @return void |
||
104 | */ |
||
105 | 4 | public function addObserver(EventObserverInterface $observer_object, $observer_method, $event) |
|
109 | |||
110 | /** |
||
111 | * Enables checking whether a certain event is observed by anyone |
||
112 | * |
||
113 | * @param string $event |
||
114 | * |
||
115 | * @return boolean |
||
116 | */ |
||
117 | public function hasObserver($event) |
||
118 | { |
||
119 | return isset($this->observers[$event]) && count($this->observers[$event]) > 0; |
||
120 | } |
||
121 | |||
122 | /** |
||
123 | * This method should be used to post a event to the dispatcher. Each |
||
124 | * registered observer will be notified about the event. |
||
125 | * |
||
126 | * @param string $event |
||
127 | * @param string $group |
||
128 | * @param mixed $attachedData |
||
129 | * |
||
130 | * @return void |
||
131 | */ |
||
132 | 4 | public function post($event, $group, $attachedData) |
|
140 | |||
141 | /** |
||
142 | * Returns the instance of the dispatcher singleton |
||
143 | * |
||
144 | * @return EventDispatcher |
||
145 | */ |
||
146 | public static function getInstance() |
||
155 | } |
||
156 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.