/** * @param \framework\libs\Event $event * @return mixed */ public function dispatchEvent(\framework\libs\Event $event) { $eventName = $event->getName(); $params = $event->getParamaters(); $returnValue = null; if (isset($this->_listeners[$eventName])) { foreach ($this->_listeners[$eventName] as $listener) { //Check if it's directly callable if (\is_callable($listener['callable'])) { $returnValue = call_user_func_array($listener['callable'], $params); } elseif (\is_a($listener['callable'], '\\framework\\libs\\Registry') && !empty($listener['callable'])) { //Check if it's an callable array if (\is_callable(array($listener['callable'][0], $listener['callable'][1]))) { $returnValue = \call_user_func_array(array($listener['callable'][0], $listener['callable'][1]), $params); } else { //Get the component... $component = null; if (isset($listener['params'])) { $component = $this->getComponent($listener['callable'][0], $listener['params']); } else { $component = $this->getComponent($listener['callable'][0]); } //...and call the specified method $returnValue = \call_user_func_array(array($component, $listener['callable'][1]), $params); } } else { throw new \InvalidArgumentException('The argument is not a callable.'); } if ($returnValue) { break; } } } return $returnValue; }