public function attachPort(string $name, $config): void
    {
        if (isset($this->attachedNames[strtolower($name)])) {
            throw new \InvalidArgumentException("The add listen port server [$name] has been exists!");
        }

        if (\is_array($config)) {
            $class = Arr::remove($config, 'listener');

            if (!$class) {
                throw new \InvalidArgumentException("Please setting the 'listener' class for the port server: $name");
            }

            $cb = new $class($config);

            if (!$cb instanceof PortListenerInterface) {
                throw new \InvalidArgumentException(
                    'The event handler must implement of ' . PortListenerInterface::class
                );
            }
        } elseif ($config instanceof \Closure || $config instanceof PortListenerInterface) {
            $cb = $config;

        } else {
            throw new \InvalidArgumentException('The 2th argument type only allow [array|\Closure|InterfacePortListener].');
        }

        $this->attachedNames[$name]     = true;
        $this->attachedListeners[$name] = $cb;
    }
public function attachPort(string $name, $config): void
    {
        if (isset($this->attachedNames[strtolower($name)])) {
            throw new \InvalidArgumentException("The add listen port server [$name] has been exists!");
        }

        if (\is_array($config)) {
            $class = Arr::remove($config, 'listener');

            if (!$class) {
                throw new \InvalidArgumentException("Please setting the 'listener' class for the port server: $name");
            }

            $cb = new $class($config);

            if (!$cb instanceof PortListenerInterface) {
                throw new \InvalidArgumentException(
                    'The event handler must implement of ' . PortListenerInterface::class
                );
            }
        } elseif ($config instanceof \Closure || $config instanceof PortListenerInterface) {
            $cb = $config;

        } else {
            throw new \InvalidArgumentException('The 2th argument type only allow [array|\Closure|InterfacePortListener].');
        }

        $this->attachedNames[$name]     = true;
        $this->attachedListeners[$name] = $cb;
    }
public function attachPort ( string $ name , $ config ) : void { if ( isset ( $ this -> attachedNames [ strtolower ( $ name ) ] ) ) { throw new \ InvalidArgumentException ( "The add listen port server [$name] has been exists!" ) ; } if ( \ is_array ( $ config ) ) { $ class = Arr :: remove ( $ config , 'listener' ) ; if ( ! $ class ) { throw new \ InvalidArgumentException ( "Please setting the 'listener' class for the port server: $name" ) ; } $ cb = new $ class ( $ config ) ; if ( ! $ cb instanceof PortListenerInterface ) { throw new \ InvalidArgumentException ( 'The event handler must implement of ' . PortListenerInterface :: class ) ; } } elseif ( $ config instanceof \ Closure || $ config instanceof PortListenerInterface ) { $ cb = $ config ; } else { throw new \ InvalidArgumentException ( 'The 2th argument type only allow [array|\Closure|InterfacePortListener].' ) ; } $ this -> attachedNames [ $ name ] = true ; $ this -> attachedListeners [ $ name ] = $ cb ; }
attach add listen port to main server.
@param string                               $name
@param \Closure|array|PortListenerInterface $config
@throws \InvalidArgumentException
attach add listen port to main server .