protected function registerServerEvents(array $events): void
    {
        $eventInfo = [];

        // register event to swoole
        foreach ($events as $name => $cb) {
            // is a Closure callback, add by self::onSwoole()
            if (\is_object($cb) && \method_exists($cb, '__invoke')) {
                $eventInfo[] = [$name, \get_class($cb)];
                $this->server->on($name, $cb);
                continue;
            }

            if (\is_string($cb)) {
                if (\is_int($name)) {
                    $name = $cb;
                }

                $method = SwooleEvent::getHandler($cb);
                if ($method && \method_exists($this, $method)) {
                    $eventInfo[] = [$name, static::class . "->$method"];
                    $this->server->on($name, [$this, $method]);
                } elseif (\function_exists($cb)) {
                    $eventInfo[] = [$name, $cb];
                    $this->server->on($name, $cb);
                }
            }
        }

        Show::table($eventInfo, 'Registered events to the server', [
            'showBorder' => 0,
            'columns'    => ['event name', 'swoole event handler']
        ]);
    }
protected function registerServerEvents(array $events): void
    {
        $eventInfo = [];

        // register event to swoole
        foreach ($events as $name => $cb) {
            // is a Closure callback, add by self::onSwoole()
            if (\is_object($cb) && \method_exists($cb, '__invoke')) {
                $eventInfo[] = [$name, \get_class($cb)];
                $this->server->on($name, $cb);
                continue;
            }

            if (\is_string($cb)) {
                if (\is_int($name)) {
                    $name = $cb;
                }

                $method = SwooleEvent::getHandler($cb);
                if ($method && \method_exists($this, $method)) {
                    $eventInfo[] = [$name, static::class . "->$method"];
                    $this->server->on($name, [$this, $method]);
                } elseif (\function_exists($cb)) {
                    $eventInfo[] = [$name, $cb];
                    $this->server->on($name, $cb);
                }
            }
        }

        Show::table($eventInfo, 'Registered events to the server', [
            'showBorder' => 0,
            'columns'    => ['event name', 'swoole event handler']
        ]);
    }
protected function registerServerEvents ( array $ events ) : void { $ eventInfo = [ ] ; // register event to swoole foreach ( $ events as $ name => $ cb ) { // is a Closure callback, add by self::onSwoole() if ( \ is_object ( $ cb ) && \ method_exists ( $ cb , '__invoke' ) ) { $ eventInfo [ ] = [ $ name , \ get_class ( $ cb ) ] ; $ this -> server -> on ( $ name , $ cb ) ; continue ; } if ( \ is_string ( $ cb ) ) { if ( \ is_int ( $ name ) ) { $ name = $ cb ; } $ method = SwooleEvent :: getHandler ( $ cb ) ; if ( $ method && \ method_exists ( $ this , $ method ) ) { $ eventInfo [ ] = [ $ name , static :: class . "->$method" ] ; $ this -> server -> on ( $ name , [ $ this , $ method ] ) ; } elseif ( \ function_exists ( $ cb ) ) { $ eventInfo [ ] = [ $ name , $ cb ] ; $ this -> server -> on ( $ name , $ cb ) ; } } } Show :: table ( $ eventInfo , 'Registered events to the server' , [ 'showBorder' => 0 , 'columns' => [ 'event name' , 'swoole event handler' ] ] ) ; }
register Swoole Events
@param array $events
register Swoole Events