Subscribe to an event.

@param string $event_name
@param callable $callback
@param int $priority
@return void
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;
	        }
	    }
1323499
protected function addFilter($name, $callback, $priority, $accepted_args)
    {
        add_filter($name, $callback, $priority, $accepted_args);
    }
1304146
public function on($eventName, $callback, $priority = 0)
    {
        if ($this->booted) {
            $this->container['event_dispatcher']->addListener($eventName, $this->container['callback_resolver']->resolveCallback($callback), $priority);

            return;
        }

        $this->container->extend('event_dispatcher', function ($dispatcher, $c) use ($callback, $priority, $eventName) {
            $dispatcher->addListener($eventName, $c['callback_resolver']->resolveCallback($callback), $priority);

            return $dispatcher;
        });
    }
1222632
def add_listener(self, event, callback, single=False, priority=1):
        
        event_stack = self._events[event]
        event_stack.append({
            "callback": callback,
            "single": single,
            "priority": priority
        })
        event_stack.sort(key=lambda x: x['priority'])
826584
public function once(string $eventName, callable $callBack, int $priority = 100)
    {
        $wrapper = null;
        $wrapper = function () use ($eventName, $callBack, &$wrapper) {
            $this->removeListener($eventName, $wrapper);

            return \call_user_func_array($callBack, \func_get_args());
        };

        $this->on($eventName, $wrapper, $priority);
    }
1169019
def add_listener(self, name, listener, priority=0):
        
        if name not in self.listeners:
            self.listeners[name] = []

        self.listeners[name].append((listener, priority))

        # reorder event
        self.listeners[name].sort(key=lambda listener: listener[1], reverse=True)
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);
    }
279040
public static function addListener(string $name, $listener, $priority = 0)
    {
        BeanFactory::getBean('eventManager')->attach($name, $listener, $priority);
    }
1226881
static function notifyUntil($event_name, $parameters = [], $subject = null, $desc = null) {
        self::$events[$event_name] = $desc ? $desc : $event_name;
        $event                     = new \sfEvent($subject, $event_name, $parameters);
        $event                     = self::dispatcher()
            ->notifyUntil($event);
        
        return $event->isProcessed();
    }
1278552
public function error($callback, $priority = -8)
    {
        $this->on(KernelEvents::EXCEPTION, new ExceptionListenerWrapper($this->container, $callback), $priority);
    }
303112
public static function init( $callback, $priority = null, $accepted_args = null ) {
		self::action( 'init', $callback, $priority, $accepted_args );
	}
64290
public function attach($eventName, callable $handler, $priority = 0)
    {
        if (is_array($eventName)) {
            foreach ($eventName as $name) {
                $this->attach($name, $handler, $priority);
            }
            return;
        }
        if (!is_string($eventName)) {
            throw new InvalidArgumentException(sprintf(
                '%s expects argument 1 to be string; %s given.',
                __METHOD__,
                is_object($eventName) ? get_class($eventName) : gettype($eventName)
            ));
        }

        if (!array_key_exists($eventName, $this->events)) {
            $this->events[$eventName] = new CallbackQueue();
        }

        $this->events[$eventName]->add($handler, $priority);
    }
185438
public function listen($eventName, $callback)
    {
        if (is_array($eventName)) {
            foreach ($eventName as $evnt) {
                $this["dispatcher"]->addListener($evnt, $callback);
            }
        } else {
            $this["dispatcher"]->addListener($eventName, $callback);
        }
    }
403447
public function listen($events, $listener, $priority = 0, $acceptedArgs = 1)
    {
        foreach ((array)$events as $event)
        {
            $this->listeners[$event][$priority][] = $this->makeListener($listener);

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

            if ( ! isset($this->registeredWpActions[$event]))
            {
                $this->registeredWpActions[$event] = true;

                add_action(
                    $event,
                    function () use ($event)
                    {
                        return $this->fire($event, func_get_args());
                    },
                    $priority,
                    $acceptedArgs
                );
            }
        }
    }
690181
public function trigger($event_name, $default_handler_callback = "", $event_properties = array())
    {
        $event = null;
        if (isset($this->event_queue[$event_name])) { //if the event already exists, use the handler callback for the event instead of the default handler callback
            $event = $this->event_queue[$event_name];
            $event->setProperties($event_properties);

            $handler_callback = $event->getHandlerCallback();
            if (is_callable($handler_callback)) { 
                $result = call_user_func_array($handler_callback, array($event));
                $event->setHandlerCallbackReturnValue($result);
            }
        }
        else{ //event does not exist yet, use the default handler callback
            $event = new Event($event_name);
            $event->setProperties($event_properties);
            if (is_callable($default_handler_callback)) {
                $event->setHandlerCallback($default_handler_callback);
                $result = call_user_func_array($default_handler_callback, array($event));
                $event->setHandlerCallbackReturnValue($result);
                $this->event_queue[$event_name] = $event;
            }
        }

        $result = $event->getHandlerCallbackReturnValue();

        return $result;
    }
769119
public function subListen($name, $event, $callable, $priority = ListenerPriority::NORMAL)
    {
        return $this->addSubListener($name, $callable, [$event => $priority]);
    }
691992
public function dispatch( $event_name, Event $event = null ) {

		if ( is_null( $event ) ) {
			$event = new Event();
		}

		do_action( $this->get_action_name_for_event( $event_name ), $event, $event_name, $this );

		return $event;
	}