This commit is contained in:
2021-04-26 12:37:50 +08:00
parent 0db6782135
commit c907c42c07
4 changed files with 4 additions and 57 deletions
+3 -9
View File
@@ -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;
}
+1 -2
View File
@@ -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) {
-10
View File
@@ -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
-36
View File
@@ -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());
}
}