Register an event with the dispatcher.

@param  string  $event
@param  \Closure|string  $callback

@return void
327513
protected static function registerObservableEvent($event, $callback)
    {
        if (! isset(static::$dispatcher)) {
            return ;
        }

        $className = get_called_class();

        $event = with(new static())->getObservableKey($event);

        static::$dispatcher->listen("{$event}: {$className}", $callback);
    }
993420
public function detach($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);
            $listeners = $this->removeListener($listeners, $eventObject, $callback);
        }
        $this->setOption(self::OPTION_LISTENERS, $listeners);
    }
1168835
protected final void registerCustomEventCallback(
            final CrawlEvent event,
            final PatternMatchingCallback callback) {
        Validate.notNull(event, "The event cannot be null.");
        Validate.notNull(callback, "The callback cannot be null.");

        callbackManager.addCustomEventCallback(event, callback);
    }
963406
public function unregister($event, $callback = null)
	{
		if (isset($this->_events[$event]))
		{
			if ($callback === null)
			{
				unset($this->_events[$event]);
				return true;
			}

			foreach ($this->_events[$event] as $i => $arguments)
			{
				if($callback === $arguments[1])
				{
					unset($this->_events[$event][$i]);
					return true;
				}
			}
		}

		return false;
	}
1237412
protected function registerCloseCallback()
    {
        $this->swooleServer->on('Close', function ($server, $fd, $reactorId) {
            $this->dispatchEvent('Close', $this, $fd, $reactorId);
        });
    }
456681
public static function on($event, $callback){

        if( !isset(self::$observers[ $event ]) ){
            self::$observers[ $event ] = array();
        }

        self::$observers[ $event ][] = $callback;
    }
675423
public function trigger($event, \Closure $callback = null)
    {
        $results = [];

        if (!$event instanceof EventInterface) {
            $event = new Event($event);
        }

        if ($listeners = $this->getListeners($event->getName())) {
            foreach ($listeners as $listener) {
                $result = call_user_func($listener, $event);
                if ($result instanceof EventInterface) {
                    // Save result
                    $results[] = clone $result;

                    // Was the queue halted early ?
                    if ($result->isQueueHaltedEarly()) {
                        return $this;
                    }

                    if ($callback !== null) {
                        call_user_func($callback, $result);
                    }

                    // Was the queue halted ?
                    if ($result->isQueueHalted()) {
                        return $this;
                    }
                } else {
                    if ($callback !== null) {
                        call_user_func($callback, $result);
                    }
                }
            }
        }
        if ($results) {
            return $results;
        }

        return false;
    }
116331
private function registerListener($event, callable $listener, $priority)
    {
        if (!isset($this->events[$event])) {
            $this->events[$event] = [];
        }

        if ($priority === null) {
            $this->events[$event][] = $listener;

            return;
        }

        array_splice($this->events[$event], (int) $priority, 0, [$listener]);
    }
46768
private function applyRegistrationCallbacks(Event $event)
    {
        foreach ($this->registrationCallbacks as $callback) {
            $event = $callback->onEventRegistration($event);
        }

        return $event;
    }
541532
public function register($name, Closure $callback): void
    {
        if ($this->has($name)) {
            $this->callbacks = $this->callbacks->put($name, $this->callbacks->get($name, collect())->push($callback));
        } else {
            $builder = new MenuGenerator();

            $builder->setViewFactory($this->viewFactory);

            $this->menus->put($name, $builder);

            $this->callbacks = $this->callbacks->put($name, $this->callbacks->get($name, collect())->push($callback));
        }
    }
466666
public function once($event, $callback, $first = false)
	{
		$this->register($event, $callback, $first, true);
	}
231403
public static function register($event, $callback, $first = false, $once = false)
	{
		return call_user_func_array([EventClass::getInstance(), 'register'], func_get_args());
	}
649324
public function detach($event, $callback)
    {
        if (null !== $callback) {
            $oid = $this->hashCallable($callback);
            if (isset($this->callable_map[$event][$oid])) {
                $callback = $this->callable_map[$event][$oid];
                unset($this->callable_map[$event][$oid]);
            }
        } else {
            unset($this->callable_map[$event]);
        }
        return parent::detach($event, $callback);
    }
609492
public function dispatchEvent($event) {
		$type = $event->getType();
		if (isset($this->eventsListeners[$type])) {
			for ($j = 0; $j < count($this->eventsListeners[$type]); $j++) {
				list($plugin, $action) = explode(':', $this->eventsListeners[$type][$j]);
				//加载plugin && 调用action
				//echo $type.'<br/>';
				$this->app->runPluginAction($plugin, $action, $event);
			}
		}
		
	}
728095
public function addLifecycleCallback(string $callback, string $event) : void
    {
        if (isset($this->lifecycleCallbacks[$event]) && in_array($callback, $this->lifecycleCallbacks[$event])) {
            return;
        }

        $this->lifecycleCallbacks[$event][] = $callback;
    }
1117863
public function registerCallback( $event, $callback ) {

		if ( !is_string( $event ) ) {
			throw new InvalidArgumentException( "Event is not a string" );
		}

		if ( !is_callable( $callback ) ) {
			throw new RuntimeException( "Invoked object is not a valid callback or Closure" );
		}

		$this->addToCollection( $event, new GenericCallbackEventListener( $callback ) );
	}
1168413
public function listen($event, $callback)
    {
        if (!isset($this->listeners[$event])) {
            $this->listeners[$event] = [];
        }

        $this->listeners[$event][] = $callback;
    }