Add single listener.

@param string   $name
@param string   $event
@param callable $callable
@param int      $priority

@return static
769119
public function subListen($name, $event, $callable, $priority = ListenerPriority::NORMAL)
    {
        return $this->addSubListener($name, $callable, [$event => $priority]);
    }
699113
public function on($event, callable $callback, int $priority = 0): EventInterface
    {
        //deal with multiple events
        if (is_array($event)) {
            foreach ($event as $item) {
                $this->on($item, $callback, $priority);
            }

            return $this;
        }

        //set up the observer
        $observer = $this->resolve(EventObserver::class, $callback);

        //is there a regexp ?
        if (strpos($event, '#') === 0 && strrpos($event, '#') !== 0) {
            $this->regex[] = $event;
        //is there a sprintf ?
        //because sscanf will match Render Home Page
        //and Render Home Body with Render %s Page
        //so this needs to be pseudo
        } else if (preg_match('#%[sducoxXbgGeEfF]#s', $event)) {
            //transform that into a regex
            $event = preg_quote($event, '#');
            $event = preg_replace('#%[sducoxXbgGeEfF]#s', '(.+)', $event);
            $event = '#' . $event . '#s';

            $this->regex[] = $event;
        }

        $this->observers[$event][] = [
            'priority' => $priority,
            'observer' => $observer
        ];

        return $this;
    }
1068128
public function addOperationListener(OperationListenerInterface $listener, $priority = 0)
    {
        $this->getEventManager()->attach('beforeOperation', [$listener, 'beforeOperation'], $priority);
        $this->getEventManager()->attach('afterOperation', [$listener, 'afterOperation'], $priority);
        $this->getEventManager()->attach('onOperationException', [$listener, 'onOperationException'], $priority);
    }
1249979
public function removeListener(string $eventName, callable $listener, $priority = 0): MediatorInterface
    {
        $this->checkEventName($eventName);
        if (!\array_key_exists($eventName, $this->listeners)) {
            return $this;
        }
        /**
         * @var array      $priorities
         * @var int        $atPriority
         * @var callable[] $listeners
         */
        if ('last' !== $priority) {
            $priorities = $this->listeners[$eventName];
        } else {
            $priorities = \array_reverse($this->listeners[$eventName], \true);
            $priority = 'first';
        }
        $isIntPriority = \is_int($priority);
        foreach ($priorities as $atPriority => $listeners) {
            if ($isIntPriority && $priority !== $atPriority) {
                continue;
            }
            $key = \array_search($listener, $listeners, \true);
            if (\false !== $key) {
                $this->bubbleUpUnsetListener($eventName, $atPriority, $key);
                if ('first' === $priority) {
                    break;
                }
            }
        }
        return $this;
    }
1111178
public function listen($events, $listener, $priority = 0)
    {
        //$priority = sprintf('p:%s', str_pad($priority, 6, '0', STR_PAD_LEFT));

        foreach ((array) $events as $event) {
            $this->listeners[$event][$priority][] = $this->makeListener($listener);
        }
    }
70623
public function insert($name, $element, $priority)
    {
        return $this->doCall(new Operation('PriorityQueue', 'insert', [$name, $element, $priority]));
    }
1276414
public function addEventHandler($eventName, $eventHandlerName, $priority = 50)
    {
        $this->addHandler(self::EVENT, $eventName, $eventHandlerName, $priority);
    }
223857
public function addListener($name, callable $handler)
    {
        $this->assertEventName($name);
        $this->getEventDispatcher()->addListener($name, $handler);
        return $this;
    }
253428
public function once(string $name, callable $handler, int $priority = 50, array $extraArguments = []): self
    {
        $this->on($name, $handler, $priority, $extraArguments);
        $handlerId = $this->handler->getKey($handler);
        $this->listeners[$name][$priority][$handlerId]['once'] = true;

        return $this;
    }
1352106
public function attachEvent($event, $handler, $priority = 0)
    {
        $this->eventDispatcher->addListener($event, $handler, $priority);
        return $this;
    }
256642
public function addListener($eventName, $listener, $priority = 0)
    {
        $this->getDispatcher()->addListener($eventName, $listener, $priority);
    }
65189
public function once($event, $listener, int $priority = Priority::NORMAL)
    {
        $this->addListener($event, $listener, $priority, true);
    }
60449
public function hook($event, callable $callback, $priority = 10)
    {
        $this->app->hook($event, $callback, $priority);
    }
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;
    }
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;
    }
312728
public function listen($events, $listener, $priority=0)
    {
        return $this->getDistributor()->listen($events, $listener, $priority);
    }
759023
public function addEventListener($eventName, $listener, $priority = EventPriority::NORMAL) {
        if (!isset($this->_listeners[$eventName][$priority])) {
            $this->_listeners->extendDeepValue(array($priority=>array()), $eventName);
        }
        $this->_listeners[$eventName][$priority][] = $listener;
    }