@param string     $eventName
@param callable   $listener
@param int|string $priority

@return MediatorInterface Fluent interface
@throws \DomainException
@throws \InvalidArgumentException
321290
public function addListener(string $eventName, callable $listener, $priority = 0): MediatorInterface
    {
        $this->checkEventName($eventName);
        $priority = $this->getActualPriority($eventName, $priority);
        if (!(\array_key_exists($eventName, $this->listeners)
            && \array_key_exists($priority, $this->listeners[$eventName])
            && \in_array($listener, $this->listeners[$eventName][$priority], \true))
        ) {
            $this->listeners[$eventName][$priority][] = $listener;
        }
        return $this;
    }
116331
private function registerListener($event, callable $listener, $priority)
    {
        if (!isset($this->events[$event])) {
            $this->events[$event] = [];
        }

        if ($priority === null) {
            $this->events[$event][] = $listener;

            return;
        }

        array_splice($this->events[$event], (int) $priority, 0, [$listener]);
    }
1085170
protected function lazyLoad($eventName)
    {
        parent::lazyLoad($eventName);

        if (isset($this->listenerIds[$eventName])) {
            foreach ($this->listenerIds[$eventName] as $args) {
                list($serviceId, $method, $priority, $queueName) = $args;
                if ($queueName != null) {
                    $listener = $this->container->get($serviceId);
                    $key = $serviceId.'.'.$method;
                    $this->listeners[$eventName][$key] = array($listener, $queueName);
                }
            }
        }
    }
631271
public function on(string $name, callable $handler, int $priority = 50, array $extraArguments = [])
    {
        $handlerId = $this->handler->getKey($handler);
        $this->listeners[$name][$priority][$handlerId] = [
            'handler' => $handler,
            'extraArguments' => $extraArguments,
            'priority' => $priority,
        ];

        $this->sorted[$name] = false;

        return $this;
    }
315304
public function getListenerPriority($eventType, $listener)
    {
        if (isset($this->listeners[$eventType])) {
            foreach ($this->listeners[$eventType] as $priority => $listeners) {
                if (false !== ($key = array_search($listener, $listeners, true))) {
                    return $priority;
                }
            }
        }

        return null;
    }
1068783
public function attach(EventManagerInterface $events, $priority = 1)
    {
        $this->listeners[] = $events->attach(ViewEvent::EVENT_RENDERER, array($this, 'selectRenderer'), $priority);
        $this->listeners[] = $events->attach(ViewEvent::EVENT_RESPONSE, array($this, 'injectResponse'), $priority);
    }
619679
public function removeListener(string $eventName, $listener): void
    {
        $this->dispatcher->removeListener($eventName, $listener);
    }
1036725
public function on($event, $callback, $priority = 0){

        if (is_array($event)) {

            foreach ($event as &$evt) {
                $this->on($evt, $callback, $priority);
            }
            return $this;
        }

        if (!isset($this->events[$event])) $this->events[$event] = [];

        // make $this available in closures
        if (is_object($callback) && $callback instanceof \Closure) {
            $callback = $callback->bindTo($this, $this);
        }

        $this->events[$event][] = ['fn' => $callback, 'prio' => $priority];

        return $this;
    }
1357886
protected function lazyLoad($eventName)
    {
        if (isset($this->listenerIds[$eventName])) {
            foreach ($this->listenerIds[$eventName] as $args) {
                list($serviceId, $method, $priority) = $args;
                $listener = $this->container->get($serviceId);

                $key = $serviceId.'.'.$method;
                if (!isset($this->listeners[$eventName][$key])) {
                    $this->addListener($eventName, array($listener, $method), $priority);
                } elseif ($listener !== $this->listeners[$eventName][$key]) {
                    parent::removeListener($eventName, array($this->listeners[$eventName][$key], $method));
                    $this->addListener($eventName, array($listener, $method), $priority);
                }

                $this->listeners[$eventName][$key] = $listener;
            }
        }
    }
566530
public function removeEventHandler($eventName, $eventHandlerName, $priority = 50)
    {
        $this->removeHandler(self::EVENT, $eventName, $eventHandlerName, $priority);
    }
1247722
protected function listen(string $event, string $methodName, int $priority = 0): EventListener
    {
        return new EventListener($event, [$this, $methodName], $priority);
    }
950793
public function trigger(string $eventName, EventInterface $event = \null): EventInterface
    {
        $this->checkEventName($eventName);
        if (\null === $event) {
            $event = new Event();
        }
        $priorities = $this->getListeners($eventName);
        if (0 !== \count($priorities)) {
            /**
             * @var array    $listeners
             * @var callable $listener
             */
            foreach ($priorities as $listeners) {
                foreach ($listeners as $listener) {
                    $listener($event, $eventName, $this);
                    /** @noinspection DisconnectedForeachInstructionInspection */
                    if ($event->hasBeenHandled()) {
                        break 2;
                    }
                }
            }
        }
        return $event;
    }
1290191
public function removeListener( $eventName, IListener $listener )
    {
        if ( !isset( $this->listeners[ $eventName ] ) )
        {
            return $this;
        }

        foreach ( $this->listeners[ $eventName ] as $priority => $listeners )
        {
            if ( FALSE !== ( $key = array_search( $listener, $listeners, TRUE ) ) )
            {
                unset( $this->listeners[ $eventName ][ $priority ][ $key ], $this->_sorted[ $eventName ] );
            }
        }

        return $this;
    }
256642
public function addListener($eventName, $listener, $priority = 0)
    {
        $this->getDispatcher()->addListener($eventName, $listener, $priority);
    }
706983
protected function sortListeners($eventName)
    {
        // If listeners exist for the given event, we will sort them by the priority
        // so that we can call them in the correct order. We will cache off these
        // sorted event listeners so we do not have to re-sort on every events.
        $listeners = isset($this->listeners[$eventName])
                            ? $this->listeners[$eventName] : [];

        if (class_exists($eventName)) {
            foreach (class_implements($eventName) as $interface) {
                if (isset($this->listeners[$interface])) {
                    foreach ($this->listeners[$interface] as $priority => $names) {
                        if (isset($listeners[$priority])) {
                            $listeners[$priority] = array_merge($listeners[$priority], $names);
                        } else {
                            $listeners[$priority] = $names;
                        }
                    }
                }
            }
        }

        if ($listeners) {
            krsort($listeners);

            $this->sorted[$eventName] = call_user_func_array('array_merge', $listeners);
        } else {
            $this->sorted[$eventName] = [];
        }
    }
484647
public function listen($event, $callable, $priority = ListenerPriority::NORMAL)
    {
        $this->getDispatcher()->listen($event, $callable, $priority);

        return $this;
    }
1047934
public static function on($event, $fn, $priority = 0)
    {
        if (!static::bound($event)) {
            static::$events[$event] = [];
        }

        static::$events[$event][] = new Listener($fn, $priority);

        uasort(static::$events[$event], function (Listener $a, Listener $b) {
            return $a->getPriority() < $b->getPriority();
        });
    }