This commit is contained in:
as2252258@163.com
2021-04-20 00:40:10 +08:00
parent 7960ca45ab
commit eaeb124994
+14 -11
View File
@@ -5,6 +5,9 @@ declare(strict_types=1);
namespace HttpServer\Route; namespace HttpServer\Route;
use Annotation\Route\After;
use Annotation\Route\Interceptor;
use Annotation\Route\Limits;
use Annotation\Route\Middleware; use Annotation\Route\Middleware;
use Annotation\Route\RpcProducer; use Annotation\Route\RpcProducer;
use Closure; use Closure;
@@ -124,8 +127,8 @@ class Node extends HttpService
*/ */
public function createDispatch(): Closure public function createDispatch(): Closure
{ {
return function (...$params) { return function () {
return Dispatch::create($this->handler, ...$params)->dispatch(); return Dispatch::create($this->handler, func_get_args())->dispatch();
}; };
} }
@@ -354,16 +357,16 @@ class Node extends HttpService
return $this; return $this;
} }
foreach ($annotation as $name => $attribute) { foreach ($annotation as $name => $attribute) {
if ($attribute instanceof \Annotation\Route\Interceptor) { if ($attribute instanceof Interceptor) {
$this->addInterceptor($attribute->interceptor); $this->addInterceptor($attribute->interceptor);
} }
if ($attribute instanceof \Annotation\Route\After) { if ($attribute instanceof After) {
$this->addAfter($attribute->after); $this->addAfter($attribute->after);
} }
if ($attribute instanceof Middleware) { if ($attribute instanceof Middleware) {
$this->addMiddleware($attribute->middleware); $this->addMiddleware($attribute->middleware);
} }
if ($attribute instanceof \Annotation\Route\Limits) { if ($attribute instanceof Limits) {
$this->addLimits($attribute->limits); $this->addLimits($attribute->limits);
} }
} }
@@ -513,12 +516,12 @@ class Node extends HttpService
* @return mixed * @return mixed
* @throws Exception * @throws Exception
*/ */
public function dispatch(...$params): mixed public function dispatch(): mixed
{ {
if (empty($this->callback)) { if (empty($this->callback)) {
return Json::to(404, $this->errorMsg()); return Json::to(404, $this->errorMsg());
} }
return $this->httpFilter(...$params); return $this->httpFilter(func_get_args());
} }
@@ -526,22 +529,22 @@ class Node extends HttpService
* @return mixed * @return mixed
* @throws Exception * @throws Exception
*/ */
private function httpFilter(...$param): mixed private function httpFilter(): mixed
{ {
try { try {
if ($this->handler instanceof Closure) { if ($this->handler instanceof Closure) {
return $this->runWith($this->handler, ...$param); return call_user_func($this->handler, ...func_get_args());
} }
/** @var HttpFilter $filter */ /** @var HttpFilter $filter */
$filter = Snowflake::app()->get('filter'); $filter = Snowflake::app()->get('filter');
$validator = $filter->check(get_class($this->handler[0]), $this->handler[1]); $validator = $filter->check(get_class($this->handler[0]), $this->handler[1]);
if (!($validator instanceof Validator)) { if (!($validator instanceof Validator)) {
return $this->runWith($this->callback, ...$param); return call_user_func($this->callback, ...func_get_args());
} }
if (!$validator->validation()) { if (!$validator->validation()) {
return Json::to(5005, $validator->getError()); return Json::to(5005, $validator->getError());
} }
return $this->runWith($this->callback, ...$param); return call_user_func($this->callback, ...func_get_args());
} catch (Throwable $throwable) { } catch (Throwable $throwable) {
$this->addError($throwable, 'throwable'); $this->addError($throwable, 'throwable');