@param AbstractEvent $event
@param bool          $asynchronous

@return EventListener[]
967166
public function getListeners(AbstractEvent $event, $asynchronous = false)
    {
        return array_filter(
            $this->listeners,
            function (EventListener $eventSubscriber) use ($asynchronous, $event) {
                $supportedEvent = $eventSubscriber->getEventClassName();

                if ($eventSubscriber->isAsynchronous() !== $asynchronous) {
                    return false;
                }
                if (null === $supportedEvent) {
                    return true;
                }

                return $event instanceof $supportedEvent;
            }
        );
    }
1282020
private function getListeners(ActionEvent $event): iterable
    {
        $prioritizedListeners = $this->events[$event->getName()] ?? [];

        \krsort($prioritizedListeners, SORT_NUMERIC);

        foreach ($prioritizedListeners as $listenersByPriority) {
            foreach ($listenersByPriority as $listenerHandler) {
                yield $listenerHandler;
            }
        }
    }
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());
        }
    }
810445
private <E extends Event> EventListener<E> getEventListener(E event) {
        @SuppressWarnings("unchecked")
        EventListener<E> eventListener = (EventListener<E>) eventListenerMap.get(event.getClass());
        return eventListener;
    }
445194
public function on($event, $callback, $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');
        
        //if it's an array they meant to bind the callback
        if (!is_array($callback)) {
            //so there's no scope
            $callback = $callback->bindTo($this, get_class($this));
        }
        
        Event::i()->on($event, $callback, $important);

        return $this;
    }
1056985
public function dispatch(EventInterface $event, \Closure $callback = null)
	{
		if( $this->isRun() )
		{
			throw new EventOverloadException("The event '{$this->name}' is already running");
		}

		// clean data

		$this->aborted = false;
		$this->complete = [];
		$dispatch = new Collection();

		if( !is_null($this->preparatory) )
		{
			$prepare = $this->preparatory;
			if( $prepare($this) === false )
			{
				$this->aborted = true;
				return $dispatch;
			}
		}

		if( ! $this->count() )
		{
			return $dispatch;
		}

		if( $event->getName() !== $this->name )
		{
			throw new \InvalidArgumentException("The name of the Event does not match the name of the Dispatcher");
		}

		$isCall = $callback instanceof \Closure;
		$this->is_run = true;

		foreach( clone $this->callbacks as $call )
		{
			if( $event->isPropagationStopped() )
			{
				$this->aborted = true;
				break;
			}

			try
			{
				$result = $call($event);
			}
			catch( EventAbortException $e )
			{
				continue;
			}

			if( $isCall )
			{
				$callback($result);
			}
			else if( $this->completable && $result instanceof \Closure )
			{
				$this->complete[] = $result;
			}
			else if( !is_null($result) )
			{
				$dispatch[] = $result;
			}
		}

		$this->is_run = false;

		return $dispatch;
	}
923050
private function getListenersForEvent($event) {
        $listeners = [];

        foreach ($this->getEventNameParts($event) as $name) {
            if (isset($this->callbacks[$name])) {
                foreach (clone $this->callbacks[$name] as $listener) {
                    $listeners[] = $listener;
                }
            }
        }

        return $listeners;
    }
186427
protected function buildGlobalCodeOfEvent(AbstractEvent $event) {
        $result = '';
        if (!$event->getInline()) {
            $result .= $this->buildHandlerFunction($event);
        }
        return $result;
    }
884691
public function makeAsynchronous($asynchronous = true)
    {
        $this->isAsynchronous = $asynchronous;

        if ($this->hasValidResource()) {
            $this->applyAsynchronous($this->resource);
        }

        return $this;

    }
525270
public function getListener($event)
    {
        if (!is_string($event) || empty($event)) {
            throw new \InvalidArgumentException('The event name is invalid');
        }

        return $this->listeners[$event];
    }
435067
public function registerCallback($event, $callback)
    {
        $this->checkEventType($event);
        $this->events[$event][] = $callback;
    }
281871
public function getTasksListeners($task, $event, $flatten = false)
    {
        // Get events
        $task = $this->builder->buildTaskFromClass($task);
        $handle = $this->getEventHandle($task, $event);
        $events = $this->events->getListeners($handle);

        // Flatten the queue if requested
        foreach ($events as $key => $listener) {
            if ($flatten && $listener instanceof ClosureTask && $stringTask = $listener->getStringTask()) {
                $events[$key] = $stringTask;
            } elseif ($flatten && $listener instanceof AbstractTask) {
                $events[$key] = $listener->getSlug();
            }
        }

        return $events;
    }
695574
function() {

    this.on = this.addEventListener = function(type, listener) {
        if (!this.events[type]) {
            this.events[type] = [];
        }

        this.events[type].push(listener);
    };

    this.off = this.removeEventListener = function (type, listener) {
        if (!!this.events[type]) {
            for(var i = 0; i < this.events[type].length; i++) {
                if (this.events[type][i] === listener) {
                    this.events[type][i] = null;
                    this.events[type].splice(i, 1);
                    return;
                }
            }
        }
    };

    this.removeAllListeners = function (type) {
        this.events[type] = [];
    };

    var emit = function(cb, event) {
        // Handle callbacks asynchronously
        setTimeout(function() {
            cb(event);
        }, 0);

    };

    this.dispatchEvent = function (event) {
        if (!!event.type) {
            var type = event.type;
            if (!!this.events[type]) {
                event.target = this;
                for (var i = 0; i < this.events[type].length && (event.returnValue === undefined || event.returnValue) ; i++) {
                    var cb = this.events[type][i];
                    // Dereference cb for async
                    emit(cb.bind(event.target), event);
                }
            }
        }
    };
}
637509
public function getListeners(string $event) : array
    {
        if (empty($this->listeners[$event])) {
            return [];
        }

        if (! isset($this->sorted[$event])) {
            $this->sorted[$event] = $this->sortListeners($this->listeners[$event]);
        }

        return $this->sorted[$event];
    }
123184
public function attach($event, $callback) {
        $events = is_array($event) ? $event : array($event);
        $listeners = $this->getOption(self::OPTION_LISTENERS);
        foreach ($events as $event) {
            $eventObject = is_object($event) ? $event : new GenericEvent($event);
            if (!isset($listeners[$eventObject->getName()])) {
                $listeners[$eventObject->getName()] = array();
            }

            if (!in_array($callback, $listeners[$eventObject->getName()], true)) {
                $listeners[$eventObject->getName()][] = $callback;
            }
        }
        $this->setOption(self::OPTION_LISTENERS, $listeners);
    }
26953
protected function getHandlerFunctionName(AbstractEvent $event) {
        $name = array_search($event, $this->handlerFunctionNames);
        if ($name === false) {
            $functionPrefix = $this->builder->getOptions()->getFunctionPrefix();
            $parts = explode('\\', get_class($event));
            $class = end($parts);
            $name = $functionPrefix . '_Handle' . $class . count($this->handlerFunctionNames);
            $this->handlerFunctionNames[$name] = $event;
        }
        return $name;
    }
291203
public static function addEventEntry(AbstractEvent $event)
    {
        return new self(
            null !== $event->aggregateRoot ? $event->aggregateRoot->getId() : null,
            null !== $event->aggregateRoot ? get_class($event->aggregateRoot) : null,
            $event->author,
            get_class($event),
            $event->date,
            serialize($event)
        );
    }