Skip to content

Commit 34eeffb

Browse files
nicolas-grekaschalasr
authored andcommitted
[EventDispatcher] Fix abstract event subscribers registration
1 parent b632ca8 commit 34eeffb

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php

+13-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1717
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
1818
use Symfony\Component\EventDispatcher\EventDispatcher;
19+
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1920

2021
/**
2122
* Compiler pass to register tagged services for an event dispatcher.
@@ -105,8 +106,8 @@ public function process(ContainerBuilder $container)
105106
}
106107
$container->addObjectResource($class);
107108

108-
$r = new \ReflectionClass($class);
109-
$extractingDispatcher->addSubscriber($r->newInstanceWithoutConstructor());
109+
ExtractingEventDispatcher::$subscriber = $class;
110+
$extractingDispatcher->addSubscriber($extractingDispatcher);
110111
foreach ($extractingDispatcher->listeners as $args) {
111112
$args[1] = new ClosureProxyArgument($id, $args[1]);
112113
$definition->addMethodCall('addListener', $args);
@@ -119,12 +120,21 @@ public function process(ContainerBuilder $container)
119120
/**
120121
* @internal
121122
*/
122-
class ExtractingEventDispatcher extends EventDispatcher
123+
class ExtractingEventDispatcher extends EventDispatcher implements EventSubscriberInterface
123124
{
124125
public $listeners = array();
125126

127+
public static $subscriber;
128+
126129
public function addListener($eventName, $listener, $priority = 0)
127130
{
128131
$this->listeners[] = array($eventName, $listener[1], $priority);
129132
}
133+
134+
public static function getSubscribedEvents()
135+
{
136+
$callback = array(self::$subscriber, 'getSubscribedEvents');
137+
138+
return $callback();
139+
}
130140
}

0 commit comments

Comments
 (0)