This commit is contained in:
2021-03-05 16:10:36 +08:00
parent cfeaf36b27
commit 7c6b5fb71f
2 changed files with 39 additions and 36 deletions
-32
View File
@@ -54,44 +54,12 @@ class Middleware
*/
public function getGenerate(Node $node): mixed
{
$this->set_attributes($node);
return $node->callback = Reduce::reduce(function () use ($node) {
return Dispatch::create($node->handler, func_get_args())->dispatch();
}, $this->annotation($node));
}
/**
* @param $node
* @throws Exception
*/
private function set_attributes(Node $node)
{
if (!is_array($node->handler)) {
return;
}
[$controller, $action] = $node->handler;
$attributes = Snowflake::app()->getAttributes();
$annotation = $attributes->getMethods(get_class($controller), $action);
if (empty($annotation)) {
return;
}
foreach ($annotation as $name => $attribute) {
if ($attribute instanceof Interceptor) {
$node->addInterceptor($attribute->interceptor);
}
if ($attribute instanceof After) {
$node->addAfter($attribute->after);
}
if ($attribute instanceof RMiddleware) {
$node->addMiddleware($attribute->middleware);
}
if ($attribute instanceof Limits) {
$node->addLimits($attribute->limits);
}
}
}
/**
* @param Node $node