@param string|object|callable $eventListener

@return EventRouter

@throws Exception\RuntimeException
@throws Exception\InvalidArgumentException
341328
public function to($eventListener): EventRouter
    {
        if (! \is_string($eventListener) && ! \is_object($eventListener) && ! \is_callable($eventListener)) {
            throw new Exception\InvalidArgumentException(\sprintf(
                'Invalid event listener provided. Expected type is string, object or callable but type of %s given.',
                \gettype($eventListener)
            ));
        }

        if (null === $this->tmpEventName) {
            throw new Exception\RuntimeException(\sprintf(
                'Cannot map listener %s to an event. Please use method route before calling method to',
                \is_object($eventListener)
                    ? \get_class($eventListener)
                    : (\is_string($eventListener) ? $eventListener : \gettype($eventListener))
            ));
        }

        $this->eventMap[$this->tmpEventName][] = $eventListener;

        return $this;
    }
227470
public function setEventListener($listener)
	{
		$this->ensureEventListeners();
		
		$this->_eventListeners[Ioc::resolveClassName($listener)] =  $listener;
		
		return $this;
	}
938925
protected function ensureListener($listener): Listener
    {
        if (Assert::instanceOf($listener, '\\One\\Event\\Listener')) {
            return $listener;
        } elseif (Assert::instanceOf($listener, '\\Closure') || Assert::array($listener)) {
            return new Listener($listener);
        } elseif (Assert::string($listener)) {
            return Reflection::newInstance($listener);
        }

        throw new InvalidArgumentException(
            '`Listener` must be `array`, `Closure` or extends class `One\Event\Listener`'
        );
    }
1003046
public function removeListener( $event, EventListener $listener = null ) {

		$event = strtolower( $event );

		if ( !$this->hasEvent( $event ) ) {
			return;
		}

		if ( $listener !== null ) {
			foreach ( $this->dispatchableListeners[$event] as $key => $dispatchableListener ) {
				if ( $dispatchableListener == $listener ) {
					unset( $this->dispatchableListeners[$event][$key] );
				}
			}
		}

		if ( $listener === null || $this->dispatchableListeners[$event] === array() ) {
			unset( $this->dispatchableListeners[$event] );
		}
	}
1108738
public function on(string $event, $listener)
    {
        if (empty($this->_events[$event])) {

            $this->_events[$event] = [$listener];
        }
        else {

            $this->_events[$event][] = $listener;
        }

        return $this;
    }
117848
public function removeListener(EventListener $listener)
    {
        if (($i = array_search($listener, $this->listeners)) !== false) {
            unset($this->listeners[$i]);
        }
        return $this;
    }
1190439
public function handler($handler)
    {

        if ($this->isNumber($handler) || $this->isBoolean($handler) || $this->isEmpty($handler)) {
            throw new EventManagerException(EventManagerException::INVALID_EVENT_HANDLER);
        }

        if ($this->isString($handler) || $this->isStringObject($handler)) {
            $handler = StdObjectWrapper::toString($handler);
            if (!class_exists($handler)) {
                throw new EventManagerException(EventManagerException::INVALID_EVENT_HANDLER);
            }
            $handler = new $handler;
        }
        $this->handler = $handler;

        return $this;
    }
755183
protected function callListener(callable $listener, array $args = [])
    {
        switch (count($args)) {
            case 0:
                return call_user_func($listener);
            case 1:
                return call_user_func($listener, $args[0]);
            case 2:
                return call_user_func($listener, $args[0], $args[1]);
            case 3:
                return call_user_func($listener, $args[0], $args[1], $args[2]);
            case 4:
                return call_user_func($listener, $args[0], $args[1], $args[2], $args[3]);
        }

        return call_user_func_array($listener, $args);
    }
1094386
protected function ensureListener($listener)
    {
        if ($listener instanceof ListenerInterface) {
            return $listener;
        }

        if (is_callable($listener)) {
            return CallbackListener::fromCallable($listener);
        }

        throw new InvalidArgumentException('Listeners should be be ListenerInterface, Closure or callable. Received type: '.gettype($listener));
    }
213846
public function removeListener(string $eventName, callable $listener): bool
    {
        // If it ends with a wildcard, we use the wildcardListeners array
        if ('*' === $eventName[\strlen($eventName) - 1]) {
            $eventName = \substr($eventName, 0, -1);
            $listeners = &$this->wildcardListeners;
        } else {
            $listeners = &$this->listeners;
        }

        if (!isset($listeners[$eventName])) {
            return false;
        }

        foreach ($listeners[$eventName] as $index => $check) {
            if ($check[1] === $listener) {
                // Remove listener
                unset($listeners[$eventName][$index]);
                // Reset index
                $this->listenerIndex = [];

                return true;
            }
        }

        return false;
    }
1037037
protected function callListener(callable $listener, $event, array $args)
    {

        if (!$this->marks) {
            return Lambda::callFast($listener, $args);
        }

        if ($listener instanceof MatchingListener) {
            return $listener->callWithMarks($args, $this->marks);
        }

        return Lambda::callFast($listener, $args);

    }
577153
public static function getEventDispatcher(): EventDispatcherInterface
    {
        if (isset(self::$dispatchers[static::class])) {
            return self::$dispatchers[static::class];
        }

        return self::$dispatchers[static::class] = new EventDispatcher();
    }
928057
public function eventFactory()
    {
        if (null !== $this->eventPrototype) {
            return clone $this->eventPrototype;
        }

        try {
            /** @var ModuleOptions $moduleOptions */
            $moduleOptions = $this->get(ModuleOptions::class);

            $moduleOptionsEventClassName = $moduleOptions->getModuleOptionsEventClassName();
            $r = new ReflectionClass($moduleOptionsEventClassName);

            $eventPrototype = $r->newInstance();
            if (!$eventPrototype instanceof EventInterface) {
                $errMsg = sprintf(
                    'Event of type %s is invalid; must implement %s',
                    (is_object($eventPrototype) ? get_class($eventPrototype) : gettype($eventPrototype)),
                    ModuleOptionsEventInterface::class
                );
                throw new Exception\RuntimeException($errMsg);
            }
            $this->eventPrototype = $eventPrototype;
        } catch (\Exception $e) {
            throw new Exception\InvalidEventException($e->getMessage(), $e->getCode(), $e);
        }

        return clone $this->eventPrototype;
    }
50868
public function onAfter($event, callable $listener)
    {
        $this->checkEvent($event);

        if (!isset($this->afterListeners[$event])) {
            $this->afterListeners[$event] = [];
        }
        $this->afterListeners[$event][] = $listener;

        return $this;
    }
626661
public function eventManager(EventManager $eventManager = null)
    {
        if ($eventManager !== null) {
            $this->_eventManager = $eventManager;
        }

        return $this->_eventManager;
    }
1129905
protected function callListener($callable, Event $event)
    {
        if ($callable instanceof Closure || is_array($callable)) {
            call_user_func_array($callable, array_filter([$event, $event->getSubject(), $event->getData()]));
        } elseif (is_object($callable)) {
            $callable->{$event->getType()}($event, $event->getSubject(), $event->getData());
        }
    }
772233
public function handle(EventListenerInterface $listener)
    {
        if (!$listener->getListeners()) {
            return;
        }

        $content = $this->request->getContent();

        try {
            $options = Serializer::parse($content);
        } catch (\InvalidArgumentException $e) {
            $options = [];
        }

        foreach ($listener->getListeners() as $namespace => $callable) {
            $event = new $namespace($options);
            if ($event->isValid()) {
                $listener->trigger($namespace, $event);
                break;
            }
        }
    }