注册事件
@param string $event
@param mixed $callback
@param bool $first 是否优先执行，以靠后设置的为准
517913
public static function register($event, $callback, $first=false)
	{
		if (! isset(self::$events[$event]))
		{
			self::$events[$event] = array ();
		}
		if($first)
		{
			array_unshift(self::$events[$event],$callback);
		}
		else 
		{
			self::$events[$event][] = $callback;
		}
	}
148861
public function on(string $event, $callback)
    {
        if (! is_string($callback) && ! is_callable($callback)) {
            throw new InvalidArgumentException(
                'Invalid websocket callback. Must be a string or callable.'
            );
        }

        $this->callbacks[$event] = $callback;

        return $this;
    }
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);
    }
876532
public static function listen($event, $callback)
    {
        if (is_array($event)) {
            foreach ($event as $e) {
                self::listen($e, $callback);
            }
            return;
        }

        if ($event !== '*' and !self::eventName($event)) {
            throw new \InvalidArgumentException('Event "'.$event.'" is not a valid event');
        }

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

        self::$events[$event][] = $callback;
    }
291870
protected function trigger($event)
    {
        $class = static::class;

        if ($this->withEvent && isset(self::$event[$class][$event])) {
            foreach (self::$event[$class][$event] as $callback) {
                $result = call_user_func_array($callback, [$this]);

                if (false === $result) {
                    return false;
                }
            }
        }

        return true;
    }
446605
public function first( Closure $callback = NULL, $default = NULL )
    {
        if ( is_null( $callback ) )
        {
            return count( $this->items ) > 0 ? reset( $this->items ) : NULL;
        }

        return array_filter( $this->items, $callback, $default );
    }
804147
public static function listen(string $event, callable $callback) {
		if (!isset(self::$events[$event])) {
			self::$events[$event] = [];
		}
		self::$events[$event][] = $callback;
	}
407167
public function on($name, $callback, $priority = 0)
    {
        if(!isset($this->events[$name]))
        {
            $this->events[$name] = new KVStorage;
        }
        // 数据映射
        $this->events[$name]->attach($callback, [
            'callback' => $callback,
            'priority' => $priority,
        ]);
        $this->eventChangeRecords[$name] = true;
    }
767116
function first (callback) {
        if (typeof callback !== 'function') {
          throw new Error('Callback must be a function, instead got: ' + (typeof callback));
        }

        function firstCallback (result) {
          callback(result);
          unbind('start', firstCallback);
        }

        bind('start', firstCallback);
        bind('stop', unbind.bind(null, 'end', firstCallback));

        return self;
      }
1119186
public function first(callable $callback = null)
    {
        if (null === $callback) {
            return reset($this->items);
        }

        return $this->filter($callback)->first();
    }
930434
public function on($event, \Closure $callback): void
    {
        // check if event is a single string and parse it to array single item
        if (!Any::isArray($event)) {
            $event = [$event];
        }
        
        foreach ($event as $item) {
            $this->events[$item][] = $callback;
        }
    }
186925
public function listen($event, \Closure $callback): void
    {
        // check if $event is a single string and set it as array with one item
        if (!Any::isArray($event)) {
            $event = [$event];
        }
        
        // each every one event in array
        foreach ($event as $item) {
            if (Any::isArray($this->runned) && array_key_exists($item, $this->runned)) {
                call_user_func_array($callback, $this->runned[$item]);
            }
        }
    }
563251
public function trigger($event, $data = null) {
		$event = strtolower(trim($event));
		if (!isset($this->_events[$event])) return $data;

		foreach ($this->_events[$event] as $callback) {
			// we don't want to affect the data if someone forgets to return the original data in his callback. 
			$result = call_user_func($callback, $event, $data);
			if ($result !== null) $data = $result;
		}

		return $data;
	}
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;
    }
572706
public function register(string $name, $callback) : Event
    {
        if (is_null($name)) {
            throw new \RuntimeException(sprintf('Event name cannot be empty in %s', __FUNCTION__));
        }

        if (is_null($callback)) {
            throw new \RuntimeException(sprintf('Empty parameter passed as callback in %s function', __FUNCTION__));
        }

        if (!isset($this->events[$name])) {
            $this->events[$name] = [];
        }

        if (!in_array($callback, $this->events[$name])) {
            $this->events[$name][] = $callback;
        }

        return $this;
    }
293183
public function help($event_name, $callback)
    {
        if (!isset($this->event_helpers[$event_name]))
        {
            $this->event_helpers[$event_name] = $callback;
        }
    }
402030
public static function onLoad(string $js, bool $first = false) {
		if (!$first) {
			self::$onload.= $js;
		} else {
			self::$onload_first.= $js;
		}
	}