public function afterRegistered() { $globals = Register::get(self::class, self::class); foreach ($this->data() as $name => &$callable) { if ($name === self::class) { continue; } if (is_string($callable) && array_key_exists($callable, $globals)) { $callable = $globals[$callable]; lego_assert(is_callable($callable), '$callable is not callable.'); } // Register to ResponseData ResponseData::add($name, $callable); } }
/** * Response 的封装 * * @param mixed $response * @return mixed */ public final function response($response) { /** * 全局重写 Response. */ $registeredResponse = ResponseData::getResponse(); if (!is_null($registeredResponse)) { return $registeredResponse; } $this->processFields(); $this->process(); /** * 通过 rewriteResponse() 重写的 Response. */ if (!is_null($this->response)) { return value($this->response); } return $response; }
/** * @return \Symfony\Component\HttpFoundation\Response|\Illuminate\Contracts\Routing\ResponseFactory */ function lego_response() { /** * Check registered global response */ $registeredResponse = ResponseData::getResponse(); if (!is_null($registeredResponse)) { return $registeredResponse; } return call_user_func_array('response', func_get_args()); }
/** * 自动补全的结果集 * @param callable $callable */ public function match($callable) { $responsePath = $this->responsePath(); Register::register(AutoCompleteData::class, $this->source()->original(), [$responsePath => $callable]); $this->remote = ResponseData::url($responsePath); }