@@ -77,7 +77,7 @@ public function getListeners($eventName = null)
77
77
}
78
78
79
79
$ sorted = array ();
80
- foreach ($ this ->listeners as $ eventName => $ listeners ) {
80
+ foreach (array_keys ( $ this ->listeners ) as $ eventName ) {
81
81
if (!isset ($ this ->sorted [$ eventName ])) {
82
82
$ this ->sortListeners ($ eventName );
83
83
}
@@ -103,16 +103,15 @@ public function hasListeners($eventName = null)
103
103
*/
104
104
public function addListener ($ eventNames , $ listener , $ priority = 0 )
105
105
{
106
- $ hash = spl_object_hash ($ listener );
107
106
foreach ((array ) $ eventNames as $ eventName ) {
108
107
if (!isset ($ this ->listeners [$ eventName ][$ priority ])) {
109
108
if (!isset ($ this ->listeners [$ eventName ])) {
110
109
$ this ->listeners [$ eventName ] = array ();
111
110
}
112
- $ this ->listeners [$ eventName ][$ priority ] = array ();
111
+ $ this ->listeners [$ eventName ][$ priority ] = new \ SplObjectStorage ();
113
112
}
114
113
115
- $ this ->listeners [$ eventName ][$ priority ][ $ hash ] = $ listener ;
114
+ $ this ->listeners [$ eventName ][$ priority ]-> attach ( $ listener) ;
116
115
unset($ this ->sorted [$ eventName ]);
117
116
}
118
117
}
@@ -127,10 +126,9 @@ public function removeListener($eventNames, $listener)
127
126
continue ;
128
127
}
129
128
130
- $ hash = spl_object_hash ($ listener );
131
129
foreach (array_keys ($ this ->listeners [$ eventName ]) as $ priority ) {
132
- if (isset ($ this ->listeners [$ eventName ][$ priority ][$ hash ])) {
133
- unset($ this ->listeners [$ eventName ][$ priority ][$ hash ], $ this ->sorted [$ eventName ]);
130
+ if (isset ($ this ->listeners [$ eventName ][$ priority ][$ listener ])) {
131
+ unset($ this ->listeners [$ eventName ][$ priority ][$ listener ], $ this ->sorted [$ eventName ]);
134
132
}
135
133
}
136
134
}
@@ -180,10 +178,13 @@ protected function triggerListener($listener, $eventName, Event $event)
180
178
private function sortListeners ($ eventName )
181
179
{
182
180
$ this ->sorted [$ eventName ] = array ();
183
-
184
181
if (isset ($ this ->listeners [$ eventName ])) {
185
182
krsort ($ this ->listeners [$ eventName ]);
186
- $ this ->sorted [$ eventName ] = array_values (call_user_func_array ('array_merge ' , $ this ->listeners [$ eventName ]));
183
+ foreach ($ this ->listeners [$ eventName ] as $ listeners ) {
184
+ foreach ($ listeners as $ listener ) {
185
+ $ this ->sorted [$ eventName ][] = $ listener ;
186
+ }
187
+ }
187
188
}
188
189
}
189
190
}
0 commit comments