+ /**
+ * Adds a service as event listener.
+ *
+ * This provides partial backwards compatibility with ContainerAwareEventDispatcher.
+ *
+ * @param string $eventName Event for which the listener is added
+ * @param array $callback The service ID of the listener service & the method
+ * name that has to be called
+ * @param int $priority The higher this value, the earlier an event listener
+ * will be triggered in the chain.
+ * Defaults to 0.
+ *
+ * @throws \InvalidArgumentException
+ */
+ public function addListenerService($eventName, $callback, $priority = 0) {
+ if (!\is_array($callback) || 2 !== \count($callback)) {
+ throw new \InvalidArgumentException('Expected an array("service", "method") argument');
+ }
+
+ $this->addListener($eventName, function($event) use ($callback) {
+ static $svc;
+ if ($svc === NULL) {
+ $svc = \Civi::container()->get($callback[0]);
+ }
+ return call_user_func([$svc, $callback[1]], $event);
+ }, $priority);
+ }
+