This commit is contained in:
2020-09-07 17:19:02 +08:00
parent a19e1c4f24
commit 7b490faee6
2 changed files with 26 additions and 3 deletions
+24 -1
View File
@@ -3,6 +3,8 @@
namespace HttpServer\Route\Annotation; namespace HttpServer\Route\Annotation;
use HttpServer\IInterface\Interceptor;
use HttpServer\IInterface\Limits;
use HttpServer\Route\Node; use HttpServer\Route\Node;
use ReflectionClass; use ReflectionClass;
use ReflectionException; use ReflectionException;
@@ -105,7 +107,6 @@ class Annotation extends \Snowflake\Annotation\Annotation
} }
/** /**
* @param Node $node * @param Node $node
* @param $annotation * @param $annotation
@@ -142,6 +143,17 @@ class Annotation extends \Snowflake\Annotation\Annotation
[$keyName, $matchs] = $annotation; [$keyName, $matchs] = $annotation;
foreach ($explode as $middleware) { foreach ($explode as $middleware) {
$middleware = 'App\Http\Interceptor\\' . $middleware;
if (!class_exists($middleware)) {
continue;
}
$middleware = Snowflake::createObject($middleware);
if (!($middleware instanceof Interceptor)) {
continue;
}
$node->addInterceptor([$middleware, 'Interceptor']);
continue;
$params = [$keyName, [$matchs[0], $matchs[1], $middleware]]; $params = [$keyName, [$matchs[0], $matchs[1], $middleware]];
$node->addInterceptor($this->pop($this->getName(...$params))); $node->addInterceptor($this->pop($this->getName(...$params)));
} }
@@ -163,6 +175,17 @@ class Annotation extends \Snowflake\Annotation\Annotation
[$keyName, $matchs] = $annotation; [$keyName, $matchs] = $annotation;
foreach ($explode as $middleware) { foreach ($explode as $middleware) {
$middleware = 'App\Http\Limits\\' . $middleware;
if (!class_exists($middleware)) {
continue;
}
$middleware = Snowflake::createObject($middleware);
if (!($middleware instanceof Limits)) {
continue;
}
$node->addLimits([$middleware, 'next']);
continue;
$params = [$keyName, [$matchs[0], $matchs[1], $middleware]]; $params = [$keyName, [$matchs[0], $matchs[1], $middleware]];
$node->addLimits($this->pop($this->getName(...$params))); $node->addLimits($this->pop($this->getName(...$params)));
} }
+2 -2
View File
@@ -70,7 +70,7 @@ class Middleware
return $this->annotation_limit($node, $middleWares); return $this->annotation_limit($node, $middleWares);
} }
foreach ($node->getInterceptor() as $item) { foreach ($node->getInterceptor() as $item) {
$middleWares[] = $item[0]; $middleWares[] = $item;
} }
return $this->annotation_limit($node, $middleWares); return $this->annotation_limit($node, $middleWares);
} }
@@ -87,7 +87,7 @@ class Middleware
return $middleWares; return $middleWares;
} }
foreach ($node->getLimits() as $item) { foreach ($node->getLimits() as $item) {
$middleWares[] = $item[0]; $middleWares[] = $item;
} }
return $middleWares; return $middleWares;
} }