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
9773
public function attach(EventManagerInterface $events, $priority = 1)
    {
        $events->attach(MediaEvent::EVENT_ADD, [$this, 'setImageSize']);
        $events->attach(MediaEvent::EVENT_ADD, [$this, 'resizeImages']);
        $events->attach(MediaEvent::EVENT_ADD, [$this, 'setCache']);
        $events->attach(MediaEvent::EVENT_EDIT, [$this, 'setCache']);
        $events->attach(MediaEvent::EVENT_DELETE, [$this, 'removeCache']);
    }
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);
    }
392396
public function attach(EventManagerInterface $events)
    {
        $sharedManager = $events->getSharedManager();
        $sharedManager->attach(ManagerRegistry::class, ManagerRegistryResourceEvent::RESOLVE_CONNECTION_EVENT, [$this, 'resolveConnectionByNameHandler']);
        $sharedManager->attach(ManagerRegistry::class, ManagerRegistryResourceEvent::RESOLVE_OBJECT_MANAGER_EVENT, [$this, 'resolveObjectManagerByNameHandler']);
    }
759023
public function addEventListener($eventName, $listener, $priority = EventPriority::NORMAL) {
        if (!isset($this->_listeners[$eventName][$priority])) {
            $this->_listeners->extendDeepValue(array($priority=>array()), $eventName);
        }
        $this->_listeners[$eventName][$priority][] = $listener;
    }
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);

        }
    }
613858
public function attach(EventManagerInterface $events)
    {
        $sharedManager = $events->getSharedManager();
        $sharedManager->attach(ManagerRegistryFactory::class, ManagerRegistryFactory::EVENT_BUILD_LIST_CONNECTIONS, [$this, 'buildListConnectionsHandler']);
        $sharedManager->attach(ManagerRegistryFactory::class, ManagerRegistryFactory::EVENT_BUILD_LIST_OBJECT_MANAGERS, [$this, 'buildListObjectManagersHandler']);
    }
374766
public function listenTo($event, $listeners, $priority = 0)
    {
        /** @var \Rocketeer\Tasks\AbstractTask[] $listeners */
        $listeners = $this->builder->isCallable($listeners) ? [$listeners] : (array) $listeners;
        $listeners = $this->builder->buildTasks($listeners);
        $event = Str::contains($event, ['commands.', 'strategies.', 'tasks.']) ? $event : 'tasks.'.$event;

        // Register events
        foreach ($listeners as $key => $listener) {
            $handle = $this->getEventHandle(null, $event);
            $this->events->addListener($handle, $listener, $priority ?: -$key);
        }

        return $event;
    }
1122495
public function attachListener(string $event, callable $listener, int $priority = 1): ListenerHandler
    {
        if (! empty($this->availableEventNames) && ! \in_array($event, $this->availableEventNames, true)) {
            throw new \InvalidArgumentException("Unknown event name given: $event");
        }

        $handler = new DefaultListenerHandler($listener);

        $this->events[$event][((int) $priority) . '.0'][] = $handler;

        return $handler;
    }
98161
public function registerEventListeners(DispatcherContract $events)
    {
        foreach ($this->listen as $event => $listeners) {
            $defaultPriority = 0;
            if (!is_array($listeners)) {
                $events->listen($event, $listeners);
                continue;
            }
            foreach ($listeners as $listener => $priority) {
                if (is_numeric($listener)) {
                    $listener = $priority;
                    $priority = $defaultPriority;
                }
                if (is_array($listener)) {
                    $priority = is_numeric(current($listener)) ? current($listener) : $defaultPriority;
                    $listener = key($listener);
                }
                $events->listen($event, $listener, $priority);
            }
        }
        foreach ($this->subscribe as $subscriber) {
            $events->subscribe($subscriber);
        }
    }
476827
function _announce($event)
    {
        foreach ($this->_listeners as $id => $listener) {
            if ($event['priority'] <= $this->_listeners[$id]->_priority) {
                $this->_listeners[$id]->notify($event);
            }
        }
    }
1234278
public static function on($name, $callback, $priority = 0)
    {
        if (is_string($name) && is_callable($callback)) {
            if (isset(self::$events[$name]) === false) {
                self::$events[$name] = array();
            }

            self::$events[$name][] = array($callback, $priority);
        }
    }
1001388
public function setEventPriority($name, AnObjectHandable $listener, $priority)
    {
        if (isset($this->_listeners[$name])) {
            $this->_listeners[$name]->setPriority($listener, $priority);
        }
        
        return $this;
    }
929500
public function addListener( $eventName, IListener $listener, $priority = 0 )
    {
        $this->listeners[ $eventName ][ $priority ][ ] = $listener;

        unset( $this->_sorted[ $eventName ] );
    }
911382
public static function insert($eventName = NULL, $callback = NULL, $priority = NULL)
    { 
        if( $callback === NULL || is_int($callback) )
        {
            $priority  = $callback;
            $callback  = $eventName;
            $eventName = Properties::$startListenerName;
        }
        else
        {
            Properties::$startListenerName = $eventName;
        }

        $callback = self::callback($callback);
            
        if( ! is_callable($callback) )
        {
            throw new InvalidCallbackMethodException;
        }

        if( isset(Properties::$listeners[$eventName]) )
        {
            Properties::$listeners[$eventName][0][] = $priority;
			Properties::$listeners[$eventName][1][] = $callback;
        }
        else
        {
            Properties::$listeners[$eventName] = [[$priority], [$callback]];
        }
    }
62958
public function attach(EventManagerInterface $events)
    {
        $this->listeners[] = $events->attach(MvcEvent::EVENT_FINISH, array($this, 'onFinish'));
    }
1068128
public function addOperationListener(OperationListenerInterface $listener, $priority = 0)
    {
        $this->getEventManager()->attach('beforeOperation', [$listener, 'beforeOperation'], $priority);
        $this->getEventManager()->attach('afterOperation', [$listener, 'afterOperation'], $priority);
        $this->getEventManager()->attach('onOperationException', [$listener, 'onOperationException'], $priority);
    }
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);
        }
    }