Skip to content

Commit f13cbb9

Browse files
committed
[EventDispatcher] Moves the logic of addSubscriberService to the compiler pass
1 parent 4e0021b commit f13cbb9

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

src/Symfony/Component/EventDispatcher/ContainerAwareEventDispatcher.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public function addSubscriberService($serviceId, $class)
144144
$this->listenerIds[$eventName][] = array($serviceId, $params, 0);
145145
} elseif (is_string($params[0])) {
146146
$this->listenerIds[$eventName][] = array($serviceId, $params[0], isset($params[1]) ? $params[1] : 0);
147-
} else {
147+
} elseif (is_array($params[0])) {
148148
foreach ($params as $listener) {
149149
$this->listenerIds[$eventName][] = array($serviceId, $listener[0], isset($listener[1]) ? $listener[1] : 0);
150150
}

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

+11-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,17 @@ public function process(ContainerBuilder $container)
100100
throw new \InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, $interface));
101101
}
102102

103-
$definition->addMethodCall('addSubscriberService', array($id, $class));
103+
foreach ($class::getSubscribedEvents() as $eventName => $params) {
104+
if (is_string($params)) {
105+
$definition->addMethodCall('addListenerService', array($eventName, array($id, $params), 0));
106+
} elseif (is_string($params[0])) {
107+
$definition->addMethodCall('addListenerService', array($eventName, array($id, $params[0]), isset($params[1]) ? $params[1] : 0));
108+
} elseif (is_array($params[0])) {
109+
foreach ($params as $listener) {
110+
$definition->addMethodCall('addListenerService', array($eventName, array($id, $listener[0]), isset($listener[1]) ? $listener[1] : 0));
111+
}
112+
}
113+
}
104114
}
105115
}
106116
}

src/Symfony/Component/EventDispatcher/Tests/DependencyInjection/RegisterListenersPassTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -138,5 +138,6 @@ class SubscriberService implements \Symfony\Component\EventDispatcher\EventSubsc
138138
{
139139
public static function getSubscribedEvents()
140140
{
141+
return array();
141142
}
142143
}

0 commit comments

Comments
 (0)