format = Kiri::getDi()->get($parameter); } else { $this->format = Kiri::getDi()->get(MixedFormat::class); } } /** * @param string $method * @return void * @throws */ public function setRequestMethod(string $method): void { if ($method == 'HEAD' || $method == 'OPTIONS') { $this->format = Kiri::getDi()->get(NoBody::class); } } /** * @return bool */ public function isClosure(): bool { return $this->handler instanceof Closure; } /** * @param string $interface * @return bool */ public function implement(string $interface): bool { if (!$this->handler instanceof Closure) { return $this->handler[0] instanceof $interface; } return false; } /** * @return string|null */ public function getClass(): ?string { if ($this->handler instanceof Closure) { return null; } return $this->handler[0]; } /** * @return string|null */ public function getMethod(): ?string { if ($this->handler instanceof Closure) { return null; } return $this->handler[1]; } /** * @param array $middlewares * @return void */ public function setMiddlewares(array $middlewares): void { $this->middlewares = $middlewares; } /** * @return array */ public function getMiddlewares(): array { return $this->middlewares; } /** * @param ServerRequestInterface $request * @return ResponseInterface * @throws */ public function handle(ServerRequestInterface $request): ResponseInterface { $controller = Kiri::getDi()->get($this->handler[0]); $data = call_user_func([$controller, $this->handler[1]], ...$this->parameters); /** 根据返回类型 */ return $this->format->call($data); } }