16
16
use Symfony \Component \DependencyInjection \Compiler \CompilerPassInterface ;
17
17
use Symfony \Component \DependencyInjection \Exception \InvalidArgumentException ;
18
18
use Symfony \Component \EventDispatcher \EventDispatcher ;
19
+ use Symfony \Component \EventDispatcher \EventSubscriberInterface ;
19
20
20
21
/**
21
22
* Compiler pass to register tagged services for an event dispatcher.
@@ -105,8 +106,8 @@ public function process(ContainerBuilder $container)
105
106
}
106
107
$ container ->addObjectResource ($ class );
107
108
108
- $ r = new \ ReflectionClass ( $ class) ;
109
- $ extractingDispatcher ->addSubscriber ($ r -> newInstanceWithoutConstructor () );
109
+ ExtractingEventDispatcher:: $ subscriber = $ class ;
110
+ $ extractingDispatcher ->addSubscriber ($ extractingDispatcher );
110
111
foreach ($ extractingDispatcher ->listeners as $ args ) {
111
112
$ args [1 ] = new ClosureProxyArgument ($ id , $ args [1 ]);
112
113
$ definition ->addMethodCall ('addListener ' , $ args );
@@ -119,12 +120,21 @@ public function process(ContainerBuilder $container)
119
120
/**
120
121
* @internal
121
122
*/
122
- class ExtractingEventDispatcher extends EventDispatcher
123
+ class ExtractingEventDispatcher extends EventDispatcher implements EventSubscriberInterface
123
124
{
124
125
public $ listeners = array ();
125
126
127
+ public static $ subscriber ;
128
+
126
129
public function addListener ($ eventName , $ listener , $ priority = 0 )
127
130
{
128
131
$ this ->listeners [] = array ($ eventName , $ listener [1 ], $ priority );
129
132
}
133
+
134
+ public static function getSubscribedEvents ()
135
+ {
136
+ $ callback = array (self ::$ subscriber , 'getSubscribedEvents ' );
137
+
138
+ return $ callback ();
139
+ }
130
140
}
0 commit comments