@param string $eventName
@param callable|null $handler
@param int|null $priority

@return $this
509060
public function off(string $eventName, callable $handler = null, int $priority = null): self
    {
        if ($handler === null) {
            return $this->offAll($eventName);
        }

        $priority === null
            ? $this->offHandlerWithoutPriority($eventName, $handler)
            : $this->offHandlerWithPriority($eventName, $handler, $priority);

        if (empty($this->listeners[$eventName])) {
            unset($this->listeners[$eventName], $this->sorted[$eventName]);
        }

        return $this;
    }
379471
public function attach(string $event, callable $callback, int $priority = self::PRIORITY_MIN): void
    {

        /* If there aren't any listeners for an event yet */
        if (empty($this->events[$event])) {

            /* Create a new queue for the event. */
            $this->events[$event] = new PriorityQueue();
        }

        /* Create a new listener with the given data */
        $listener = new EventListener($event, $callback, $priority);

        /* Insert the new callback into the queue. */
        $this->events[$event]->insert($listener, $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]
                ];
            }
        }
    }
393340
protected function removeHandler($type, $name, $handlerName, $priority)
    {
        // If the event isn't set we add an array to the events array
        if (!isset($this->handlers[$type][$name][$priority])) {
            return;
        }
        
        // If the event handler isn't registred we return with true.
        if (!in_array($handlerName, $this->handlers[$type][$name][$priority])) {
            return;
        }
        
        // Remove the event handler from the array
        $index = array_search($handlerName, $this->handlers[$type][$name][$priority]);
        unset($this->handlers[$type][$name][$priority][$index]);
        $this->saveHandlers();
    }
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);
        }
    }
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;
    }
1092993
public function subscribe($event, $listener, $priority = ListenerAcceptorInterface::P_NORMAL)
    {
        $this->addListener($event, $listener, $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]);
            }
        }
    }
627809
protected function addEventListener($name, $callback, $priority = null)
    {
        if (is_null($priority)) {
            $this->events->listen($name, $callback);
        } else {
            $this->events->listen($name, $callback, $priority);
        }
    }
683879
public function addHandler(HandlerInterface $handler, $priority = 0)
    {
        if (filter_var($priority, FILTER_VALIDATE_INT) === false) {
            throw new InvalidArgumentException("Argument 'priority' should be an integer, got '$priority'");
        }

        if ($this->handlerAlreadyRegistered($handler)) {
            return;
        }

        $this->handlers[$priority][] = $handler;
    }
646481
public function getListenerPriority(string $eventName, callable $listener)
	{
		if (isset($this->listeners[$eventName])) {
			foreach ($this->listeners[$eventName] as $priority => $listeners) {
				if (false !== \in_array($listener, $listeners, true)) {
					return $priority;
				}
			}
		}

		return null;
	}
74379
public function listen($event, $callable, $priority = ListenerPriority::NORMAL)
    {
        $this->addListener($callable, [$event => $priority]);

        return $this;
    }
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);
    }
738510
public function on($event_name, $handler_callback)
    {
        $event = null;
        if (!isset($this->event_queue[$event_name])) {
            $event = new Event($event_name);
            $this->event_queue[$event_name] = $event;
        }

        $event = $this->event_queue[$event_name];
        $event->setHandlerCallback($handler_callback);
    }
486075
public function setHandlerPriority(CommandHandlerInterface $handler, $priority)
    {
        $this->__queue->setPriority($handler, $priority);
        return $this;
    }
929500
public function addListener( $eventName, IListener $listener, $priority = 0 )
    {
        $this->listeners[ $eventName ][ $priority ][ ] = $listener;

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

        return $this;
    }