From c907c42c074e65b55cf41da4410b760e968afe0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Mon, 26 Apr 2021 12:37:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Annotation/Route/Filter.php | 12 +++-------- HttpServer/Events/OnRequest.php | 3 +-- HttpServer/Http/Request.php | 10 --------- HttpServer/Route/Node.php | 36 --------------------------------- 4 files changed, 4 insertions(+), 57 deletions(-) diff --git a/Annotation/Route/Filter.php b/Annotation/Route/Filter.php index fdd5731b..4b78d3f3 100644 --- a/Annotation/Route/Filter.php +++ b/Annotation/Route/Filter.php @@ -30,18 +30,12 @@ use Snowflake\Snowflake; /** * @param array $handler - * @return array + * @return bool * @throws Exception */ - public function execute(array $handler): array + public function execute(array $handler): bool { - [$class, $method] = $handler; - - /** @var HttpFilter $filter */ - $filter = Snowflake::app()->get('filter'); - $filter->register($class::class, $method, $this->rules); - - return $handler; + return true; } diff --git a/HttpServer/Events/OnRequest.php b/HttpServer/Events/OnRequest.php index 58fb3d52..7dad5f7e 100644 --- a/HttpServer/Events/OnRequest.php +++ b/HttpServer/Events/OnRequest.php @@ -54,11 +54,10 @@ class OnRequest extends Callback defer(function () { fire(Event::SYSTEM_RESOURCE_RELEASES); }); - /** @var HRequest $request */ /** @var HResponse $response */ [$request, $response] = OnRequest::createContext($request, $response); if ($request->is('favicon.ico')) { - return $response->send('', 404); + return $response->close(404); } return $this->router->dispatch(); } catch (ExitException | Error | \Throwable $exception) { diff --git a/HttpServer/Http/Request.php b/HttpServer/Http/Request.php index 6cbdaada..e4731444 100644 --- a/HttpServer/Http/Request.php +++ b/HttpServer/Http/Request.php @@ -450,16 +450,6 @@ class Request extends HttpService } - /** - * @return mixed - * @throws Exception - */ - public function dispatch(): mixed - { - return $this->is('favicon.ico') ? \send(null) : \router()->dispatch(); - } - - /** * @param $request * @return mixed diff --git a/HttpServer/Route/Node.php b/HttpServer/Route/Node.php index 2ca915c2..42489b47 100644 --- a/HttpServer/Route/Node.php +++ b/HttpServer/Route/Node.php @@ -520,42 +520,6 @@ class Node extends HttpService return Json::to(404, $this->errorMsg()); } return call_user_func($this->handler, \request()); - return $this->httpFilter(); - } - - - /** - * @return mixed - * @throws Exception - */ - private function httpFilter(): mixed - { - if ($this->handler instanceof Closure) { - return call_user_func($this->handler, \request()); - } else { - return $this->runValidator([\request()]); - } - } - - - /** - * @param $dispatchParams - * @return mixed - * @throws Exception - */ - private function runValidator($dispatchParams): mixed - { - if (empty($this->rules) || !is_array($this->rules)) { - return call_user_func($this->callback, ...$dispatchParams); - } - /** @var HttpFilter $filter */ - $filter = Snowflake::app()->get('filter'); - $validator = $filter->check($this->rules); - if (!($validator instanceof Validator) || $validator->validation()) { - return call_user_func($this->callback, ...$dispatchParams); - } else { - return Json::to(5005, $validator->getError()); - } }