1
1
<?php
2
- /**
3
- * @category IRCBot
4
- * @package IRCBot_Handlers
5
- * @subpackage Events
6
- * @author Marlin Cremers <[email protected] >
7
- */
8
-
9
2
namespace Ircbot \Handler ;
10
3
11
4
use \Ircbot \Application \Debug ;
5
+ use \Symfony \Component \EventDispatcher \Event ;
12
6
13
7
/**
14
8
* The IRCBot event handler
17
11
* you can simply raise any event by calling the raiseEvent method
18
12
* or register a callback with any event by calling the addEventCallback method
19
13
*/
20
- class Events
14
+ class Events extends \ Symfony \ Component \ EventDispatcher \EventDispatcher
21
15
{
22
16
/**
23
17
* This variable contains all the callbacks registered with the events
@@ -42,6 +36,11 @@ public function raiseEvent($eventName, $data = null)
42
36
\Ircbot \Application::getInstance ()->getDebugger ()->log (
43
37
'Events ' , 'RaisedEvent ' , $ eventName , Debug::LEVEL_INFO
44
38
);
39
+ \Ircbot \Application::getInstance ()->getDebugger ()->log (
40
+ 'Events ' , 'Event ' , 'WARNING - This method is deprecated! '
41
+ . 'Use dispatch instead. ( ' . $ eventName . ') ' ,
42
+ Debug::LEVEL_WARN
43
+ );
45
44
}
46
45
foreach ($ this ->_callbacks as $ callback ) {
47
46
if ($ callback ['eventName ' ] == $ eventName ) {
@@ -80,6 +79,31 @@ public function addEventCallback($eventName, $callback)
80
79
'Events ' , 'AddCallback ' , $ eventName . ' => ' . $ callbackDisplay ,
81
80
Debug::LEVEL_DEBUG
82
81
);
82
+ \Ircbot \Application::getInstance ()->getDebugger ()->log (
83
+ 'Events ' , 'Callback ' , 'WARNING - This method is deprecated! '
84
+ . 'Use addListener instead. ( ' . $ eventName . ') ' ,
85
+ Debug::LEVEL_WARN
86
+ );
83
87
return $ this ;
84
88
}
89
+
90
+ public function addListener ($ eventName , $ listener , $ priority = 0 )
91
+ {
92
+ if (!$ this ->hasListeners ($ eventName )) {
93
+ $ this ->dispatch ('eventdispatcher.event_used. ' . $ eventName );
94
+ }
95
+ parent ::addListener ($ eventName , $ listener , $ priority );
96
+ }
97
+
98
+ protected function doDispatch ($ listeners , $ eventName , Event $ event )
99
+ {
100
+ if ($ eventName != 'loop.iterated ' ) {
101
+ \Ircbot \Application::getInstance ()->getDebugger ()->log (
102
+ 'Symfony ' , 'EventDispatcher ' , 'Dispatched event ' . $ eventName ,
103
+ Debug::LEVEL_INFO
104
+ );
105
+ }
106
+ parent ::doDispatch ($ listeners , $ eventName , $ event );
107
+ }
108
+
85
109
}
0 commit comments