worker = new Worker($this->socket ?: $this->protocol . '://' . $this->host . ':' . $this->port, $this->context); // 设置参数 if (!empty($this->option)) { foreach ($this->option as $key => $val) { $this->worker->$key = $val; } } // 设置回调 foreach ($this->event as $event) { if (method_exists($this, $event)) { $this->worker->$event = [$this, $event]; } } // 初始化 $this->init(); } /** * 服务初始化方法 * @return mixed */ abstract protected function init(); /** * 动态设置属性 * @param string $name * @param mixed $value * @return void */ public function __set(string $name, $value) { $this->worker->$name = $value; } /** * 动态调用方法 * @param string $method * @param array $args * @return void */ public function __call(string $method, array $args) { call_user_func_array([$this->worker, $method], $args); } }