Skip to content

[EventDispatcher] Moves the logic of addSubscriberService to the compiler pass #12069

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public function addSubscriberService($serviceId, $class)
$this->listenerIds[$eventName][] = array($serviceId, $params, 0);
} elseif (is_string($params[0])) {
$this->listenerIds[$eventName][] = array($serviceId, $params[0], isset($params[1]) ? $params[1] : 0);
} else {
} elseif (is_array($params[0])) {
foreach ($params as $listener) {
$this->listenerIds[$eventName][] = array($serviceId, $listener[0], isset($listener[1]) ? $listener[1] : 0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,17 @@ public function process(ContainerBuilder $container)
throw new \InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, $interface));
}

$definition->addMethodCall('addSubscriberService', array($id, $class));
foreach ($class::getSubscribedEvents() as $eventName => $params) {
if (is_string($params)) {
$definition->addMethodCall('addListenerService', array($eventName, array($id, $params), 0));
} elseif (is_string($params[0])) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You assume it's an array if it's not a string

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a great opportunity to make sure it will not break 👍

$definition->addMethodCall('addListenerService', array($eventName, array($id, $params[0]), isset($params[1]) ? $params[1] : 0));
} elseif (is_array($params[0])) {
foreach ($params as $listener) {
$definition->addMethodCall('addListenerService', array($eventName, array($id, $listener[0]), isset($listener[1]) ? $listener[1] : 0));
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,6 @@ class SubscriberService implements \Symfony\Component\EventDispatcher\EventSubsc
{
public static function getSubscribedEvents()
{
return array();
}
}