From b8c75fdccbbff8c11c7c9c17889e6d2cf96f6996 Mon Sep 17 00:00:00 2001 From: Andrei Shapiro Date: Wed, 29 Sep 2021 13:25:23 +0000 Subject: [PATCH] refactor: use new container to get services --- common/oatbox/event/EventManager.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/common/oatbox/event/EventManager.php b/common/oatbox/event/EventManager.php index 0ce2153ed..706883322 100644 --- a/common/oatbox/event/EventManager.php +++ b/common/oatbox/event/EventManager.php @@ -36,9 +36,9 @@ class EventManager extends ConfigurableService * @deprecated use SERVICE_ID */ const CONFIG_ID = 'generis/event'; - + const OPTION_LISTENERS = 'listeners'; - + /** * Dispatch an event and trigger its listeners * @@ -49,21 +49,23 @@ public function trigger($event, $params = []) { $eventObject = is_object($event) ? $event : new GenericEvent($event, $params); foreach ($this->getListeners($eventObject) as $callback) { - if (is_array($callback) && count($callback) == 2) { - list($key, $function) = $callback; + if (is_array($callback) && count($callback) === 2) { + [$key, $function] = $callback; + if (is_string($key)) { try { - $service = $this->getServiceManager()->get($key); + $service = $this->getServiceLocator()->getContainer()->get($key); $callback = [$service, $function]; } catch (ServiceNotFoundException $e) { //do nothing } } } + call_user_func($callback, $eventObject); } } - + /** * Attach a Listener to one or multiple events * @@ -86,7 +88,7 @@ public function attach($event, $callback) } $this->setOption(self::OPTION_LISTENERS, $listeners); } - + /** * remove listener from an event and delete event if it dosn't have any listeners * @param array $listeners @@ -126,7 +128,7 @@ public function detach($event, $callback) } $this->setOption(self::OPTION_LISTENERS, $listeners); } - + /** * Get all Listeners listening to this kind of event *