Attach listener

@param string               $eventType
@param array|Closure|object $callable
@param int                  $priority

@return EventManager
771782
public function attach($eventType, $callable, $priority = 10)
    {
        if (!isset(self::$listener[$eventType])) {
            self::$listener[$eventType] = new SplPriorityQueue();
        }

        self::$listener[$eventType]->insert($callable, $priority);

        return $this;
    }
72450
public function attach(EventManagerInterface $events, $priority = 1)
    {
        $this->listeners[] = $events->attach(ComposerEvent::EVENT_COMPOSE_POST, [$this, 'generateTextBody']);
    }
1359489
public function on($event, $callable, $important = false)
    {
        Argument::i()
            //argument 1 must be string
            ->test(1, 'string')
            //argument 2 must be callable or null
            ->test(2, 'callable', 'null')
            //argument 3 must be boolean
            ->test(3, 'bool');

        $id = $this->getId($callable);

        //set up the observer
        $observer = array($event, $id, $callable);

        //if this is important
        if ($important) {
            //put the observer on the top of the list
            array_unshift($this->observers, $observer);
            return $this;
        }

        //add the observer
        $this->observers[] = $observer;
        return $this;
    }
1063449
public function register($eventType, callable $filter)
    {
        if (!isset($this->handlers[$eventType])) {
            $this->handlers[$eventType] = [];
        }

        $this->handlers[$eventType][] = $filter;
    }
259072
protected function addHandler($type, $name, $handlerName, $priority)
    {
        // If the priority isn't existing we add the priority as 
        // a new array.
        if (!isset($this->handlers[$type][$name][$priority])) {
            $this->handlers[$type][$name][$priority] = array();
            ksort($this->handlers[$type][$name]);
        }
        
        // If we had the event handler already registred, return at this point
        if (in_array($handlerName, $this->handlers[$type][$name][$priority])) {
            return;
        }
        
        // Add the event handler and save the new events array
        $this->handlers[$type][$name][$priority][] = $handlerName;
        $this->saveHandlers();
    }
591114
public function attachEventListener($eventType,$handler) {
    if (!$eventType)
      $eventType = $this->getEventPrefix();
    elseif (!strstr($eventType,':') && $eventType != $this->getEventPrefix())
      $eventType = $this->getEventPrefix().':'.$eventType;
    
    return $this->_forceGetEventsManager()->attach($eventType,$handler);
  }
444963
protected function registerListener($event, $listener, $priority)
    {
        if (!is_callable($listener)) {
            throw new DispatcherException(sprintf('Invalid event listener. Only callables or ListenerInterface instances can be registered, got "%s"', gettype($listener)));
        }

        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]);
    }
56527
protected function offHandlerWithPriority(string $eventName, callable $handler, int $priority = 50): self
    {
        $handlerId = $this->handler->getKey($handler);

        if (isset($this->listeners[$eventName][$priority][$handlerId])) {
            unset($this->listeners[$eventName][$priority][$handlerId]);
            $this->cleanEmptyEvent($eventName, $priority);
        }

        return $this;
    }
1222632
def add_listener(self, event, callback, single=False, priority=1):
        
        event_stack = self._events[event]
        event_stack.append({
            "callback": callback,
            "single": single,
            "priority": priority
        })
        event_stack.sort(key=lambda x: x['priority'])
495330
public function attach(EventManagerInterface $events, $priority = 1000)
    {
        if (PHP_SAPI === 'cli') {
            return;
        }

        $this->listeners[] = $events->getSharedManager()->attach(
            Application::class,
            MvcEvent::EVENT_ROUTE,
            [
                $this,
                'onRouteRemoveTrailingSlash'
            ],
            $priority
        );

        $this->listeners[] = $events->getSharedManager()->attach(
            Application::class,
            MvcEvent::EVENT_ROUTE,
            [
                $this,
                'onRouteNormalizeParameters'
            ],
            -$priority
        );
    }
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());
        }
    }
926651
public function attach($eventName, $callback, $priority = 1): void
    {
        if (!isset($this->listeners[$eventName])) {
            $this->listeners[$eventName] = [];
        }
        if (!isset($this->listeners[$eventName][$priority])) {
            $this->listeners[$eventName][$priority] = [];
        }
        $this->listeners[$eventName][$priority][] = $callback;
    }
403447
public function listen($events, $listener, $priority = 0, $acceptedArgs = 1)
    {
        foreach ((array)$events as $event)
        {
            $this->listeners[$event][$priority][] = $this->makeListener($listener);

            unset($this->sorted[$event]);

            if ( ! isset($this->registeredWpActions[$event]))
            {
                $this->registeredWpActions[$event] = true;

                add_action(
                    $event,
                    function () use ($event)
                    {
                        return $this->fire($event, func_get_args());
                    },
                    $priority,
                    $acceptedArgs
                );
            }
        }
    }
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;
    }
75650
function on(string $event, $callback, int $priority = 0): void
    {
        $this->getEventEmitter()->on($event, $callback, $priority);
    }
60449
public function hook($event, callable $callback, $priority = 10)
    {
        $this->app->hook($event, $callback, $priority);
    }
592581
public function listen($events, $listener, $priority = 0)
    {
        foreach ((array) $events as $event) {
            if (mb_strpos($event, '*') !== false) {
                $this->setupWildcardListen($event, $listener);
            } else {
                $this->listeners[$event][$priority][] = $this->makeListener($listener);

                unset($this->sorted[$event]);
            }
        }
    }