改名
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user