Attach one or more listeners.
Implementors may add an optional $priority argument; the EventManager implementation will pass this to the
aggregate.

@param EventManagerInterface $events
@param int                   $priority

@return void
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
        );
    }
198161
public function attach(EventManagerInterface $events)
    {
        $eventConfigListener = new modules\EventConfigModuleListener($this->serviceLocator);

        $this->listeners[] = $events->attach(ModuleEvent::EVENT_LOAD_MODULES_POST, $eventConfigListener);
        $this->listeners[] = $events->attach(ModuleEvent::EVENT_LOAD_MODULE_RESOLVE, array($this, 'resolve'), 100);

        return $this;
    }
1019307
public function attach(EventManagerInterface $events)
    {
        $this->listeners[] = $events->attach($this->eventBefore, array($this, 'prepareUpload'));
        $this->listeners[] = $events->attach($this->eventAfter, array($this, 'finalizeUpload'));
    }
699779
public function addEventListener($eventName, callable $listener, $priority = Emitter::P_NORMAL)
    {
        $this->eventEmitter->addListener($eventName, $listener, $priority);
    }
1247722
protected function listen(string $event, string $methodName, int $priority = 0): EventListener
    {
        return new EventListener($event, [$this, $methodName], $priority);
    }
321290
public function addListener(string $eventName, callable $listener, $priority = 0): MediatorInterface
    {
        $this->checkEventName($eventName);
        $priority = $this->getActualPriority($eventName, $priority);
        if (!(\array_key_exists($eventName, $this->listeners)
            && \array_key_exists($priority, $this->listeners[$eventName])
            && \in_array($listener, $this->listeners[$eventName][$priority], \true))
        ) {
            $this->listeners[$eventName][$priority][] = $listener;
        }
        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);
        }
    }
1276414
public function addEventHandler($eventName, $eventHandlerName, $priority = 50)
    {
        $this->addHandler(self::EVENT, $eventName, $eventHandlerName, $priority);
    }
1368120
public static function listen($eventId, $callable, $priority = 0)
    {
        /**
         * Closure to wrap the Symphony event dispather callbacks to make for a nicer API
         *
         * @param EventObject $eventObject
         */
        $closure = function ($eventObject) use ($callable) {

            // Get any passed in data
            $data = $eventObject->getData();

            // Work out if we should stop event propogation
            $returnValue = $callable($data, $eventObject->getEventId(), $eventObject->getOriginalId());

            if ($returnValue === false) {
                $eventObject->stopPropagation();
            }
        };

        Event::eventDispatcherInstance()->addListener($eventId, $closure, $priority);

        return new EventInstance($eventId, $closure);
    }
178945
public function listen($events, $listener, $priority=0)
    {
        $this->dispatcher->listen($events, $listener, $priority);
    }
389584
public function detach(EventManagerInterface $events)
    {
        $sharedManager = $events->getSharedManager();

        foreach ($this->listeners as $index => $listeners) {
            if ($listeners === $this) {
                continue;
            }

            if ($listeners instanceof ListenerAggregateInterface) {
                $listeners->detach($events);
            }

            $events->detach($listeners);
        }

        /** @var array $sharedListeners */
        foreach ($this->sharedListeners as $id => $sharedListeners) {
            foreach ($sharedListeners as $index => $listener) {
                if ($listener === $this) {
                    continue;
                }

                if ($listener instanceof ListenerAggregateInterface) {
                    $listener->detach($events);
                }

                $sharedManager->detach($listener, $id);
            }
        }
    }
593724
public function on(string $eventName, callable $callBack, int $priority = 100)
    {
        // If it ends with a wildcard, we use the wildcardListeners array
        if ('*' === $eventName[\strlen($eventName) - 1]) {
            $eventName = \substr($eventName, 0, -1);
            $listeners = &$this->wildcardListeners;
        } else {
            $listeners = &$this->listeners;
        }

        // Always fully reset the listener index. This is fairly sane for most
        // applications, because there's a clear "event registering" and "event
        // emitting" phase, but can be slow if there's a lot adding and removing
        // of listeners during emitting of events.
        $this->listenerIndex = [];

        if (!isset($listeners[$eventName])) {
            $listeners[$eventName] = [];
        }
        $listeners[$eventName][] = [$priority, $callBack];
    }
692222
public function add(EventInterface $event)
    {
        $index = $this->computeIndex($event);
        if (isset($this->events[$index])) {
            $this->events[$index][] = $event;
        } else {
            $this->events[$index] = array($event);
        }

        ++$this->count;
    }
82463
public function on($eventNames, $callback, $priority = self::MID)
    {
        $eventNames = (array)$eventNames;

        foreach ($eventNames as $oneEventName) {
            $oneEventName = $this->cleanEventName($oneEventName);

            if (!array_key_exists($oneEventName, $this->_list)) {
                $this->_list[$oneEventName] = array();
            }

            $this->_list[$oneEventName][] = array((int)$priority, $callback, $oneEventName);
        }

        return $this;
    }
1149241
public function attach(EventManagerInterface $events)
    {
        $this->listeners[] = $events->attach(
            ViewEvent::EVENT_RENDERER_POST
            , array($this, 'onRenderRenderWidgets')
        );
    }
1225528
public function listen($events, $listener, $priority = 10, $acceptedArgs = 1)
    {
        foreach ((array) $events as $filter) {
            $this->listeners[$filter][] = $listener;

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

            if ( ! isset($this->registeredWpFilters[$filter])) {
                $this->registeredWpFilters[$filter] = true;

                add_filter(
                    $filter,
                    function () use ($filter) {
                        return $this->dispatch($filter, func_get_args());
                    },
                    $priority,
                    $acceptedArgs
                );
            }
        }
    }
60449
public function hook($event, callable $callback, $priority = 10)
    {
        $this->app->hook($event, $callback, $priority);
    }