改名
This commit is contained in:
@@ -30,18 +30,12 @@ use Snowflake\Snowflake;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $handler
|
* @param array $handler
|
||||||
* @return array
|
* @return bool
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function execute(array $handler): array
|
public function execute(array $handler): bool
|
||||||
{
|
{
|
||||||
[$class, $method] = $handler;
|
return true;
|
||||||
|
|
||||||
/** @var HttpFilter $filter */
|
|
||||||
$filter = Snowflake::app()->get('filter');
|
|
||||||
$filter->register($class::class, $method, $this->rules);
|
|
||||||
|
|
||||||
return $handler;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -54,11 +54,10 @@ class OnRequest extends Callback
|
|||||||
defer(function () {
|
defer(function () {
|
||||||
fire(Event::SYSTEM_RESOURCE_RELEASES);
|
fire(Event::SYSTEM_RESOURCE_RELEASES);
|
||||||
});
|
});
|
||||||
/** @var HRequest $request */
|
|
||||||
/** @var HResponse $response */
|
/** @var HResponse $response */
|
||||||
[$request, $response] = OnRequest::createContext($request, $response);
|
[$request, $response] = OnRequest::createContext($request, $response);
|
||||||
if ($request->is('favicon.ico')) {
|
if ($request->is('favicon.ico')) {
|
||||||
return $response->send('', 404);
|
return $response->close(404);
|
||||||
}
|
}
|
||||||
return $this->router->dispatch();
|
return $this->router->dispatch();
|
||||||
} catch (ExitException | Error | \Throwable $exception) {
|
} 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
|
* @param $request
|
||||||
* @return mixed
|
* @return mixed
|
||||||
|
|||||||
@@ -520,42 +520,6 @@ class Node extends HttpService
|
|||||||
return Json::to(404, $this->errorMsg());
|
return Json::to(404, $this->errorMsg());
|
||||||
}
|
}
|
||||||
return call_user_func($this->handler, \request());
|
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