Subscribe to an Event with either a closure or callable structure

@param     $eventName
@param     $callable
@param int $priority - highest number highest priority

@return $this
@throws \EventDispatch\Exception\SubscriberNotCallable
498900
public function subscribe($eventName, $callable, $priority = 0)
    {
        if (!is_callable($callable)) {
            throw new SubscriberNotCallable();
        }

        $this->eventList[$eventName][$priority][] = $callable;

        /*
         * Clear cached sorted array
         */
        unset($this->sorted[$eventName]);

        return $this;
    }
360627
public function onServer($command, $callback, $priority = 0)
    {
        $handler = new EventListener(null, $callback);
        $this->dispatcher->addListener('server.' . $command, array($handler, 'testAndExecute'), $priority);

        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;
    }
74379
public function listen($event, $callable, $priority = ListenerPriority::NORMAL)
    {
        $this->addListener($callable, [$event => $priority]);

        return $this;
    }
1093258
public function addEventSubscriber(AnEventSubscriberInterface $subscriber, $priority = null)
    {
        $handle = $subscriber->getHandle();
    
        if (! isset($this->_subscribers[$handle])) {
            $subscriptions = $subscriber->getSubscriptions();
            $priority = is_int($priority) ? $priority : $subscriber->getPriority();
    
            foreach ($subscriptions as $subscription) {
                $this->addEventListener($subscription, $subscriber, $priority);
            }
    
            $this->_subscribers[$handle] = $subscriber;
        }
    
        return $this;
    }
484362
public function on($event_name, $callback, $priority = 100) {
	    	if(!is_callable($callback)){
	    		throw new \InvalidArgumentException("Argument 'callback' is not callable.");
	    	}

	        if (!isset($this->listeners[$event_name])) {
	            $this->listeners[$event_name] = array(
	                true,  // If there's only one item, it's sorted
	                array($priority),
	                array($callback)
	            );
	        } else {
	            $this->listeners[$event_name][0] = false; // marked as unsorted
	            $this->listeners[$event_name][1][] = $priority;
	            $this->listeners[$event_name][2][] = $callback;
	        }
	    }
687509
final public function registerEvent($event_name, $callback, $priority)
    {
        $event_name = trim($event_name);
        if (!isset($this->listeners[$event_name])) {
            $this->listeners[$event_name] = array();
        }
        $event = array(
            'event_name' => $event_name,
            'callback' => $callback,
            'priority' => (int)$priority
        );
        array_push($this->listeners[$event_name], $event);
        if (count($this->listeners[$event_name]) > 1) {
            usort($this->listeners[$event_name], array($this, 'sortListenerByPriority'));
        }
        return $this;
    }
767661
public function unSubscribe(string $eventName, callable $subscriber): self
    {
        if (($subscriber instanceof Closure) === false &&
            ($staticMethod = $this->parseStaticMethod($subscriber)) !== null
        ) {
            $subscriber = $this->getUnifiedStaticMethodRepresentation($staticMethod);
        }

        $eventSubscribers = $this->getEventSubscribers($eventName);
        $eventSubscribers = array_filter($eventSubscribers, function ($curSubscriber) use ($subscriber) {
            return $curSubscriber !== $subscriber;
        });

        return $this->setEventSubscribers($eventName, $eventSubscribers);
    }
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);
    }
138605
public function attach(EventManagerInterface $events, $priority = 1)
    {
        $this->listeners[] = $events->attach(ComposerEvent::EVENT_COMPOSE_PRE, [$this, 'setMessageEncoding']);
    }
1041387
protected function triggerEvent($eventName, NodeInterface $node = null)
    {
        if (isset($this->activeEvents[$eventName])) {
            $this->dispatcher->dispatch($eventName, $this->sharedEvent->setNode($node));
        }

        return $this;
    }
397742
public function listen($events, $listener, $priority=0)
    {

        if (!is_callable($listener)) {
            throw new InvalidArgumentException('Listener has to be callable');
        }

        foreach ((array)$events as $event) {

            if ($this->isWildcardSyntax($event)){
                $this->addWildCardListener($event, $listener, $priority);
            }
            $this->addListener($event, $listener, $priority);

        }
    }
566530
public function removeEventHandler($eventName, $eventHandlerName, $priority = 50)
    {
        $this->removeHandler(self::EVENT, $eventName, $eventHandlerName, $priority);
    }
902725
public function hook($name, $callable, $priority = 10, $override = false)
    {
        if ($override) {
            $this->clearHooks($name);
        }

        return parent::hook($name, $callable, $priority);
    }
1107671
function on(string $eventName, /*mixed*/ $callBack, int $priority = 100) 
    {
        if(!is_callable($callBack)) {
            error_log("callback is not callable");
        }
        if(is_array($callBack)) {
            foreach($this->listeners($eventName, true) as $listener) {
                if(is_object($listener) && $listener instanceof \Closure)
                    continue;
                if($listener[1]==$callBack[1]) {
                    if(is_object($listener[0])) {
                        if($listener[0]->id()->equals($callBack[0]->id()))
                            return;
                    }
                    if($listener[0]==$callBack[0]->id()->toString())
                        return;
                }
            }
        }
        $closure = \Closure::fromCallable($callBack);
        // $analyzer = new \SuperClosure\Analyzer\TokenAnalyzer();
        //    eval(\Psy\sh());
        if (!isset($this->listeners[$eventName])) {
            $this->listeners[$eventName] = [
                true,  // If there's only one item, it's sorted
                [$priority],
                [$closure]
            ];
            if(is_array($callBack)) {
                //$subject=$analyzer->analyze($closure);
                $this->listeners_flat[$eventName] = [
                    true,  // If there's only one item, it's sorted
                    [$priority],
                    [
                        [
                            $callBack[0]->id()->toString(), // $subject["reflection"]->getClosureThis()->id()->toString(),
                            $callBack[1]
                        ]
                    ]
                ];
            }
        } else {
            $this->listeners[$eventName][0] = false; // marked as unsorted
            $this->listeners[$eventName][1][] = $priority;
            $this->listeners[$eventName][2][] =  $closure;
            if(is_array($callBack)) {
                //$subject=$analyzer->analyze($closure);
                $this->listeners_flat[$eventName][0] = false;
                $this->listeners_flat[$eventName][1][] = $priority;
                $this->listeners_flat[$eventName][2][] = [
                        $callBack[0]->id()->toString(),    //$subject["reflection"]->getClosureThis()->id()->toString(), 
                        $callBack[1]
                ];
            }
        }
    }
761575
public function subscribe(string $event, string $listener, callable $callback)
    {
        $callbackKey = $event . ' ' . $listener;
        $this->events[$event][] = $callbackKey;
        $this->subscriptions[$callbackKey] = $callback;
    }
919294
public function callbackRule(callable $callback, $expected, $value, $priority = 0)
    {
        $key = is_string($callback) ? $callback : $this->getFreeKey();

        $this
            ->defineMap($key, $callback, $priority)
            ->rule($key, $expected, $value)
        ;

        return $this;
    }