diff --git a/common/oatbox/event/EventManager.php b/common/oatbox/event/EventManager.php index 2ecebcb4a..e6007b3ac 100644 --- a/common/oatbox/event/EventManager.php +++ b/common/oatbox/event/EventManager.php @@ -16,7 +16,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Copyright (c) 2015-2022 (original work) Open Assessment Technologies SA; - * */ namespace oat\oatbox\event; @@ -36,9 +35,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 * @@ -48,18 +47,18 @@ class EventManager extends ConfigurableService public function trigger($event, $params = []) { $container = $this->getServiceManager()->getContainer(); - $event = is_object($event) ? $event : new GenericEvent($event, $params); foreach ($this->getListeners($event) 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 = $container->get($key); $callback = [$service, $function]; } catch (ServiceNotFoundException $e) { - //do nothing + // Do nothing } } } @@ -67,7 +66,7 @@ public function trigger($event, $params = []) call_user_func($callback, $event); } } - + /** * Attach a Listener to one or multiple events * @@ -90,7 +89,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 @@ -130,7 +129,7 @@ public function detach($event, $callback) } $this->setOption(self::OPTION_LISTENERS, $listeners); } - + /** * Get all Listeners listening to this kind of event *